> ## Documentation Index
> Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-speech

> List Plivo voices, turn text into an audio file, manage pronunciation lexicons and check text-to-speech usage from the terminal.

`plivo tts` works with [Plivo Text-to-Speech](https://plivo.com/docs/models/text-to-speech/overview.md): list the voices, turn text into an audio file, manage pronunciation lexicons, and see what you have generated. Requires Plivo CLI v1.3.3 or later; `tts voice` and the regional English codes need v1.4.1. After [logging in](https://plivo.com/docs/cli/install.md#log-in-with-a-browser), list the voices for a language:

```bash theme={null}
plivo tts voices --language hi
```

* Replace `<values>` with your own and omit `[flags]` unless adding options. Global flags: see [Configuration](https://plivo.com/docs/cli/configure.md).
* `tts speak` is billed per character, so it needs `--yes`. Preview it first with `--dry-run`.
* Realtime text-to-speech for voice agents is a WebSocket API with no CLI command. See [Realtime](https://plivo.com/docs/models/text-to-speech/concepts/realtime.md), or install the [text-to-speech skill](#use-it-from-a-coding-agent).

| Usage | What it does |
| - | - |
| `plivo tts voices [flags]` | List the voices you can speak with: Plivo's public voices and any your organization owns |
| `plivo tts voice <voice_id>` | Show one voice: its languages, accent, description, whether it supports lexicons, and a sample URL that works for an hour (v1.4.1) |
| `plivo tts speak [flags]` | Turn text into an audio file (billed per character) |
| `plivo tts lexicons list` | List pronunciation lexicons |
| `plivo tts lexicons get <lexicon_id>` | Get a lexicon and its rules |
| `plivo tts lexicons create [flags]` | Create a lexicon of word pronunciations |
| `plivo tts lexicons delete <lexicon_id>` | Delete a lexicon (requires `--yes`) |
| `plivo tts usage` | Show the characters and audio generated so far, batch and realtime |

## Pick a voice

Each voice speaks one language. `--language` and `--gender` filter the list in the CLI; the API has no filters.

```bash theme={null}
plivo tts voices --language en-IN --gender female
plivo tts voice 6uWzc4xFj31t4jNJUaED
```

| Flag | Description |
| - | - |
| `--language <code>` | only voices for this language: `en`, `en-US`, `en-GB`, `en-IN`, `en-AU`, `hi`, `bn`, `ta`, `te`, `mr`, `gu` or `kn`. `en` lists every English voice; a regional code lists one accent. |
| `--gender <value>` | only voices of this gender: `male` or `female` |

From v1.4.1, `tts voices -o json` and `tts voice` show a `lexicon` field: whether the voice can use a pronunciation lexicon.

## Turn text into an audio file

```bash theme={null}
plivo tts speak --voice lC7qzMoRE7SSjaNCVeff --text "Hello from Plivo" --out hello.wav --dry-run
plivo tts speak --voice lC7qzMoRE7SSjaNCVeff --text "Hello from Plivo" --out hello.wav --yes
plivo tts speak --voice 6uWzc4xFj31t4jNJUaED --language hi --file msg.txt --out msg.ulaw --yes
```

`--dry-run` prints the request and the character count and sends nothing. Without `--yes`, `speak` is refused with `DESTRUCTIVE_REFUSED` (exit `5`).

| Flag | Description |
| - | - |
| `--voice <voice_id>` | the voice, from `plivo tts voices` (required) |
| `--text <string>` | the text to speak, up to 5,000 characters |
| `--file <path>` | read the text from a file (`-` reads stdin) |
| `--out <path>` | file to write the audio to (required). `-` writes to stdout, which is refused on a terminal. |
| `--format <value>` | `wav` (24 kHz), `mp3` (44.1 kHz, 128 kbps), `mulaw` or `alaw` (8 kHz telephony, raw) or `pcm` (24 kHz, raw). Without it, the `--out` extension decides (`.wav`, `.mp3`, `.ulaw`, `.alaw`, `.pcm`); anything else is wav. |
| `--language <code>` | `auto` (default), `en-US`, `en-GB`, `en-IN`, `en-AU`, `hi`, `bn`, `ta`, `te`, `mr`, `gu` or `kn`, in any letter case. From v1.4.1 a bare `en` is refused before any request: pick the regional code the voice speaks. |
| `--sample-rate <int>` | sample rate in Hz (default from `--format`) |
| `--bitrate <int>` | mp3 bitrate in bits per second (default depends on the sample rate) |
| `--pace <float>` | speaking pace, `0.7` to `1.2` (default `1`) |
| `--volume <float>` | volume, `0.5` to `2.0` (default `1`) |
| `--lexicon <lexicon_id>` | apply a saved lexicon |
| `--seed <int>` | repeatable output: the same text, voice and seed give identical audio |

* For a phone call, use `mulaw` or `alaw`: 8 kHz audio that needs no conversion.
* Text that was cut off, starts with a byte order mark (BOM) or isn't UTF-8 is refused before the send. So is an `--out` the CLI can't write.
* The audio is saved only when the whole file arrives. If something fails after the request was sent, the request may already be billed: the error says so. Compare `plivo tts usage` with the reading from before, and don't send it again blindly.

## Pronunciation lexicons

A lexicon holds up to 100 rules, each a word and how to say it. `--kind` sets how every value is written: `ipa`, `arpa` (ARPAbet) or `respell`. See [Pronunciation](https://plivo.com/docs/models/text-to-speech/concepts/pronunciation.md).

```bash theme={null}
plivo tts lexicons create --name brands --kind respell --rule "Plivo=PLEE-voh"
plivo tts speak --voice <voice_id> --lexicon <lexicon_id> --text "Welcome to Plivo" --out welcome.wav --yes
```

| Flag on `lexicons create` | Description |
| - | - |
| `--name <string>` | lexicon name, up to 100 characters (required) |
| `--kind <value>` | how the values are written: `ipa`, `arpa` or `respell` (required) |
| `--rule <word=value>` | one rule (repeatable) |
| `--file <path>` | a JSON array of `{"word": ..., "value": ...}` |

## Use it from a coding agent

`plivo skill install tts` installs the text-to-speech skill (v1.3.3). Your coding agent picks a voice, checks your credit, previews the request and sends it only after you agree. It also covers the realtime WebSocket API, which has no CLI command. See [Build with an AI coding agent](https://plivo.com/docs/models/text-to-speech/ai-coding-agent.md).
