
Use this flow when all text is already available and audio should start before generation finishes.
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.
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.
Do not automatically replay a partial stream. Retrying after bytes were delivered can duplicate speech.
On this page