Barge-in lets a caller talk over a voice agent and be heard: the agent stops speaking, drops the rest of its reply, and answers what the caller just said. It takes three things working together: hearing the caller while the agent is speaking, stopping audio that is already playing, and cancelling the model that was writing the reply. In VoiceAI SDK, session.converse does all three when the session supports interruptions.
The examples use the planned 1.0 API of VoiceAI SDK, a developer preview, and were not run against live provider accounts. How quickly speech stops after the caller starts talking depends on the provider and the transport, so this post gives no figures.
Barge-in at a glance
| Step | What the session does | What you control |
|---|---|---|
| The caller starts talking during a reply | Voice activity detection hears speech | Whether the session supports interruptions |
| The reply stops | Stops the current speech and emits interrupt | session.on("interrupt", fn) |
| The model stops | Aborts ctx.signal for the turn | Passing ctx.signal to the model and to any fetch |
| The caller finishes | Waits for vad.silenceMs of quiet, then produces a final transcript | vad.silenceMs |
| The next turn starts | Calls your handler with the new text | What the model is told about the interruption |
Check that the session can be interrupted
Barge-in needs both directions to stream: the session has to hear the caller while it speaks, and stop audio already on its way. session.capabilities.interruptions tells you whether the session you opened can. In a pipeline it is true only when the speech-to-text half streams transcripts and the text-to-speech half streams audio.
import { createSession } from "voiceai-sdk";
import { cartesia } from "voiceai-sdk/cartesia";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession({ stt: deepgram(), tts: cartesia({ voice: process.env.VOICE_ID }) });
if (!session.capabilities.interruptions) {
console.warn(`${session.provider} can't be interrupted. Keep replies short.`);
}When it is false, replies play to the end, and session.interrupt() still stops speech when you call it. Ask the model for short replies, so the caller doesn't wait long for a turn. With openai(), barge-in uses the Realtime API's server-side voice activity detection.
Stop the model with ctx.signal
When the caller interrupts, the session stops speaking, but a model that is still writing keeps going unless you stop it. Pass ctx.signal to the model call and to anything else the handler waits on:
import { streamText } from "ai";
await session.converse(async (text, ctx) => {
const res = await fetch("https://api.example.com/account/plan", { signal: ctx.signal });
const plan = await res.json();
const result = streamText({
model: "openai/gpt-5",
system: `You answer billing questions. The caller's plan: ${JSON.stringify(plan)}`,
messages: [...ctx.history, { role: "user", content: text }],
abortSignal: ctx.signal,
});
return result.textStream;
});When the signal aborts, the lookup and the model stream both stop. Words nobody will hear are not generated, and the next turn starts from what the caller said.
Tell the model it was cut off
After an interruption, the model doesn't know the caller missed the end of its last reply, and it may repeat the whole answer. Set a flag on interrupt and add a note to the next turn:
import { streamText } from "ai";
let cutOff = false;
session.on("interrupt", () => {
cutOff = true;
});
await session.converse((text, ctx) => {
const note = cutOff ? " The caller interrupted your last reply. Answer what they just said, and don't repeat the old reply." : "";
cutOff = false;
const result = streamText({
model: "openai/gpt-5",
system: "You answer billing questions in short sentences." + note,
messages: [...ctx.history, { role: "user", content: text }],
abortSignal: ctx.signal,
});
return result.textStream;
});Choose when the caller's turn ends
Barge-in decides what happens when the caller starts talking. Turn detection decides when they have finished. The session waits for vad.silenceMs of quiet before it treats the turn as over:
import { createSession } from "voiceai-sdk";
import { cartesia } from "voiceai-sdk/cartesia";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(
{ stt: deepgram(), tts: cartesia({ voice: process.env.VOICE_ID }) },
{ vad: { silenceMs: 800 } },
);- A shorter value answers sooner, but cuts in when the caller pauses mid-sentence.
- A longer value lets the caller pause to think, but every reply starts later.
Tune it on recordings of real calls. Whether a provider accepts a custom silenceMs depends on the provider; one that can't fails at createSession with unsupported.
Write replies that survive interruption
- Put the answer first. If the caller cuts in after one sentence, they should already have what they asked for.
- Keep greetings short. Callers often start talking before a long greeting ends.
- Avoid long lists. Offer two options and ask, instead of reading out six.
- Stop from your own code when you need to.
session.interrupt()stops the current speech, for example when a supervisor presses Stop in a dashboard.
Common questions
What is the difference between barge-in and turn detection? Turn detection decides when the caller has finished, after vad.silenceMs of quiet. Barge-in decides what happens when the caller starts talking while the agent is still speaking. A voice agent needs both.
Does barge-in work on phone calls? Yes, through a transport such as twilioMediaStream(ws), as long as interruptions is true for the session. How much audio already sent to the call still plays depends on the provider and the transport.
Can background noise trigger barge-in? It can. Voice activity detection can take noise for speech, and how well it tells them apart depends on the provider. Test with recordings from the places your callers call from, such as cars and busy rooms.
What does the model see on the next turn? ctx.history holds the earlier turns, and your handler gets the caller's new words as text. To make the model aware that a reply was cut off, use the interrupt flag shown above.
Next steps
- Interruptions and barge-in: every control for interruptions in one place.
- Capabilities: when
interruptionsis true for a provider or a pipeline. - Latency and audio formats: how
vad.silenceMsadds to the wait before each reply.
More guides on the VoiceAI SDK blog, or start with the quickstart.