Voice and Multimodal AI Pipelines: Low-Latency STT/TTS, Turn-Taking, and WebRTC
In text chat, a 2.5-second response feels fast. In live voice calls, a 2.5-second silence feels awkward and broken. Engineering real-time voice and multimodal agents revolves around streaming every stage concurrently and handling natural human interruptions (barge-in) cleanly.
End-to-End Voice Latency Budget
Human conversational gaps average 300 to 600ms. To feel natural, a cascaded voice pipeline targets sub-1,000ms voice-to-voice response by streaming audio frames and text tokens rather than waiting for complete turns.
| Stage | Target Latency | Key Optimization |
|---|---|---|
| Media Transport (WebRTC) | 30 to 80ms | UDP/ICE edge relays instead of HTTP audio uploads |
| VAD + Endpointing | 150 to 300ms | Semantic turn detection (avoid cutting off mid-thought pauses) |
| Streaming STT | 100 to 200ms | Incremental partial transcripts over persistent socket |
| LLM First Token | 200 to 400ms | Compact voice-tuned prompt + fast model tier |
| Streaming TTS | 100 to 250ms | Synthesize sentence-by-sentence as tokens stream |
Handling Barge-In (User Interruptions)
When the caller speaks while the assistant is still talking, the pipeline must:
- Detect speech immediately via Voice Activity Detection (VAD).
- Flush the outbound audio playout buffer within ~100ms so the assistant stops talking over the user.
- Cancel the in-flight TTS and LLM generation streams and truncate the assistant's transcript to only the words actually spoken aloud before the interruption.
export interface VoiceTurnController {
abortActiveGeneration(): void;
clearAudioPlayoutBuffer(): void;
commitSpokenPrefix(spokenText: string): void;
}
export function handleUserBargeIn(
controller: VoiceTurnController,
spokenTextSoFar: string
): void {
controller.abortActiveGeneration();
controller.clearAudioPlayoutBuffer();
if (spokenTextSoFar.trim()) {
controller.commitSpokenPrefix(spokenTextSoFar);
}
}
Multimodal Input Hygiene (Images, Voice Notes, PDFs)
For asynchronous channels (WhatsApp, Instagram, Telegram), inbound voice notes and images arrive as short-lived media URLs. Fetch media through authenticated workers, validate MIME types and byte limits before decoding, transcribe audio into searchable text, and store durable transcripts so downstream RAG and analytics treat voice and text uniformly.
Continue to the next pillar: Durable Execution and Event-Driven Workflows: Systems Engineering Guide.