SDK
Text to speech
Create speech
Audio formats
HTTP and SSE streaming
WebSocket streaming

WebSocket streaming

Use stream_input() when text arrives in fragments, such as output from a language model.

1. Open a session

Python

stream = client.audio.speech.stream_input(
    voice="default",
    response_format="mp3",
    quality="fast",
)

2. Send text and read audio

Python

with stream:
    stream.send_text("The first fragment ")
    stream.send_text("and the final fragment.", flush=True)
    stream.finish()

    for event in stream:
        if event.audio:
            player.write(event.audio)
        if event.is_final:
            break

flush() completes the current utterance. finish() ends input and lets the remaining audio drain. Async sessions use awaited methods and async iteration.

Session options

OptionAccepted values
response_formatpcm or mp3
output_sample_rate8000–48000 Hz
qualityfast or expressive
chunk_length_scheduleOptional sequence of chunk targets
auto_modeTrue or False

Alignment collections are wire-compatible placeholders, not timestamp data.