Real-Time & Voice AI
Speech pipelines, latency budgets measured against human conversational expectations, and interruption handling — where a 300 ms delay is the difference between natural and broken.
#The budget humans enforce
Text chat tolerates a two-second wait. Speech does not. Human turn-taking has a gap distribution centred around 200 ms, and listeners register anything past roughly 500 ms as a hesitation — meaning something.
PERCEIVED QUALITY OF RESPONSE DELAY
< 300 ms natural
300-500 ms slightly slow, acceptable
500-800 ms noticeably laggy; users start to interject
800-1500 ms broken; users repeat themselves
> 1500 ms unusable as conversation
→ The entire pipeline — endpointing, transcription,
model, speech synthesis, network — must fit in
roughly 500 ms.That budget is the constraint that determines every architectural decision below.
#The pipeline
Six stages, and the abbreviations recur below. VAD (voice activity detection) decides whether the microphone is picking up speech or just room noise. WebRTC is the browser standard for carrying live audio. STT turns speech into text, TTS turns text back into speech, and a jitter buffer holds a fraction of a second of audio so that packets arriving unevenly still play smoothly.
The key insight: only time-to-first-audio matters. Total generation time is irrelevant if playback starts quickly and never starves — never runs out of audio to play because the next chunk isn't ready yet. This makes TTFT the single metric to optimise on the model side — and it means a long prompt is far more costly here than in a text product, because TTFT scales with prompt length.
#Endpointing
Deciding when the user has finished speaking, and the largest single controllable term in the budget.
SIMPLE VAD (energy threshold + silence timer)
wait 700 ms of silence → assume they're done
✗ 700 ms of pure latency added to every turn
✗ cuts off mid-sentence pauses
✗ triggers on background noise
SEMANTIC ENDPOINTING
stream the partial transcript to a small model:
"is this a complete utterance?"
"What's the weather in—" → incomplete, keep waiting
"What's the weather in Delhi" → complete, go now
✓ 200-300 ms, and more accurate
SPECULATIVE EXECUTION
start the LLM on the partial transcript BEFORE the
user finishes. If they continue, cancel and restart.
✓ can reach near-zero perceived latency
✗ wasted compute on cancellations — but compute is
cheaper than the latency it buysSpeculative execution is the same idea as speculative decoding one level up: spend cheap resources on a guess to avoid paying an expensive wait.
#Transport
| Option | Latency | Fits |
|---|---|---|
| WebRTC | 50–150 ms | Real-time audio. Purpose-built: UDP, adaptive jitter buffer, packet loss concealment, echo cancellation |
| WebSocket | 100–300 ms | Simpler; TCP head-of-line blocking hurts under loss |
| HTTP streaming | 200 ms+ | Output only; no good for capture |
WebRTC is the right answer for voice, and it's a real infrastructure commitment:
- STUN/TURN servers for NAT traversal — helping two devices behind home or mobile routers find a path to each other, and relaying the audio when no direct path exists.
- An SFU (selective forwarding unit) if you have multiple participants — a server that receives each person's stream and forwards it to the others.
- Codec negotiation — the two ends agreeing on an audio format both support.
Teams routinely start with WebSockets because it's easier, and hit a quality ceiling on mobile networks that they cannot fix. The cause is TCP: when a packet is lost, TCP holds back every later packet until the lost one has been resent (head-of-line blocking). On a lossy link that means the audio freezes and then bursts. That's exactly the wrong behaviour for audio, where a late packet is worthless — you'd rather skip the missing 20 ms and keep playing.
The pieces WebRTC gives you that are easy to underestimate: acoustic echo cancellation (without it the assistant hears itself and interrupts itself), jitter buffering, and packet loss concealment (filling a missing slice of audio with a plausible guess so the gap isn't heard). Reimplementing these is not a weekend project.
#Interruption
Barge-in — the user speaking while the assistant is talking — is what separates a demo from a product, and it is genuinely hard.
WHEN THE USER STARTS SPEAKING MID-RESPONSE:
1. detect it, distinguishing speech from
echo of your own audio (needs AEC)
2. stop TTS playback immediately
3. cancel in-flight LLM generation
4. cancel queued TTS synthesis
5. TRUNCATE THE CONVERSATION HISTORY to what was
actually PLAYED, not what was generated
6. start listening
Step 5 is the one everyone gets wrong.#Cascaded versus end-to-end
Cascaded remains the practical default for anything needing tool use, moderation, or auditable transcripts — which is most business applications. End-to-end wins on naturalness and latency, and is advancing quickly. A common hybrid: end-to-end for the conversational path, with a parallel STT stream feeding logging and moderation.
#Serving characteristics
Voice load differs from text load in ways that matter for capacity planning:
- Sessions are long-lived and stateful. A ten-minute call holds resources throughout, so you provision for concurrent sessions, not requests per second.
- Latency variance is the enemy, not average latency. A p99 of 900 ms with a p50 of 300 ms produces a conversation that intermittently feels broken — which is worse than one that's consistently slightly slow. Sacrifice mean latency for a tighter distribution.
- Batching is constrained. Large batches raise TTFT, and TTFT is the whole product here. Voice traffic should run in a small-batch, latency-optimised lane, separate from bulk text work.
- Multiple models per session. STT, LLM, and TTS each need capacity, and they scale on different signals — STT on audio minutes, LLM on tokens, TTS on output characters.
#Monitoring
| Metric | Target |
|---|---|
| Time to first audio | < 500 ms p95 — the headline number |
| Endpointing delay | < 300 ms |
| Audio underruns | ≈ 0; playback starving is very audible |
| Interruption handling latency | < 100 ms from detection to silence |
| Word error rate | Tracked by accent, language, and noise condition |
| Turn-taking anomalies | Both talking, or long awkward gaps |
| Session drop rate | Network and infrastructure health |
Audio underruns deserve special attention. An underrun is playback running out of audio. If TTS can't keep ahead of playback, the audio has gaps — and a gap mid-word is far more jarring than a slightly later start. The mitigation is a small output buffer: hold 200 ms of synthesised audio before starting playback, trading a little initial latency for robustness against synthesis jitter. It's the same jitter buffer reasoning as any streaming media system.
#Check yourself
What latency budget does speech impose?Show answer
Which metric matters most for voice, and why?Show answer
What are the endpointing options?Show answer
Why WebRTC rather than WebSockets for voice?Show answer
What must happen when a user interrupts?Show answer
Cascaded or speech-to-speech?Show answer
How is voice capacity planned?Show answer
How are audio underruns prevented?Show answer
#What to carry forward
- Humans enforce a ~500 ms budget. Past 800 ms, conversation breaks down.
- Stream and overlap every stage. Only time to first audio matters; the rest streams behind playback.
- Endpointing is the largest controllable term. Semantic endpointing or speculative execution beats a silence timer.
- WebRTC, not WebSockets — you need echo cancellation, jitter buffering, and loss concealment.
- On interruption, truncate history to what was actually played, not what was generated.
- Provision for concurrent sessions, run voice in a small-batch latency lane, and optimise for tight latency variance rather than low mean.