Capstone 03 — Real-Time Voice Assistant (ASR to LLM to TTS)
A voice agent that feels right answers in under 800ms end to end, knows when you've stopped talking, handles barge-in, and calls a tool without stalling. Retell, Vapi, LiveKit Agents, and Pipecat all hit this bar in 2026, and they share one shape: streaming ASR, a turn-detector, a streaming LLM, and streaming TTS, wired through WebRTC with a tight latency budget at every hop. Build one, measure WER, MOS, and false-cutoff rate, then run it under packet loss.
Learning Objectives
- Describe the five streaming stages of a realtime voice agent (audio in, ASR, turn detection, LLM, TTS) and why each must pass partial results downstream.
- Build a turn-taking gate that commits a turn only after 500ms of VAD silence and a turn-detector completion score above 0.6.
- Implement barge-in cancellation and a tool side channel that emits a filler when a call runs past 300ms.
- Measure WER, first-audio-out p50, false-cutoff rate, and TTS MOS, including a run with 3% packet loss injected.
Problem
A realtime voice assistant is a pipeline that listens to speech, decides when the user has finished, and answers aloud while audio is still streaming in both directions. Voice has been the fastest-moving AI UX category of 2025-2026, and the technical ceiling dropped every quarter. OpenAI Realtime API, Gemini 2.5 Live, Cartesia Sonic-2, ElevenLabs Flash v3, LiveKit Agents 1.0, and Pipecat 0.0.70 all put sub-800ms first-audio-out within reach.
Latency alone doesn't make it feel right. The feel comes from not cutting the user off, not getting cut off, recovering from a mid-sentence interruption, calling a tool without stalling the audio, and surviving a jittery mobile network.
Three chained REST calls won't get you there. The architecture has to be streaming end to end, and building it makes the failure modes visible: a VAD tuned for phone audio firing on a background TV, a turn-detector waiting for punctuation that never comes, a TTS that buffers 400ms before emitting. The capstone is to fix these one at a time under load and publish a latency-and-quality report.
Concept
A realtime voice agent is a pipeline of five streaming stages, each passing partial results downstream before its own input is finished:
- Audio in. WebRTC from a browser, or PSTN from a phone line.
- ASR. Streaming partial transcripts from Deepgram Nova-3 or faster-whisper.
- Turn detection. VAD plus a small turn-detector model that reads partial transcripts for completion cues.
- LLM. Streams tokens as soon as the turn is judged complete.
- TTS. Streams audio out within ~200ms of the first LLM token.
Three concerns cut across all of them. Barge-in means that when the user starts speaking while the agent is speaking, the TTS cancels and the ASR picks up immediately. Tool use covers mid-conversation function calls (weather, calendar), which run on a side channel so the audio never stalls. If a call takes longer than 300ms, the agent pre-fills an acknowledgement ("one second..."). Backpressure is what happens under packet loss: partial transcripts are held, VAD raises the speech-gate threshold, and the agent avoids speaking over a message the user hasn't acknowledged.
The measurement bar is quantitative, and the numbers are the deliverable:
- WER under 8% on the Hamming VAD benchmark at 15 dB SNR
- First-audio-out p50 under 800ms across 100 measured calls
- False-cutoff rate under 3%
- MOS above 4.2 on TTS
- 50 concurrent calls on a single g5.xlarge
Architecture
browser / Twilio PSTN
|
v
WebRTC / SIP edge
|
v
LiveKit Agents 1.0 (or Pipecat 0.0.70)
|
+----+--------------+--------------+-----------------+
| | | |
v v v v
ASR VAD v5 turn-detector side-channel
(Deepgram (Silero) (LiveKit) tools
Nova-3 / speech-gate completion score (weather,
Whisper-v3) per 20ms on partials calendar)
| | |
+--------+----------+--------------+
v
LLM (streaming)
GPT-4o-realtime / Gemini 2.5 Flash /
cascaded Claude Haiku 4.5
|
v
TTS streaming
Cartesia Sonic-2 / ElevenLabs Flash v3
|
v
audio back to caller
|
v
OpenTelemetry voice traces -> Langfuse
Stack
- Transport: LiveKit Agents 1.0 (WebRTC) plus Twilio PSTN gateway; Pipecat 0.0.70 as the alternate framework
- ASR: Deepgram Nova-3 (streaming, sub-300ms first partial) or faster-whisper Whisper-v3-turbo self-hosted
- VAD: Silero VAD v5 plus the LiveKit turn-detector (small transformer that reads partial transcripts)
- LLM: OpenAI GPT-4o-realtime for tight integration, Gemini 2.5 Flash Live, or cascaded Claude Haiku 4.5 (streaming completions, separate audio path)
- TTS: Cartesia Sonic-2 (lowest first-byte), ElevenLabs Flash v3, or open-source Orpheus for self-host
- Tools: FastMCP side-channel for weather/calendar/booking; agent pre-emits filler if tool takes >300ms
- Observability: OpenTelemetry voice spans, Langfuse voice traces with audio replay
- Deployment: single g5.xlarge (24GB VRAM) for self-hosted Whisper + Orpheus; hosted APIs for lowest latency
Build It
-
WebRTC session. Stand up a LiveKit room and a web client that streams microphone audio. On the server, attach an agent worker that joins the room.
-
ASR streaming. Feed 20ms PCM frames to Deepgram Nova-3 (or faster-whisper on GPU). Subscribe to partial and final transcripts. Log per-partial latency.
-
VAD and turn detector. Run Silero VAD v5 on the frame stream. On speech-end event, fire the LiveKit turn-detector against the latest partial transcript. Commit to "turn complete" only when VAD reports 500ms of silence and the turn-detector scores completion above 0.6.
-
LLM stream. On turn complete, start the LLM call with the running conversation plus the final transcript. Stream tokens out. At the first token, hand off to TTS.
-
TTS stream. Cartesia Sonic-2 streams audio chunks back. The first chunk must leave the server within 200ms of the first LLM token. Emit chunks to the LiveKit room, and the client plays them through the WebRTC jitter buffer.
-
Barge-in. When VAD detects new user speech while TTS is playing, cancel the TTS stream immediately, drop the remaining LLM output, and re-arm the ASR. Publish a
tts_canceledspan. -
Tool side channel. Register weather and calendar as function-calling tools. When one is invoked, fire the call concurrently. If it hasn't resolved within 300ms, have the LLM emit "one second, let me check" as a filler, then resume once the tool returns.
-
Eval harness. Record 100 calls. Compute WER (against a held-out transcript), false-cutoff rate (TTS cancelled while user was mid-sentence), first-audio-out p50, TTS MOS (human or NISQA), and a jitter-loss test (drop 3% of packets).
-
Load test. Drive 50 concurrent calls on a single g5.xlarge with a synthetic caller. Measure sustained first-audio-out p95.
Use It
Running python main.py replays a simulated caller through the scheduler. Session 1 (the weather call) prints this:
$ python main.py
=== session 1: clean call with tool (weather) ===
120ms LISTENING
2840ms TURN COMPLETE (score=0.75) partial='what is the weather in tokyo tomorrow'
2840ms LLM call fired
3140ms filler 'one second, let me check'
3260ms tool result: 68/52 partly cloudy
3400ms LLM first token
3580ms TTS first audio-out
turn_complete @ 2840ms
first_llm_tok @ 3400ms
first_audio_out @ 3580ms
turn latency = 740ms
The timestamps are simulated frame times, not wall-clock. The turn commits at 2840ms because seven words at 320ms each plus 120ms of leading silence end at 2360ms, and the 500ms silence gate then has to elapse. The 740ms latency is the three simulated delays stacked after the commit: the tool call (420ms), the LLM time-to-first-token (140ms), and the TTS start (180ms). The filler fires 300ms into the tool call, before the result arrives. These constants are stand-ins, so treat the 740ms as a demonstration of the accounting, not a benchmark.
Ship It
outputs/skill-voice-agent.md is the deliverable. Given a domain (customer support, scheduling, or kiosk), it stands up a LiveKit agent whose ASR/VAD/LLM/TTS pipeline is tuned to the measurement bar. The rubric:
| Weight | Criterion | How it is measured |
|---|---|---|
| 25 | End-to-end latency | p50 first-audio-out under 800ms across 100 recorded calls |
| 20 | Turn-taking quality | False-cutoff rate under 3% on the Hamming VAD benchmark |
| 20 | Tool-use correctness | Mid-conversation tool calls that return the right data without stalling audio |
| 20 | Reliability under packet loss | WER and turn-taking stability with 3% packet drop injected |
| 15 | Eval harness completeness | Reproducible measurements with public config |
| 100 |
I'd tune turn-taking before latency. A 700ms agent that cuts people off mid-sentence is worse than a 900ms one that waits. The rubric weights turn-taking at 20 against latency's 25, but a user who gets cut off has already failed the call. Build the eval harness in step 8 first, even crudely, so every threshold change (the 500ms silence gate, the 0.6 completion score) shows up as a number instead of a feeling. My bet is that most of your time goes into those two thresholds and the barge-in policy, not into choosing between Cartesia and ElevenLabs.
Exercises
-
Swap Deepgram Nova-3 for faster-whisper v3 turbo on a g5.xlarge. Measure the latency and WER gap. Identify where CPU-vs-GPU decisions matter.
-
Add an interruption-arbitration policy: what does the agent do when the user barges in during a tool call? Compare three policies (hard cancel, finish-tool-then-stop, queue next turn).
-
Run an adversarial turn-detector test: give the user long pauses mid-sentence. Tune the VAD silence threshold and the turn-detector score threshold for lowest false-cutoff without blowing past 900ms.
-
Deploy the same agent on PSTN via Twilio. Compare PSTN first-audio-out to WebRTC. Explain the jitter-buffer and codec differences.
-
Add voice activity detection for non-English languages (Japanese, Spanish). Measure the Silero VAD v5 false-trigger rate versus language-specific fine-tunes.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| Turn detection | "End of utterance" | Classifier that, given VAD silence and a partial transcript, decides the user is done speaking |
| Barge-in | "Interruption handling" | Canceling TTS mid-playback when VAD detects new user speech |
| First-audio-out | "Latency" | Time from user stops speaking to the first audio packet leaving the server |
| VAD | "Speech gate" | Model classifying audio frames as speech vs silence; Silero VAD v5 is the 2026 default |
| Jitter buffer | "Audio smoothing" | Client-side buffer that holds packets briefly to absorb network variance |
| Filler | "Acknowledgment token" | Short phrase the agent emits to avoid silence when a tool is slow |
| MOS | "Mean opinion score" | Perceptual speech quality rating; NISQA is the automated proxy |
Further Reading
- LiveKit Agents 1.0: reference WebRTC agent framework
- Pipecat: alternate Python-first streaming agent framework
- OpenAI Realtime API: reference for integrated speech models
- Deepgram Nova-3 documentation: streaming ASR reference
- Silero VAD v5: VAD reference model
- Cartesia Sonic-2: low-latency TTS reference
- Retell AI architecture: production voice agent architecture
- Vapi.ai production stack: alternate production reference
Code
- main.py (python, 239 lines)
- ts/package.json (json, 23 lines)
- ts/README.md (markdown, 36 lines)
- ts/src/index.ts (typescript, 124 lines)
- ts/src/orchestrator.ts (typescript, 163 lines)
- ts/src/protocol.ts (typescript, 29 lines)
- ts/src/server.ts (typescript, 61 lines)
- ts/src/types.ts (typescript, 32 lines)
- ts/src/vad.ts (typescript, 38 lines)
- ts/tests/orchestrator.test.ts (typescript, 61 lines)
- ts/tests/protocol.test.ts (typescript, 33 lines)
- ts/tests/vad.test.ts (typescript, 41 lines)
- ts/tsconfig.json (json, 21 lines)