Barge-In & Full-Duplex State Machine
Voice & Conversational Audio AI Agents Testing β Day 4
Test full-duplex voice state transitions (IDLE, LISTENING, THINKING, SPEAKING, INTERRUPTED), enforce <150ms barge-in TTS cancellation SLOs, guard against AEC self-interruption, and verify zero ghost audio buffers.
Natural phone conversations are full-duplex: callers interrupt long policy disclaimers mid-sentence. When barge-in fails to cancel TTS within 150ms or leaves stale audio chunks in the outbound queue, callers hear jarring ghost speech. Conversely, without an Acoustic Echo Cancellation (AEC) guard, the agent interrupts itself on speakerphone.
The official reference codebase for Day 4 is hosted in the repository. Clone the repository and navigate to day-4-barge-in-duplex/test_day4.py to run the working solution.
git clone https://github.com/777abhi/voice-ai-testing-roadmap.git
cd voice-ai-testing-roadmap/day-4-barge-in-duplex/test_day4.pyTest Barge-In Cancellation & AEC Echo Guard
Run the Day 4 full-duplex state machine and barge-in SLO tests.
npm run test:day4# Own TTS echo must NOT interrupt playback
assert not agent.receive_mic_frame(energy=4500.0, matches_aec_reference=True)
# Genuine caller barge-in cancels TTS within 150ms and flushes remaining buffer
assert agent.receive_mic_frame(energy=3800.0, matches_aec_reference=False, cancel_latency_ms=95.0)
assert agent.state == VoiceState.LISTENING and len(agent.tts_buffer) == 0- Modeled the full-duplex voice lifecycle: IDLE -> LISTENING -> THINKING -> SPEAKING -> INTERRUPTED.
- Verified AEC echo guards suppress agent self-interruption during speakerphone playback.
- Enforced <150ms barge-in TTS cancellation SLO and zero ghost/stale audio chunks after interruption.
π§ Knowledge Check
What are the two mandatory invariants when a caller legitimately barges in while a voice agent is speaking?