# Voices and languages

> Choose the language an agent speaks and the voice it speaks in.

An agent speaks one language in one voice. Both are settings on the agent, and both are chosen from lists the API serves, so your code never has to hard-code them.

## Languages

[Get the catalog](https://www.cracklehq.com/docs/reference/catalog) lists the languages an agent can speak under `languages`. Each has an `id`, which is what you set as the agent’s `voice.language`, and an `iso` code.

Request:

cURL:

```bash
curl "https://goblins-call-api.onrender.com/v1/catalog" \
  -H "Authorization: Bearer $CRACKLE_API_KEY"
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/catalog', {
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
  },
});
if (!response.ok) throw new Error(await response.text());
const { catalog } = await response.json();
```

Python:

```python
import os
import requests

response = requests.get(
    "https://goblins-call-api.onrender.com/v1/catalog",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    timeout=30,
)
response.raise_for_status()
catalog = response.json()["catalog"]
```

Hindi, Hinglish and English lead the list, and many more follow. **Hinglish** is Hindi with English words mixed in, the way it is commonly spoken; choose it when callers move between the two in one sentence.

Request:

cURL:

```bash
curl -X PATCH "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "voice": {
    "language": "hinglish"
  },
  "stt": {
    "language": "hi"
  }
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b', {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    voice: {
      language: 'hinglish',
    },
    stt: {
      language: 'hi',
    },
  }),
});
if (!response.ok) throw new Error(await response.text());
const { agent } = await response.json();
```

Python:

```python
import os
import requests

response = requests.patch(
    "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "voice": {
            "language": "hinglish",
        },
        "stt": {
            "language": "hi",
        },
    },
    timeout=30,
)
response.raise_for_status()
agent = response.json()["agent"]
```

When you set a language through the API, set the agent’s `stt.language` to the same language’s `iso` code, so it listens for the language it speaks. The studio does both when you pick a language there. English is listened for either way.

Write the agent’s instructions in the language you want it to speak, or say in them which language to use. An agent with the `changeLanguage` [built-in tool](https://www.cracklehq.com/docs/tools#built-in-tools) can also move between Hindi and English mid-call when the caller does.

## One call in another language

The agent’s language is the one its calls start in. To hold a single call in a different one, send `language` when you [start the call](https://www.cracklehq.com/docs/reference/calls/start): a language’s `id` from the catalog, or its `iso` code. Nothing on the agent changes.

Request:

cURL:

```bash
curl -X POST "https://goblins-call-api.onrender.com/v1/calls" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "agentId": "ua_3f9a1c2b",
  "language": "ta"
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/calls', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    agentId: 'ua_3f9a1c2b',
    language: 'ta',
  }),
});
if (!response.ok) throw new Error(await response.text());
const session = await response.json();
```

Python:

```python
import os
import requests

response = requests.post(
    "https://goblins-call-api.onrender.com/v1/calls",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "agentId": "ua_3f9a1c2b",
        "language": "ta",
    },
    timeout=30,
)
response.raise_for_status()
session = response.json()
```

The agent keeps its voice and speaks that language in it, and it listens for that language as well as its own and English. Hindi and English need only a voice engine that speaks them. Any other language needs a voice engine that speaks it (`cartesia`, or `sarvam` for the languages it has voices in) and `openai` or `sarvam` transcription; without them the request answers `400 UNSUPPORTED_LANGUAGE`. [A call in another language](https://www.cracklehq.com/docs/calls#a-call-in-another-language) has the rest.

## Voices

[List voices](https://www.cracklehq.com/docs/reference/voices/list) is the voice library. Search it by name, narrow it to a language and a gender, and page through the results.

Request:

cURL:

```bash
curl "https://goblins-call-api.onrender.com/v1/providers/voices?language=hi&gender=feminine&limit=10" \
  -H "Authorization: Bearer $CRACKLE_API_KEY"
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/providers/voices?language=hi&gender=feminine&limit=10', {
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
  },
});
if (!response.ok) throw new Error(await response.text());
const { voices } = await response.json();
```

Python:

```python
import os
import requests

response = requests.get(
    "https://goblins-call-api.onrender.com/v1/providers/voices?language=hi&gender=feminine&limit=10",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    timeout=30,
)
response.raise_for_status()
voices = response.json()["voices"]
```

Each voice has an `id`, a `name`, a short `description`, and `preview`, which says whether it has a sample you can listen to through [Play a voice sample](https://www.cracklehq.com/docs/reference/voices/preview). Set the voice on an agent by its `id`:

Request:

cURL:

```bash
curl -X PATCH "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b" \
  -H "Authorization: Bearer $CRACKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "voice": {
    "speaker": "VOICE_ID"
  }
}'
```

Node.js:

```js
const response = await fetch('https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b', {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.CRACKLE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    voice: {
      speaker: 'VOICE_ID',
    },
  }),
});
if (!response.ok) throw new Error(await response.text());
const { agent } = await response.json();
```

Python:

```python
import os
import requests

response = requests.patch(
    "https://goblins-call-api.onrender.com/v1/agents/ua_3f9a1c2b",
    headers={"Authorization": f"Bearer {os.environ['CRACKLE_API_KEY']}"},
    json={
        "voice": {
            "speaker": "VOICE_ID",
        },
    },
    timeout=30,
)
response.raise_for_status()
agent = response.json()["agent"]
```

> Pick a voice recorded in the language the agent speaks: filter the library by `language`, and listen to the sample before you settle on one.

## Shaping the delivery

- `voice.speed` (number, 0.2–2): How fast the agent speaks. `1` is the voice’s natural pace.
- `voice.volume` (number, 0.5–2): How loud it is, with `1` as the voice’s own level.
- `voice.emotion` (string): A delivery such as `calm`, on engines that support emotions.

Engines that lack one of these controls ignore it. The best way to judge a change is to make it and press Test agent in the studio.

Source: https://www.cracklehq.com/docs/voices-and-languages
