TTS input streaming
Send text and receive generated audio on the same WebSocket. Output streams automatically; there is no separate stream: true option.
Connect
Open wss://api.narilabs.com/v1/text-to-speech/{voice_id}/stream-input?model_id=qwen3-tts with Authorization: Bearer YOUR_API_KEY in the handshake. Use a voice ID supported by the selected model. qwen3-tts is Standard; qwen3-tts-fast is Fast.
Connect from your backend: browser WebSocket clients cannot set an Authorization header. Keep x-request-id from the handshake for troubleshooting. The WebSocket API reference lists optional query parameters and message fields.
Send text and flush
Send JSON text messages in this order:
Send each line as a separate message. Start with exactly one space; it is not billed. Later text fragments join without added spaces, so include spaces between words yourself. Audio may arrive before a flush when enough text is available; short input may wait for more text or a flush. flush: true completes a segment and keeps the connection open; empty text ends input. Continue receiving until the connection finishes.
Only automatic generation is supported. Omit auto_mode or set it to true; false, generation_config, generator_config, and try_trigger_generation are rejected.
Receive audio
Receive messages concurrently while sending text:
Decode audio from base64 into 24 kHz, 16-bit little-endian, mono PCM. There is no WAV header. Append chunks in arrival order.
The final message is:
isFinal completes the connection. Individual flushes have no completion event; see Request logs for their results.
Python example: two flushes
Install websockets version 14 or later and set NARI_API_KEY. This script saves both segments as one speech.pcm file.
Play the PCM file with:
If the connection ends before isFinal, the audio may be incomplete. See WebSocket failures and Usage and billing.