Skip to navigation

Stream text to speech

View as Markdown

Stream text and receive base64-encoded 24 kHz PCM audio over an authenticated WebSocket.

Message flow

  1. Send {"text":" "} immediately after connecting. This initialization space is not billed.
  2. Send text fragments while receiving audio chunks. Set flush:true to finish a segment without closing the connection. Audio may arrive before a flush.
  3. Send {"text":""} to end input. Keep receiving until {"isFinal":true}, then the connection closes.

Output streams automatically. Only automatic generation is supported. There is no public flush-completion event; isFinal completes the whole connection. See the TTS input streaming guide for a runnable example.

Handshake

WSS
wss://api.narilabs.com/v1/text-to-speech/:voice_id/stream-input

Authentication

AuthorizationBearer
A Nari API key created in the Dashboard.

Path parameters

voice_idstringRequired
Voice ID from the selected model catalog, such as diana.

Query parameters

model_idenumRequired

Select Standard (qwen3-tts) or Fast (qwen3-tts-fast).

Allowed values:
output_formatenumOptionalDefaults to pcm_24000

Raw 24 kHz PCM16 mono audio; no WAV header.

Allowed values:
language_codestringOptionalDefaults to auto

Use auto or the selected voice’s language code.

seedintegerOptional0-4294967295Defaults to 0

Random seed used for each segment; defaults to 0.

inactivity_timeoutintegerOptional1-180Defaults to 20

Seconds without incoming messages before the connection closes; defaults to 20.

auto_modebooleanOptionalDefaults to true

Omit or set to true; false is rejected.

sync_alignmentbooleanOptionalDefaults to false

Only false is supported; alignment is unavailable.

enable_ssml_parsingbooleanOptionalDefaults to false

Only false is supported; SSML is unavailable.

apply_text_normalizationenumOptionalDefaults to off

Only off is supported.

Allowed values:

Send

InitializeobjectRequired

Send {"text":" "} once to initialize the connection.

OR
Send text / flushobjectRequired

Append text. Set flush:true to finish the current segment and keep the connection open.

OR
End inputobjectRequired

Send empty text and keep receiving until isFinal arrives.

Receive

Audio chunkobjectRequired

Decode the base64 audio as raw PCM16 at 24 kHz. Chunks arrive in order.

OR
Connection completeobjectRequired

The isFinal:true message confirms that all audio for the connection has been sent.

OR
ErrorobjectRequired

A terminal error may be followed by a non-1000 WebSocket close.