> ## 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 Quickstart

> Pick a voice, generate an audio file, and stream speech over a WebSocket with the Plivo Text-to-Speech API.

> [!NOTE]
>
> List voices, generate your first WAV file with one curl command, then stream speech over a WebSocket.

## Prerequisites

1. A Plivo account. Copy your **Auth ID** and **Auth Token** from the [Plivo Console](https://cx.plivo.com/home).

***

## Step 1: Pick a voice

```bash theme={null}
curl "https://api.plivo.com/v1/Account/<auth_id>/TTS/Voices/" -u '<auth_id>:<auth_token>'
```

Copy a `voice_id` whose `languages` include the language you want.

```json theme={null}
{"api_id": "148d6af0bee98c09", "meta": {"limit": 33, "total_count": 33, ...}, "objects": [{"voice_id": "lC7qzMoRE7SSjaNCVeff", "name": "Hailey", "gender": "female", "languages": ["en-US"], "accent_type": "American", ...}]}
```

***

## Step 2: Generate a file

```bash theme={null}
curl -X POST "https://api.plivo.com/v1/Account/<auth_id>/TTS/" \
  -u '<auth_id>:<auth_token>' \
  -H "Content-Type: application/json" \
  -d '{"voice_id": "<voice_id>", "text": "Hello from Plivo", "language": "en-US",
       "output_format": {"container": "wav", "encoding": "pcm_s16le", "sample_rate": 24000}}' \
  -o hello.wav
```

Play `hello.wav`.

***

## Step 3: Stream speech

Open the WebSocket and send a `text` message. Audio arrives as binary frames.

```python theme={null}
import asyncio, base64, json, websockets

URL = "wss://api.plivo.com/v1/Account/<auth_id>/TTS/Realtime/"
AUTH = {"Authorization": "Basic " + base64.b64encode(b"<auth_id>:<auth_token>").decode()}

async def main():
    async with websockets.connect(URL, additional_headers=AUTH) as ws:
        await ws.send(json.dumps({
            "type": "text", "context_id": "c1", "voice_id": "<voice_id>",
            "text": "Hello from Plivo", "finish": True,
        }))
        audio = bytearray()
        async for msg in ws:
            if isinstance(msg, bytes):
                id_len = int.from_bytes(msg[:2], "little")
                audio += msg[2 + id_len:]          # strip [id length][context_id]
            elif json.loads(msg)["type"] == "done":
                break
        open("hello.raw", "wb").write(audio)       # raw pcm_s16le, 24 kHz

asyncio.run(main())
```

***

## Next steps

* [Realtime: contexts, flush and cancel](https://plivo.com/docs/models/text-to-speech/concepts/realtime.md)
* [Custom pronunciation](https://plivo.com/docs/models/text-to-speech/concepts/pronunciation.md)
* [Batch API reference](https://plivo.com/docs/models/text-to-speech/api/batch.md)
