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

HTTP and SSE streaming

Use this flow when all text is already available and audio should start before generation finishes.

Raw audio

Python

with client.audio.speech.with_streaming_response.create(
    model="teen-v1",
    voice="default",
    input="Write audio while it is generated.",
    response_format="mp3",
) as response:
    response.stream_to_file("speech.mp3")

Use iter_bytes() instead of stream_to_file() when forwarding chunks to a player or downstream response.

SSE events

Python

with client.audio.speech.with_streaming_response.create(
    model="teen-v1",
    voice="default",
    input="Return audio events.",
    response_format="mp3",
    stream_format="sse",
) as response:
    for event in response.iter_events():
        if event.type == "audio.delta":
            consume(event.audio)

SSE returns ordered audio.delta events followed by audio.done. Async clients provide async context managers and async for iteration.