How to Build a Human-Sounding Voice Agent: Lessons from LiveKit Agents
A voice agent feels human when its turn-taking is right. A walkthrough of the LiveKit Agents pipeline: WebRTC, VAD, streaming STT, LLM, paced TTS, and the models that decide when to speak.
Last updated

A voice agent sounds human because of when it speaks, not only what it says.
A plain STT, LLM, TTS chain works in a demo. In a real conversation it talks over people, waits too long after they finish, and stops dead when someone says "uh-huh". LiveKit Agents is an open source framework that spends most of its code on those problems.
This post is based on reading the source of livekit-agents and its plugins. I did not run anything, so treat the numbers below as what the code says, not as benchmarks.
The Stack
- Transport: WebRTC through the LiveKit Rust SDK (
livekit.rtc). Python only seesAudioFrameobjects. - Process model:
worker.pyis anAgentServerthat connects to LiveKit over a websocket and registers for jobs. Each room gets its own subprocess. Models such as the turn detector run in a separate inference process, so heavy ONNX work never blocks the audio loop. - Plugins: about 90 of them, covering OpenAI, Anthropic, Google, Deepgram, ElevenLabs, Cartesia and more. Each implements a small STT, LLM, TTS or VAD interface, so swapping a provider is a config change. There are also realtime speech-to-speech models and avatar plugins.
The framework is Apache 2.0. The hosted LiveKit Inference gateway and Krisp noise cancellation are the commercial layer.
The Pipeline, Stage by Stage
| Stage | What happens |
|---|---|
| Mic in | Audio arrives from rtc.AudioStream in 50 ms frames. It is resampled, and noise cancellation can be applied in the SDK. |
| VAD | A Silero ONNX model scores each audio window as speech or not speech. |
| STT | A streaming recogniser returns interim and final transcripts as the user talks. |
| Turn end | VAD silence and the transcript go to an end-of-turn detector. |
| LLM | Runs with tool calls. The token stream is piped onward immediately. |
| Text to TTS | Tokens are split into sentences and paced before they reach the TTS. |
| Audio out | TTS bytes are re-chunked into frames and pushed through a short queue. |
VAD: Is Anyone Speaking?
VAD stands for Voice Activity Detection. It looks at a slice of audio and answers "speech or not?". It is fast and cheap, but it only hears sound, not meaning.
LiveKit's Silero VAD runs on 256-sample windows at 8 kHz or 512 at 16 kHz. It uses hysteresis so it does not flicker: an activation threshold of 0.5, a deactivation threshold 0.15 lower, 0.55 s of minimum silence, and 0.5 s of prefix padding so the first syllable is not clipped.
A quick note on ONNX, since it comes up: ONNX is a model file format and runtime, not a type of model. The VAD and the turn detector are small purpose-built models exported to ONNX so they run fast on CPU. The actual LLM is a separate API call.
Text to TTS: Pace the Sentences
Streaming tokens straight into TTS produces choppy speech. LiveKit tokenizes the stream into sentences (minimum 20 characters), then a SentenceStreamPacer holds text back until less than 5 seconds of audio remains, sending batches of up to 300 characters.
Two benefits. The TTS gets more context per call, which improves prosody. And less audio is wasted if the user interrupts, because unsynthesized text is simply dropped.
Audio Out: Keep the Cancel Window Small
AudioByteStream re-chunks TTS output in a progressive mode: it starts with a 20 ms frame and doubles up to the target size, so the first sound plays fast. The output pushes frames into an rtc.AudioSource with a 200 ms queue. That caps how much audio is already committed and cannot be cancelled when the user barges in.
The Parts That Make It Feel Human
Everything above is plumbing. The turn-taking logic lives in voice/, and it is where the agent stops feeling like a walkie-talkie.
1. A Semantic End-of-Turn Model
A silence timer cannot tell "I think I'd like the, um, let me think..." from a finished sentence. LiveKit adds a small transformer in ONNX that reads the last 6 turns or 128 tokens of text and predicts whether the user is done. It uses per-language thresholds. It is a language model of sorts, but tiny, and it outputs a probability rather than text.
2. Dynamic Endpointing
endpointing.py adapts the minimum and maximum wait using an exponential moving average of the user's own pause patterns, both between utterances and between turns. A slow, careful speaker gets more patience. A fast one gets quicker replies.
3. Preemptive Generation
The LLM starts on the interim transcript before the turn is confirmed. If the final transcript differs, that work is discarded. TTS can optionally start early too. You trade some wasted tokens for a real cut in perceived latency.
4. Adaptive Interruption Detection
A model scores a 3 s audio window every 0.1 s, with a minimum of about 50 ms of overlap. It separates a real barge-in from a backchannel such as "uh-huh" or "right". Backchannels do not stop the agent. Real interruptions cancel in-flight speech through SpeechHandle.
5. Fallback Adapters
fallback_adapter.py for STT and TTS switches providers automatically when one fails, and stream_adapter.py lets non-streaming providers behave like streaming ones. Voice is unforgiving, since a dead provider means dead air.
What to Copy in Your Own Agent
- Separate "silence" from "done". Use VAD for sound and a text-based signal for meaning.
- Adapt to the speaker. A fixed timeout is wrong for someone.
- Start early, discard cheaply. Preemptive LLM calls are worth it when latency is the product.
- Keep committed audio short. A small output queue makes interruption feel instant.
- Distinguish backchannels from barge-ins. Otherwise the agent either ignores people or stops constantly.
- Plan for provider failure. Fallbacks belong in the design, not in the postmortem.
Where to Read Next
Start with voice/audio_recognition.py (about 2,400 lines) and voice/agent_activity.py (about 5,600 lines). Together they hold the turn-taking and interruption logic.
TL;DR
A human-sounding voice agent is a 50 ms frame pipeline of VAD, streaming STT, LLM and sentence-paced TTS, made natural by a small neural turn detector, adaptive endpointing, preemptive generation and backchannel-aware interruption handling.
References
- LiveKit Agents source code, Apache 2.0 (
livekit-agents/livekit/agents/andlivekit-plugins/). - LiveKit Agents documentation.
- Silero VAD.
- ONNX, Open Neural Network Exchange.
