Text to Speech
Stream speech (SSE)
Synthesize speech and stream the audio back over Server-Sent Events. Same body as /waves/v1/tts — the only difference is the response is a stream of base64-encoded PCM chunks instead of one binary blob.
Pick the model with the model body parameter, same as the sync route.
<Note> **The same URL serves the WebSocket endpoint.** `wss://api.smallest.ai/waves/v1/tts/live` accepts a WebSocket upgrade for streaming-text scenarios (LLM token streams, live captioning). The HTTP `POST` documented on this page returns SSE; use `wss://` to use the WebSocket protocol instead. See the [WebSocket reference](/models/api-reference/text-to-speech/stream-speech-web-socket). </Note>When to use this
- Use this when you want playback to start before synthesis is complete — long passages, latency-sensitive UI, live narration.
- Use sync /waves/v1/tts when total latency doesn't matter and you'd rather get one buffer.
- Use /waves/v1/tts/live (WebSocket) when the text arrives incrementally (LLM token stream). SSE assumes you have the full text up front.
How it works
- POST your text + voice settings — same payload as /waves/v1/tts, plus optional model.
- The response is Content-Type: text/event-stream. Each chunk frame is event: audio\n followed by data: {"audio": "<base64-pcm>"}\n\n.
- Decode each chunk's audio field with base64 and feed the PCM bytes to your audio pipeline (browser MediaSource, ffmpeg pipe, raw PCM player, etc.).
- A final data: {"done": true}\n\n frame marks end of stream.
Examples
cURL
curl -N -X POST "https://api.smallest.ai/waves/v1/tts/live" \
-H "Authorization: Bearer $SMALLEST_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Streaming this paragraph chunk by chunk so playback can start sooner.",
"voice_id": "magnus",
"sample_rate": 24000,
"output_format": "pcm"
}'
Common gotchas
- Use a streaming-friendly client. curl -N, Python iter_lines, or a fetch ReadableStream reader. Buffering clients will hide the latency win.
- Audio is base64 inside the event payload, not the raw event bytes. Decode the data.audio field per event.
- output_format=pcm gives the lowest overhead for streaming playback. wav/mp3 work but add per-chunk framing bytes.
post/waves/v1/tts/live
Request body
Example request
{
"output_format": "mp3"
}Response
Synthesized speech retrieved successfully.