Skip to main content
By default the server speaks each reply in its own voice, which is Cartesia. To speak the replies yourself, set output_modalities: ["text"] in your session.update. The reply then streams as response.output_text.delta, with no audio events, and you send it to the text-to-speech provider of your choice.

Full code on GitHub

A Python agent that speaks each reply through ElevenLabs as it streams, with every section of this page in code.
Building with a coding agent? The coding agent version of this guide gives you the prompts, what to check, and what to tell your agent when it goes wrong.

When to use your own text-to-speech

The server’s voice needs no wiring. Audio arrives as response.output_audio.delta at the pace it plays, the words arrive as response.output_audio_transcript.delta, and the server tracks playback itself, so barge-in and conversation history follow what the caller heard. Pick a voice with audio.output.voice, a Cartesia voice id. Dialog-RSN-1 can also write Cartesia’s non-speech tags, such as [laughter], and the server’s voice performs them. The response style recipes show how to ask for them. Use your own text-to-speech when you want:
  • a voice or vendor other than Cartesia,
  • control over playback, such as your own buffering or audio pipeline,
  • the reply as text first, so you can log it or run your own guardrails over it before a caller hears it.
You then own the parts the server handles for its own voice: streaming the text, stopping on a barge-in, and telling the server what the caller heard. A text-to-speech failure shows up as a broken call rather than an API error, so the rest of this page covers what most often goes wrong.

Stream each delta to TTS

response.output_text.delta arrives while the model is still writing the reply. Push each delta to a streaming TTS context as it arrives, and the voice starts speaking before the reply is finished. Waiting for response.output_text.done adds the whole generation to the caller’s silence.
pseudocode
Push only the new text each event carries. Re-sending the whole reply on every delta makes the provider synthesize it again and adds latency. A delta can end mid-word. If your provider’s prosody suffers from split words, hold back the text after the last space until the word is complete. Check your provider’s buffering setting too. Some wait for more text before they speak, and a lower delay gets the first words out sooner.

Open one TTS context per response

Open one TTS streaming context per response_id, and start it on response.created. A barge-in can cancel a response mid-stream, and a context per response means a canceled reply’s audio can’t leak into the next one. When the model calls a tool that looks slow, such as an API lookup, it says a short line too, like “let me check that”. That line arrives as the response’s text and goes through the same context.

Stop speaking on barge-in

When the caller talks over a reply, Dialog-RSN-1 checks that the sound is the caller and then sends input_audio_buffer.speech_started. Stop the reply straight away. Stopping takes two steps:
  1. Cancel the TTS context for that response. Stop feeding it text so it synthesizes no more audio for that reply.
  2. Flush what’s already queued in the speaker. Audio synthesized before the cancellation can still be in a playback buffer, and closing the TTS context doesn’t clear it. Clear it yourself, or the caller keeps hearing the end of a reply they interrupted.
Most replies finish generating well before they finish playing, so speech_started is usually the only signal you get. If the reply was still generating, response.done with status: "cancelled" follows too. Both mean the same thing, so stop only once. With push-to-talk (turn_detection: null) nothing barges in. Send response.cancel and stop playback yourself when the caller presses the button.

Playback reports

With your own text-to-speech, only your client knows what the caller is hearing. Three client events tell the server: poly.output_audio.started, .delta and .stopped. They change two things.
  • Barge-in follows your real playback. For as long as a reply is audible, Dialog-RSN-1 checks that a sound like an “mm-hm” or a cough is a real interruption before it stops the reply. Reports tell it exactly how long your reply is audible, so a backchannel late in a slow reply still gets that check.
  • History keeps what the caller heard. On stopped, the server cuts the reply in conversation history back to spoken_text, ending in a dash if dropped_ms says it was cut off. The model’s next turn then knows exactly where the caller cut in, and doesn’t assume they heard the rest.
Send them as your speaker plays the reply:
you send: playback reports
  • Send started when the first sample of the reply plays.
  • Send a delta about every 250 ms, with audio_ms, the cumulative milliseconds played so far, and delta, the text spoken since the last report. Because audio_ms is cumulative, a lost report leaves the count in step.
  • Send stopped when the reply finishes or is cut off, with audio_ms, dropped_ms (audio synthesized but never played) and spoken_text (everything the caller heard). Always send it, even when the reply played to the end. Until it arrives, the server treats the reply as still playing.
  • Carry the response_id from response.created through every report about that reply. A report that names a response that is no longer playing is ignored.
Count what the speaker has played, not what the synthesizer has sent, because a reply can be synthesized seconds ahead of playback. To turn milliseconds into words, use your provider’s word or character timestamps: every word whose audio had started by audio_ms. Cartesia sends word timestamps, and ElevenLabs sends character alignment when you ask for it. Reports are optional. Without them, the server estimates playback from a typical speaking rate, and your voice’s real pace and buffering make that estimate drift. The first report you send replaces the estimate for the rest of the session, so once you start, send reports for every reply. On a session where the server speaks the reply, it tracks playback itself and ignores reports. The API reference lists the event fields. If you evaluate your agent, send reports in your test harness exactly as your production client does.

Skip text with nothing to say

A reply can be empty, or only punctuation, once you strip tags and whitespace. Most TTS providers reject that with a 400, and if your code treats a TTS failure as fatal, that 400 ends the call. Check what’s left and skip the synthesis call when nothing is:
pseudocode

Strip tags before text-to-speech

If your instructions ask for an emotion tag on each reply, strip it before the text reaches your synthesizer. Send [reassuring] Don't worry, I can get that sorted for you. straight to TTS and most providers say “reassuring” out loud before the reply. Parse the tag where text leaves your code for TTS, and pass it as a style or voice parameter:
pseudocode
The tag is optional, so handle text without one. It can also arrive split across deltas, so hold back the start of a reply until you’ve seen the closing bracket. Non-speech tags work the other way. If your voice performs tags such as a laugh, tell the model in your instructions which tags your provider accepts and pass them through. Either way, strip tags from the text you show or log.

Measure time to first audio

The caller hears nothing until your speaker plays the reply’s first sample. Measure latency to that point: from the end of the caller’s turn to first audio. It includes the model, your text buffering and the round trip to your synthesizer, and the caller hears all of it as silence. Time the first response.output_text.delta too. The gap between first text and first audio is your text-to-speech’s share, and if first text is fast but first audio is slow, look at your provider’s buffering and whether you open a new TTS connection for each reply. Evaluating a Dialog-RSN-1 agent defines each latency metric.

Next steps

Voice agent with Cartesia

A sample app with everything on this page: a Python server and browser page that stream each reply into Cartesia.

Response style

Instructions for spoken replies: text normalization for your voice, emotion tags and non-speech tags.

API reference

The fields of poly.output_audio.started, .delta and .stopped.

Evaluation

Time to first token, time to first audio, and how to measure the gap.
Last modified on November 24, 2026