Мазмұнға өту
Мақала Kazakh тілінде әлі жарияланбаған. English нұсқасы көрсетілуде.

Voice and Multimodal AI Pipelines: Low-Latency STT/TTS, Turn-Taking, and WebRTC

2 мин оқу

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.

StageTarget LatencyKey Optimization
Media Transport (WebRTC)30 to 80msUDP/ICE edge relays instead of HTTP audio uploads
VAD + Endpointing150 to 300msSemantic turn detection (avoid cutting off mid-thought pauses)
Streaming STT100 to 200msIncremental partial transcripts over persistent socket
LLM First Token200 to 400msCompact voice-tuned prompt + fast model tier
Streaming TTS100 to 250msSynthesize sentence-by-sentence as tokens stream

Handling Barge-In (User Interruptions)

When the caller speaks while the assistant is still talking, the pipeline must:

  1. Detect speech immediately via Voice Activity Detection (VAD).
  2. Flush the outbound audio playout buffer within ~100ms so the assistant stops talking over the user.
  3. 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.
ts
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.

Бұл пайдалы болды ма?