The Text to Voice channel object goes into the `channel` object under the `text2voice` key - see [Cascade](https://www.bulkgate.com/en/docs/advanced-api/advanced-cascade/). Instead of a written message, the recipient gets a phone call that reads the text aloud.

> [!IMPORTANT]
> Text to Voice is a **transactional-only** channel. It is available in [Advanced transactional](https://www.bulkgate.com/en/docs/advanced-api/advanced-transactional/2.0/), **not** in [Advanced promotional](https://www.bulkgate.com/en/docs/advanced-api/advanced-promotional/2.0/) - a request that puts `text2voice` into a promotional `channel` is rejected with `Unexpected item 'text2voice'`.

```json
{
	"text2voice": {
		"text": "Your verification code is 1 2 3 4.",
		"language": "en",
		"prefer_gender": "female"
	}
}
```

## Text to Voice object

| PARAMETER NAME | VALUE                                                                                                                                                                                                    | MANDATORY | DEFAULT VALUE |
|:---------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------:|:-------------:|
| text           | The text read aloud to the recipient. Overrides the top-level `text`, see [Which text is used](#which-text-is-used). SSML is supported, variables are not - see the notes below.                         |    No     |    `null`     |
| sender         | Sender (calling line) the recipient sees. Leave empty to use the default.                                                                                                                                |    No     |    `null`     |
| language       | Language the text is spoken in. Uses an ISO code from [Supported languages](#supported-languages). If omitted, it is auto-detected from the recipient's country / phone number, falling back to English. |    No     |    auto       |
| prefer_gender  | Preferred voice gender, `male` or `female`. If the language has only one voice, that voice is used regardless.                                                                                           |    No     |    `male`     |
| speed          | Speaking speed as a multiplier - `1.0` is normal, `1.5` is faster, `0.8` is slower.                                                                                                                      |    No     |    `1.0`      |
| expiration     | Time limit in seconds after which the next channel in the cascade is used. Values below `60` are ignored and replaced by the default.                                                                    |    No     |    `180`      |

> [!NOTE]
> **Variables are not substituted in Text to Voice.** The `text` is read exactly as sent, so a placeholder like `<first_name>` would be read out literally. Put the final wording directly into `text` (or into `number[].text` per recipient). To make a code or number easy to understand, write it out with spaces, e.g. `1 2 3 4`.

> [!TIP]
> **SSML is supported** for finer control over how the text is spoken (pauses, spelled-out characters, …). Use SSML tags directly - do **not** wrap the whole text in `<speak>…</speak>`, the voice engine adds that itself. A surrounding `<speak>` wrapper is stripped automatically; inner tags such as `<say-as interpret-as="characters">AB</say-as>` or `<break time="300ms"/>` are kept.

## Which text is used

The spoken text is taken from the first non-empty place in this order:

| PRIORITY | PLACE                   | NOTE                                                                                           |
|:--------:|:-------------------------|:-----------------------------------------------------------------------------------------------|
| 1        | `channel.text2voice.text` | text for the Text to Voice channel                                                            |
| 2        | `number[].text`           | text of one specific recipient, see [Value `number`](https://www.bulkgate.com/en/docs/advanced-api/advanced-transactional/2.0/)     |
| 3        | `text`                    | top-level text of the request                                                                  |

## Supported languages

`language` must be one of these ISO codes. An unsupported value is rejected rather than silently replaced.

| CODE | LANGUAGE   | CODE | LANGUAGE   | CODE | LANGUAGE   | CODE | LANGUAGE    |
|:-----|:-----------|:-----|:-----------|:-----|:-----------|:-----|:------------|
| `af` | Afrikaans  | `ca` | Catalan    | `el` | Greek      | `eu` | Basque      |
| `ar` | Arabic     | `cs` | Czech      | `en` | English    | `fi` | Finnish     |
| `bg` | Bulgarian  | `da` | Danish     | `es` | Spanish    | `fr` | French      |
| `bn` | Bengali    | `de` | German     | `et` | Estonian   | `gl` | Galician    |
| `gu` | Gujarati   | `id` | Indonesian | `kn` | Kannada    | `ml` | Malayalam   |
| `he` | Hebrew     | `is` | Icelandic  | `ko` | Korean     | `mr` | Marathi     |
| `hi` | Hindi      | `it` | Italian    | `lt` | Lithuanian | `ms` | Malay       |
| `hu` | Hungarian  | `ja` | Japanese   | `lv` | Latvian    | `nl` | Dutch       |
| `no` | Norwegian  | `pt` | Portuguese | `sk` | Slovak     | `ta` | Tamil       |
| `pa` | Punjabi    | `ro` | Romanian   | `sr` | Serbian    | `te` | Telugu      |
| `pl` | Polish     | `ru` | Russian    | `sv` | Swedish    | `tr` | Turkish     |
| `uk` | Ukrainian  | `vi` | Vietnamese | `zh` | Chinese    |      |             |

## Example of full request

A verification call to two numbers. The code is spelled out with spaces so it is read digit by digit, the voice is female and speaks a little slower than normal. `country` lets the language be auto-detected when `language` is omitted.

```http-json
POST /api/2.0/advanced/transactional HTTP/1.1
Host: portal.bulkgate.com
Content-Type: application/json

{
	"application_id": 451,
	"application_token": "NKN02TWE6NfBkfl-your-secret-token-Wf05GaqLIWLW4aBj",
	"number": ["420777777777", "420777777778"],
	"country": "cz",
	"channel": {
		"text2voice": {
			"text": "Hello, your BulkGate verification code is 1 2 3 4. I repeat, 1 2 3 4.",
			"language": "en",
			"prefer_gender": "female",
			"speed": 0.9,
			"expiration": 180
		}
	}
}
```

Text to Voice as the last fallback in a cascade - Viber is tried first, then SMS, and if neither is delivered the recipient is called. Each channel keeps its own `expiration`.

```http-json
POST /api/2.0/advanced/transactional HTTP/1.1
Host: portal.bulkgate.com
Content-Type: application/json

{
	"application_id": 451,
	"application_token": "NKN02TWE6NfBkfl-your-secret-token-Wf05GaqLIWLW4aBj",
	"number": ["420777777777"],
	"text": "Your order 4517 has been shipped.",
	"channel": {
		"viber": {"sender": "BulkGate", "expiration": 300},
		"sms": {"sender_id": "gText", "sender_id_value": "BulkGate"},
		"text2voice": {"language": "en"}
	}
}
```

In the second example `text2voice` has no `text` of its own, so it reads the top-level `text` - see [Which text is used](#which-text-is-used).

The response is the same for every channel - see [Advanced transactional](https://www.bulkgate.com/en/docs/advanced-api/advanced-transactional/2.0/).
