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

# Text-to-Speech Overview

> When to use the WebSocket API vs the REST endpoint, and how the pieces fit together

Gradium exposes Text-to-Speech over two transports. They share the same
models and voices; you pick the transport that matches your input shape
and latency needs.

## WebSocket vs REST

| If your text is... | Use | Why |
| - | - | - |
| Streamed in token-by-token (LLM output, agent loop, live UI) | [WebSocket](https://docs.gradium.ai/guides/text-to-speech.md) | Lowest first-byte latency. Send text as it arrives, audio chunks come back as soon as they're generated. |
| A finished block in hand (article, scripted line, batch job) | [REST](https://docs.gradium.ai/guides/text-to-speech-rest.md) | One HTTP call, no connection to manage. Save the response body to a file and you're done. |
| Many concurrent synthesis requests | [WebSocket + Multiplexing](https://docs.gradium.ai/guides/multiplexing.md) | Run several requests over a single socket, matched by `client_req_id`. |
| Browser or mobile app audio | [Browser WebSockets](https://docs.gradium.ai/guides/browser-websockets.md) | Use short-lived tokens instead of exposing an API key. |

If you're unsure, start with REST. It's a single POST and the response
body is the audio. Move to WebSocket once latency or streaming-input
concerns make REST the bottleneck.

## What both transports share

* **Voices**: any `voice_id` from the [Voice Library](https://docs.gradium.ai/guides/voices/overview.md) works on both. [Voice Design](https://docs.gradium.ai/guides/voices/voice-design.md) candidates are the exception: REST only, until converted.
* **Output formats**: PCM, WAV, Opus, and the telephony codecs (`ulaw_8000`, `alaw_8000`).
* **Voice settings**: `temp`, `padding_bonus` and `rewrite_rules`, all passed inside `json_config`. See [Voice Settings](https://docs.gradium.ai/guides/voice-settings.md).

## What's transport-specific

* **`<flush>` and `<break time="..." />` tags** are processed by the model in both transports, but only meaningfully useful when you're streaming text in over the WebSocket.
* **WebSocket-only**: setup-message stream controls (`send_setup_on_start`, `wait_for_ready_on_start`), multiplexing, in-stream `flush`, browser tokens, pronunciation dictionaries (`pronunciation_id`). See [WebSocket Lifecycle](https://docs.gradium.ai/guides/websocket-lifecycle.md). Over REST, use `rewrite_rules` in `json_config` for pronunciation control.
* **REST-only**: `only_audio` toggle to choose between raw audio bytes and an NDJSON stream that mirrors the WebSocket protocol.

## Next steps

> [card] [Use the WebSocket API](https://docs.gradium.ai/guides/text-to-speech.md)
>
> SDK and direct WebSocket usage, streaming output, flush, timestamps.

> [card] [Use the REST API](https://docs.gradium.ai/guides/text-to-speech-rest.md)
>
> One-shot synthesis with a single HTTP POST.

> [card] [LLM to TTS](https://docs.gradium.ai/guides/recipes/llm-to-tts.md)
>
> Stream generated text into TTS while preserving natural prosody.

> [card] [Voice settings](https://docs.gradium.ai/guides/voice-settings.md)
>
> Speed, temperature and rewrite rules.

> [card] [Voice Library](https://docs.gradium.ai/guides/voices/overview.md)
>
> Browse flagship voices or create your own clones.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.