Streaming Audio
Receive audio chunks as they are generated for lower latency:Async Streaming
For async applications:LLM Integration: Streaming Sessions
For real-time TTS when streaming text from an LLM (like GPT-4, Claude, etc.):Async Streaming Session
Synchronous Streaming Session
Session Reuse
End a session without closing the WebSocket to avoid reconnection overhead when starting a new session (see Turn lifecycle):Barge-in (interrupt the current turn)
When the end user speaks over the agent, callcancel_current() to stop
generating the current turn immediately and drop any buffered/queued text —
without closing the WebSocket. Unlike end_session(), no remaining text
is flushed; the turn is abandoned. The socket stays open so the next
send() starts the next turn right away.
cancel_current() returns once the server acknowledges, or after a short quiet
timeout if the server goes silent. Stop local playback as soon as you call it —
a few in-flight frames may arrive before the acknowledgement. See
Barge-in for the
full protocol. The synchronous wrapper exposes cancel_current() too.
Updating settings mid-session
Change generation parameters on a live connection without reconnecting viaupdate_settings(). It sends an explicit, acknowledged update and returns
the parameters now in effect:
cfg_scale, temperature, speed,
max_new_tokens, language, normalize. Identity / audio-format settings
(voice_id, model_id, sample_rate, output_format, dictionary_ids) are
fixed for the connection — change those with update_config() after
end_session(). The change applies to the next turn; call it between turns.
The server rejects an out-of-range value or a non-updatable field with a typed
error. StreamingSessionSync and MultiContextSession expose update_settings()
too (on the multi session it is session-scoped and applies to contexts started
after the update).
Streaming session reference
A session is created withstreaming_session(...) (async) or
streaming_session_sync(...) (sync). Both accept the same configuration:
voice_id, model_id, cfg_scale, temperature, max_new_tokens,
sample_rate, flush_timeout_ms, normalize, language, word_timestamps,
speed, dictionary_ids, and an on_word_timestamps callback.
Although voice_id defaults to None in the SDK signature, it must be set
before the first synthesis; omission fails with MISSING_VOICE_ID.
The async StreamingSession exposes:
StreamingSessionSync mirrors the async API without await/async for:
send(), flush(), and drain() return list[AudioChunk]; cancel_current(),
close(), and the last_word_timestamps / last_final / last_usage
properties behave the same.
Tuning streaming latency
By default the server accumulates LLM tokens and only begins generating at natural sentence boundaries. Tune how eagerly it starts with these session parameters:chunk_length_schedule, auto_mode, and max_buffer_length are set by
constructing a StreamConfig and passing it where a config is
accepted, or via session.update_config(...):
Multi-Context Sessions
A multi-context session manages up to 20 independent audio-generation contexts over a single WebSocket (see limits). Each context has its own text buffer, voice settings, and generation queue — useful for multi-speaker conversations, pre-buffering one stream while another plays, or interleaving audio for dynamic dialogue.multi_context_session(...):
Every context that synthesizes text must have an effective voice. Set
default_voice_id on the session or pass voice_id to every
create_context() call; otherwise the first text sent to that context fails
with MISSING_VOICE_ID.
MultiContextSession methods:
Word Timestamps in Streaming
Word timestamps work with one-shot streams and streaming sessions. During a one-shot stream, they are yielded aslist[WordTimestamp] objects between
audio chunks:
Word Timestamps in Streaming Sessions
Request word-level time alignments alongside audio. Timestamps are delivered per chunk after the corresponding audio data:Next steps
- Types & Errors —
AudioChunk,StreamConfig,SessionUsage,WordTimestamp - Text Normalization — languages and spell tags in streaming