# Barge-In

> The Barge-In is the ability of a user to interrupt a voice agent while it is speaking.

## What is barge-in in voice AI?

The ability to interrupt a voice agent mid-sentence, as in a normal conversation. The app must stop playback instantly, cancel the ongoing generation and remember which part of the answer the user actually heard.

- Topic: Voice AI
- Type: concept

## Example

Wrong:

```js
vad.on('speech', () => {
  console.log('user started talking');
});
```

Right:

```js
vad.on('speech', () => {
  player.stop();
  player.clearQueue();
  generation.abort();
  history.trimLastReply(player.playedText());
});
```

On user speech the agent stops audio, cancels generation and keeps only the part of the reply the user heard.

## Key points

- Playback stops and the audio buffer is cleared when user speech is detected.
- The conversation history keeps only the part of the answer that was played.

## Interview questions

### How do I stop a voice agent from interrupting itself?

Enable echo cancellation, so the agent's own voice from the speakers is not detected as user speech, and require a minimum speech length before barge-in.

### Should every sound interrupt the agent?

No. Short sounds like 'mm-hm' or coughs often should not stop it. Use a minimum speech duration or check the words before stopping playback.

### Why does the agent repeat things the user never heard?

The full generated reply was saved to history even though playback was cut off. Trim the stored reply to the text that was actually played.

## Related cards

- [Turn Detection](https://wonderium.dev/ai/turn-detection.md)
- [Voice Activity Detection](https://wonderium.dev/ai/voice-activity-detection.md)
- [Voice Agent](https://wonderium.dev/ai/voice-agent.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/barge-in
- Last updated: 2026-11-25
