- "description": "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.\n\nPick the model with the `model` body parameter, same as the sync route.\n\n<Note>\n **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).\n</Note>\n\n## When to use this\n\n- **Use this** when you want playback to start before synthesis is complete — long passages, latency-sensitive UI, live narration.\n- **Use sync `/waves/v1/tts`** when total latency doesn't matter and you'd rather get one buffer.\n- **Use `/waves/v1/tts/live`** (WebSocket) when the *text* arrives incrementally (LLM token stream). SSE assumes you have the full text up front.\n\n## How it works\n\n1. POST your text + voice settings — same payload as `/waves/v1/tts`, plus optional `model`.\n2. The response is `Content-Type: text/event-stream`. Each chunk frame is `event: audio\\n` followed by `data: {\"audio\": \"<base64-pcm>\", \"done\": false, \"status\": \"206\"}\\n\\n`.\n3. 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.).\n4. A final `data: {\"status\": \"200\", \"done\": true}\\n\\n` frame marks end of stream. Detect the terminator with `done == true`; every chunk frame also carries `done: false`, so `\"done\" in msg` matches every frame.\n\n## Examples\n\n**cURL**\n```bash\ncurl -N -X POST \"https://api.smallest.ai/waves/v1/tts/live\" \\\n -H \"Authorization: Bearer $SMALLEST_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"text\": \"Streaming this paragraph chunk by chunk so playback can start sooner.\",\n \"voice_id\": \"magnus\",\n \"sample_rate\": 24000,\n \"output_format\": \"pcm\"\n }'\n```\n\n## Common gotchas\n\n- **Use a streaming-friendly client.** `curl -N`, Python `iter_lines`, or a `fetch` `ReadableStream` reader. Buffering clients will hide the latency win.\n- **Audio is base64 inside the event payload**, not the raw event bytes. Decode the `data.audio` field per event.\n- **`output_format=pcm`** gives the lowest overhead for streaming playback. `wav`/`mp3` work but add per-chunk framing bytes.\n",
0 commit comments