All blogs
Real-Time AIDec 3, 20269 min read

Voice AI & Real-Time WebRTC: Architecting Sub-500ms Audio Pipelines in Production

Why TCP WebSockets break conversational rhythm, how edge WebRTC SFUs keep round-trip latency under 500ms, and how to synchronize live audio, barge-ins, and transcripts across web, desktop, and mobile.

Voice AIReal-Time WebRTCLow-Latency Audio
Dark editorial systems illustration of acid-lime acoustic waveforms flowing through glassmorphic edge WebRTC relay rings and a central neural audio sphere

Humans notice conversational lag at around 500 milliseconds. Once a voice assistant or live speech translator crosses 800ms to 1,200ms, people talk over it, repeat themselves, and lose trust in the product. That threshold makes Voice AI fundamentally different from text chat: a slow token stream in a chat box feels mildly sluggish, whereas a slow audio frame breaks the conversation.

Shipping real-time speech translation and live audio products across Electron desktop apps, mobile clients, and browsers teaches you quickly that the model is only one link in the latency chain. Transport protocol choices, edge routing, jitter buffers, and turn-detection state machines determine whether an interaction feels natural.

1. WebRTC vs. WebSockets for User Audio Transport

Most teams prototype voice features by capturing microphone PCM chunks in the browser and pushing them over a WebSocket to a backend server. It works on gigabit office Wi-Fi, then falls apart on cellular or crowded networks. WebSockets run on TCP, which guarantees ordered, lossless delivery—meaning a single dropped packet stalls every subsequent audio frame behind it (head-of-line blocking).

In live audio, a frame from 300ms ago is useless; you want the current frame now and let the Opus codec mask minor packet loss with forward error correction (FEC). Real-Time WebRTC runs over UDP/DTLS/SRTP, handles adaptive bitrate congestion control natively, and ships with battle-tested browser echo cancellation (AEC) and automatic gain control.

Four-stage sub-500ms Voice AI pipeline showing Client Audio Capture, Edge WebRTC SFU, Voice AI Core, Synced UI, and a sub-40ms barge-in loop
End-to-end sub-500ms Voice AI architecture: UDP/Opus WebRTC transport at the edge paired with fast barge-in buffer cancellation.

2. Speech-to-Speech vs. Modular STT → LLM → TTS Pipelines

Teams building Voice AI in 2026 choose between native speech-to-speech models (like the Realtime API) and modular streaming pipelines (streaming STT such as Deepgram, an LLM, and streaming TTS such as ElevenLabs). Both can hit sub-500ms perceived latency if every stage streams incrementally rather than waiting for full-utterance completion.

  • Native Speech-to-Speech: Lowest end-to-end latency and preserves prosody, tone, and emotion directly in audio tokens. Best for natural conversational agents, though harder to inspect or deterministically filter mid-turn.
  • Modular Streaming (STT → LLM → TTS): Gives you full control over multilingual transcripts, custom domain glossaries, speaker diarization, and parallel side effects (like updating UI cards or translating into multiple target languages simultaneously).
  • Sentence-level pipelining: When using modular pipelines, start synthesizing TTS on the very first clause boundary from the LLM instead of waiting for the full completion.

3. VAD, Turn Detection, and Sub-40ms Barge-In Recovery

If a user interrupts the AI mid-sentence, the assistant must stop talking immediately. Continuing to play buffered audio for half a second after the user starts speaking makes the product feel broken. Implementing reliable barge-in requires coordinating Voice Activity Detection (VAD), semantic turn-end detection, and client-side audio queue flushing.

barge-in-controller.tstypescript
export class VoiceTurnController {
  private activeTurnId: string | null = null;
  private abortController: AbortController | null = null;

  startTurn(turnId: string) {
    this.cancelActiveTurn("superseded");
    this.activeTurnId = turnId;
    this.abortController = new AbortController();
    return this.abortController.signal;
  }

  onUserSpeechDetected(vadConfidence: number) {
    if (vadConfidence < 0.72 || !this.activeTurnId) return;

    // 1. Flush client WebRTC / AudioWorklet playback buffer immediately
    this.emitClientControl({ type: "audio.flush", turnId: this.activeTurnId });

    // 2. Abort upstream LLM + TTS streams to stop wasted token generation
    this.cancelActiveTurn("barge_in");
  }

  private cancelActiveTurn(reason: string) {
    this.abortController?.abort(reason);
    this.abortController = null;
    this.activeTurnId = null;
  }
}

4. Keeping Audio, Partial Transcripts, and Clients in Sync

Voice products rarely ship audio alone—users expect live captions, multilingual translations, speaker separation, and post-session history. Running audio playback and transcript rendering as independent event streams with a shared `turnId` and monotonic sequence number prevents duplicate lines, out-of-order partial updates, and dropped finals when a mobile client briefly switches from Wi-Fi to 5G.

Key takeaways
  • Use WebRTC (UDP + Opus) to the nearest Edge SFU for user-facing audio transport instead of raw TCP WebSockets, eliminating head-of-line blocking on lossy mobile and Wi-Fi networks.
  • Budget every millisecond of the pipeline: keep transport under 50ms, VAD turn detection sharp, and model TTFB streaming so total mouth-to-ear latency stays below 500ms.
  • Treat interruption (barge-in) as a first-class state transition that flushes client playback buffers in under 40ms and cancels in-flight downstream generation.
Keep reading

More engineering notes

View all