Real-Time Voice Agents Under 300ms: Architecting WebRTC, Silero VAD, and Speculative Turn-Detection Pipelines
Why Turn-Based HTTP Voice Pipelines Feel Broken
Human conversation relies on 200–350ms turn-taking latency. Yet most first-generation AI voice agents feel robotic because they serialize three heavy network hops over HTTP:
- Record full user utterance -> upload
.wavover HTTP (~400ms). - Run batch ASR transcription -> wait for full LLM completion (~1,300ms).
- Synthesize full audio file via TTS -> download and play (~700ms).
At 2,400ms total latency, users repeatedly say "Hello? Are you still there?"—triggering overlapping audio collisions.
Full-Duplex Streaming Architecture (<300ms Voice-to-Voice)
To hit human conversational cadence, every stage must stream continuously over WebRTC UDP with instant barge-in cancellation:
text[Browser Mic (WebRTC Opus 20ms frames)] │ ▼ [Edge Media Server (LiveKit / Pipecat)] ├──► [Silero VAD (<1ms/frame)] ──(Speech Start)──► Cancel Active TTS Playback! │ ▼ (Continuous PCM Stream) [Streaming ASR (Deepgram Nova / Whisper-Streaming)] │ ▼ (Partial Transcript + Semantic End-of-Turn) [Streaming LLM (TTFT ~140ms)] ──► [Sentence Clause Buffer] ──► [Streaming TTS (Cartesia / ElevenLabs)] │ ▼ (First 40ms Audio Chunk) [WebRTC Speaker Output]
Implementing Barge-In & Clause-Chunked Streaming in Python
The secret to cutting perceived latency in half is never waiting for the full LLM response before starting TTS, while using Silero VAD to cancel queued audio buffers the millisecond the user interrupts:
pythonimport asyncio import re CLAUSE_BOUNDARY = re.compile(r"(?<=[.!?,;:])\s+") class DuplexVoicePipeline: def __init__(self, asr_stream, llm_client, tts_client, audio_out_queue: asyncio.Queue): self.asr_stream = asr_stream self.llm_client = llm_client self.tts_client = tts_client self.audio_out = audio_out_queue self.current_turn_task: asyncio.Task | None = None async def on_vad_speech_started(self): # Immediate barge-in: cancel in-flight LLM/TTS generation and flush speaker buffer if self.current_turn_task and not self.current_turn_task.done(): self.current_turn_task.cancel() while not self.audio_out.empty(): self.audio_out.get_nowait() async def handle_user_turn(self, transcript: str): buffer = "" async for token in self.llm_client.stream_tokens(transcript): buffer += token # Flush to TTS as soon as a natural prosody clause completes parts = CLAUSE_BOUNDARY.split(buffer, maxsplit=1) if len(parts) == 2: clause, buffer = parts await self._synthesize_and_enqueue(clause) if buffer.strip(): await self._synthesize_and_enqueue(buffer.strip()) async def _synthesize_and_enqueue(self, text_chunk: str): async for pcm_frame in self.tts_client.stream_pcm(text_chunk): await self.audio_out.put(pcm_frame)
Latency Budget Breakdown
- WebRTC Audio Transport: ~35ms
- Streaming ASR Finalization + Semantic EOT: ~90ms
- LLM Time-to-First-Clause (6–8 tokens): ~125ms
- Streaming TTS First-Byte Audio: ~45ms
- Total Voice-to-Voice Latency: ~295ms
With WebRTC, local VAD barge-in, and clause-level TTS pipelining, voice agents cross the uncanny valley into natural, responsive conversation.