HomeRoadmapsVoice AI Day 4
Voice & Conversational Audio AI Agents Testing Β· Day 4 Β· 20 min

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.

⚑ Runtime: Python 3.10+ Β· Zero External Dependencies (unittest + wave)πŸŽ™οΈ Voice & Conversational Audio AI QE Lead
Full-DuplexBarge-InAEC Echo GuardTTS FlushPython unittest
About this lab

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.

πŸ“¦Sample Codebase & Working Solution (Day 4)Available Now
View on GitHub

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 β€” 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.py
🏭Production Context & Contact-Center Implementation
πŸ’‘ Why We Are Doing This: Unflushed TTS buffers and speakerphone echo loops ruin conversational naturalness and cause callers to hang up or mash zero for a human agent.
🏒 Real-World Production Usecase: Deterministic full-duplex state machine verifying AEC self-interruption suppression, <150ms barge-in cancel SLO, and zero stale audio chunks.
βš™οΈ How Implemented in Production: VoiceState and FullDuplexAgent in voicelab/duplex.py.
Phase 1

Test Barge-In Cancellation & AEC Echo Guard

Run the Day 4 full-duplex state machine and barge-in SLO tests.

Step 1.1: Run Day 4 Tests
Terminal β€” Day 4 Lab
npm run test:day4
Step 1.2: Verify AEC Suppression & Clean Buffer Flush
voicelab/duplex.py
# 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
Day 4 Key Learnings
  • 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?