enough-dentist-75383
12/05/2025, 5:30 AMtall-airline-16756
12/05/2025, 5:30 AMtall-airline-16756
12/05/2025, 5:30 AMenough-dentist-75383
12/05/2025, 5:31 AMtall-airline-16756
12/05/2025, 5:31 AMenough-dentist-75383
12/05/2025, 5:31 AMtall-airline-16756
12/05/2025, 5:31 AMenough-dentist-75383
12/05/2025, 5:34 AMtall-airline-16756
12/05/2025, 5:34 AMenough-dentist-75383
12/05/2025, 10:15 AM┌─────────────┐
│ LISTENING │ ◄─── Initial state, waiting for user
└─────────────┘
│
│ User speaks
▼
┌─────────────┐
│ SPEAKING │ ◄─── VAD detects speech
└─────────────┘
│
│ User stops
▼
┌─────────────┐
│ EOU WAIT │ ◄─── Waiting for end-of-utterance
└─────────────┘
│
│ EOU detected
▼
┌─────────────┐
│ THINKING │ ◄─── LLM processing
└─────────────┘
│
│ LLM response ready
▼
┌─────────────┐
│ SPEAKING │ ◄─── TTS generation & playback
└─────────────┘
│
│ Playback complete
▼
┌─────────────┐
│ LISTENING │ ◄─── Ready for next turn
└─────────────┘
---tall-airline-16756
12/05/2025, 10:16 AMenough-dentist-75383
12/05/2025, 10:17 AMtall-airline-16756
12/05/2025, 10:17 AMlk.transcription if STT is enabled.
◦ VAD: continuous local/agent-side VAD analysis on incoming frames.
• Streams not active:
◦ Agent audio output (no TTS published).
◦ Agent LLM inference.
• Where time is spent:
◦ Network transport of audio frames (WebRTC latency, jitter handling).
◦ VAD buffering/decision time (frame size and VAD sensitivity).
SPEAKING (user speaking; VAD = speaking)
• Streams active:
◦ Raw audio frames: continuous streaming to agent and STT.
◦ Streaming STT: interim transcripts emitted if provider supports streaming.
◦ Possible early LLM prefetching if configured to begin inference during utterance (optional).
• Streams not active:
◦ Agent TTS audio output (unless agent is configured to stream audio concurrently, uncommon).
• Where time is spent:
◦ Audio framing buffers (e.g., 10–30ms frames).
◦ STT streaming latency (interim result delay).
◦ Network jitter/retransmits.
EOU WAIT (endpointing; waiting for end-of-utterance)
• Streams active:
◦ Finalizing STT transcripts (final chunks).
◦ VAD silence signals and endpointing logic.
• Streams not active:
◦ Agent TTS audio (not yet started).
◦ Full LLM response (still pending until turn committed).
• Where time is spent:
◦ Endpointing timeout (min/max endpointing delays to avoid cutting user off).
◦ Any STT provider end-of-speech detection latency.
THINKING (agent performing LLM/tool processing)
• Streams active:
◦ Text: final transcript (prompt) forwarded to LLM or tool chain.
◦ LLM token stream: LLM may stream tokens back (if streaming completions used).
◦ Telemetry/events: tool call results, logs.
• Streams not active:
◦ Agent audio output (until TTS starts).
◦ Continuous raw user audio (user audio is typically paused for this turn).
• Where time is spent:
◦ LLM TTFT (time to first token) and token generation.
◦ Network round-trip to LLM provider (reduced if using LiveKit Inference/co‑location).
◦ Any tool execution latency.
SPEAKING (agent TTS generation & playback)
• Streams active:
◦ LLM → TTS: text segments or token streams fed to TTS.
◦ TTS streaming audio: synthesized audio frames returned from TTS service (sentence- or token-level streaming).
◦ Agent → Room: LocalAudioTrack publishes TTS audio into the LiveKit room over WebRTC.
◦ Optional: TTS-aligned transcription stream (word/sentence timing) sent to clients.
• Streams not active:
◦ STT for new user speech (unless interruption handling allows simultaneous listening).
• Where time is spent:
◦ TTS TTFB / synthesis latency.
◦ Audio encoding and WebRTC transmission to clients.
◦ Client playback buffering and decode time.
◦ If interruption is enabled: detection of user speech during playback and cancellation latency.
BACK TO LISTENING (agent ready for next turn)
• Streams active:
◦ Agent unsubscribes/publishes appropriately; VAD resumes monitoring incoming audio.
◦ STT resumes when user next speaks.
• Streams not active:
◦ Agent TTS output.
◦ LLM processing (unless prefetching next turn).
• Where time is spent:
◦ Interruption rollback/cancellation cleanup if playback was interrupted.
◦ VAD detection to capture the next user speech start.
Cross-cutting details (what streams vs. what does not)
• WebRTC audio transport (user ↔️ room ↔️ agent): always the medium when audio is used.
• STT:
◦ Streaming STT: streams interim transcripts during SPEAKING and EOU WAIT.
◦ Non-streaming STT: only final transcript after end-of-speech (adds wait time).
• LLM:
◦ Streaming LLM: can stream tokens during THINKING, enabling early TTS start.
◦ Non-streaming LLM: waits for full response, lengthening THINKING.
• TTS:
◦ Streaming TTS: returns audio chunks that can be published as soon as available.
◦ Batch TTS: requires full audio before publishing (increases latency).
• VAD & endpointing: VAD always processes incoming audio during LISTENING/SPEAKING; endpointing introduces intentional pauses to avoid cutoff.
• Interruption handling: when enabled, user audio can preempt agent TTS; this requires VAD during agent SPEAKING and immediate TTS cancellation.
Where most time is consumed (typical bottlenecks)
1. Endpointing wait (to detect end of user utterance).
2. STT mode: non-streaming STT or slow streaming STT.
3. LLM TTFT and token generation.
4. TTS synthesis/TTFB and client playback buffering.
Network jitter, poor client networks, or misconfigured buffers can amplify each stage.
Optimization levers (short)
• Use streaming STT, streaming LLM, and streaming TTS where possible.
• Start LLM inference early (preemptive) during long user utterances.
• Use LiveKit Inference or co‑locate services to cut network hops.
• Tune VAD/endpoint timeouts and client jitter/buffer sizes.
• Ensure WebRTC settings (Opus, packet recovery/FEC) are correct.
If you want, I can:
• Map expected ms ranges per stage for specific STT/LLM/TTS providers you plan to use, or
• Recommend exact VAD/endpoint and buffer settings for SDK clients vs custom clients.
Which would you like next?
Sources: Events and error handling | LiveKit docs | examples/voice_agents | livekit/livekit_composite | DeepWiki | Text and transcriptions | LiveKit docs | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agentsenough-dentist-75383
12/05/2025, 10:26 AMtall-airline-16756
12/05/2025, 10:27 AMaway / idle timeout: session may transition to away after configured inactivity.
If you’d like, I can:
• Annotate your diagram with expected latency ranges per stage (ms) for specific STT/LLM/TTS providers, or
• Recommend concrete endpointing, VAD, and buffer settings to target a specific end-to-end latency (e.g., <1s). Which do you want? Sources: Turn detection and interruptions | LiveKit Docs | Agent session | LiveKit docs | Events and error handling | LiveKit docs | How to detect when an agent has finished speaking | examples/voice_agents | livekit/livekit_composite | DeepWiki