Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Voice AI Real-Time Agents
Handbook~15 min readAI · Engineeringworked math + runnable code
The Voice AI Real-Time Agents Handbook

Talk is
a stopwatch.

A voice agent has one job that a chat box doesn't: it has to answer fast enough to feel like talking. Under the hood it's three stages in a row — hear it (speech-to-text), think (the LLM), say it (text-to-speech) — and the user waits for all three. Human conversation has a rhythm: reply in a beat and it feels alive; pause a second too long and it feels like a dropped call. So a voice agent isn't really about intelligence — it's about a latency budget, and this handbook is the arithmetic of spending it.

01

Three stages, one wait

A real-time voice agent is a pipeline. The user speaks; speech-to-text (STT) turns the audio into words; the LLM reads those words and generates a reply; text-to-speech (TTS) turns the reply back into audio the user hears. Three stages, run in order, because each needs the previous one's output: the LLM can't think until it has a transcript, TTS can't speak until it has text.

The consequence is simple and unforgiving: the user hears nothing until all three have finished, so the response time they feel is the sum of the stage times. It doesn't matter that your LLM is brilliant if the round trip takes two seconds — by then the human has already felt the silence. That's what makes voice different from a chat interface, where a spinner is socially acceptable. In conversation, the clock is running the whole time, and the budget for that clock is tiny.

The one-sentence version

A voice agent is STT + LLM + TTS in series, and the user waits for the whole sum — so it feels conversational only when that sum stays under the human turn-taking threshold, roughly 800 milliseconds.

02

The latency budget

Human turn-taking is astonishingly fast. In natural dialogue people begin replying within a couple hundred milliseconds of the other person stopping — often before, by predicting the end of the sentence. A gap much beyond that starts to feel like something's wrong: the other person is confused, distracted, or the line is bad. Cross about a second and the illusion of conversation collapses entirely.

So a voice agent has a latency budget — a hard ceiling on the end-to-end response time, commonly targeted around 800 ms to feel snappy (and every millisecond under that feels better). Every stage spends against it: STT might take 150 ms, the LLM 400 ms, TTS 200 ms. Add them up and you're at 750 ms — under budget, barely. Swap in a slower LLM at 700 ms and you're at 1050 ms, over the line, and the agent now feels like a laggy phone tree no matter how good its answers are. The whole engineering problem is keeping that sum under the ceiling.

03

Attack the bottleneck

When the sum is over budget, not all stages are equal. The one to fix first is the bottleneck — the slowest stage — because a fixed reduction there moves the total the same as anywhere else, but the bottleneck is where the biggest reductions are available. If the LLM is 700 ms and STT/TTS are 150 ms each, shaving the LLM is the only move that can bring a 1000 ms pipeline under 800 ms; trimming an already-fast stage barely helps.

Where the milliseconds go
STTTranscribe speech → text. ~100–300 ms; stream partial transcripts to start the LLM early.
LLMGenerate the reply. Often the bottleneck; smaller/faster model + token streaming.
TTSSynthesize audio → speech. ~100–300 ms; stream audio as tokens arrive.
TotalUser feels the sum — must fit the ~800 ms budget to feel like conversation.

So the optimization loop is: measure each stage, find the max, cut it, remeasure. Sometimes the bottleneck is the LLM (use a faster model, or fewer tokens); sometimes it's a network hop (colocate the services); sometimes it's TTS warmup. The discipline is to always spend your effort on the slowest stage, because that's the only place the total budget has real slack to give.

04

The budget math

The stages run in series, so end-to-end latency is their sum, and the pipeline "fits" only when that sum is within the conversational threshold:

total  =  tSTT + tLLM + tTTS     fits  ⟺  total ≤ threshold

150 + 400 + 200 = 750 ms ≤ 800 → fits. Swap the LLM to 700 → 1050 > 800 → over budget, feels laggy.

The stage to optimize is the one that dominates the sum — the max — and shaving the bottleneck is what pulls an over-budget pipeline back under the line:

bottleneck  =  argmax(tSTT, tLLM, tTTS)   ⟹   cut it → total falls fastest toward the budget

Bottleneck of (150, 700, 200) is the LLM; halving it to 350 turns a failing 1050 ms into a passing 700 ms. The runnable version below computes the total, the fit, the bottleneck, and the headroom.

RUN IT YOURSELF

The latency budget, in numbers

A voice agent's response time is the sum of its three stages, because the user waits for STT, then the LLM, then TTS. It feels conversational only when that sum stays under the threshold — around 800 ms. The stage to optimize is the bottleneck, the slowest one, since that's where the biggest cuts live: halving a 700 ms LLM turns a failing 1050 ms pipeline into a passing 700 ms. Change the stage times or the threshold and watch the total, the fit, and the bottleneck move.

CPython · WebAssembly
05

Streaming buys time

The math above treats the stages as strictly sequential — a worst case. Production voice agents beat it with streaming: each stage emits partial output as it works instead of waiting to finish, so the stages overlap. Streaming STT sends transcript fragments while the user is still talking, so the LLM can start on the first words before the sentence ends. A streaming LLM emits tokens one at a time, and streaming TTS speaks those tokens as they arrive — so the user starts hearing a reply while the LLM is still generating the rest of it.

The effect is dramatic: the perceived time-to-first-audio becomes far smaller than the naive sum, because the user only waits for the pipeline to begin producing sound, not to fully complete. This is the main reason a voice agent can feel real-time even when each stage individually takes a few hundred milliseconds. The sequential sum is still the right mental model for the budget — it's the ceiling you'd hit without overlap — but streaming is the lever that lets a real system live comfortably under it.

06

Pitfalls

The first trap is optimizing the wrong stage. It's tempting to tune the part you understand best, but if you shave 50 ms off a 150 ms STT while a 700 ms LLM sits untouched, you've barely moved the total. Always measure all three and attack the max. The second is ignoring the network: STT, LLM, and TTS are often three separate services, and every hop between them adds real time. Colocating them, or cutting round trips, can matter as much as the model choice.

Two more that make voice feel broken even under budget. Turn-taking: the agent must know when the user has actually stopped speaking (voice-activity detection and endpointing) and must gracefully handle being interrupted — a human who keeps talking over you feels awful, and so does an agent that won't yield. And no thinking-sound: because the budget is so tight, good voice agents fill unavoidable gaps with a natural filler ("let me check…") so the silence never reads as a freeze. Get the budget right and the interruption handling humane, and a voice agent stops feeling like a phone menu and starts feeling like a conversation. The rule is the whole handbook: keep the sum under the clock, and always cut the slowest stage first.

Worth knowing

End-to-end latency is the sum of STT + LLM + TTS, so budget against that sum, optimize the bottleneck, and use streaming to overlap the stages. But a natural-feeling voice agent also needs good endpointing and interruption handling — low latency is necessary, not sufficient.

By the numbers

Worked example: time to first audio, step by step

The page’s budget counts STT, LLM and TTS. A real turn has two more costs: endpointing, the silence the agent waits through before deciding you have finished, and network hops. Take an illustrative stack: the endpointer waits 300 ms of silence, the LLM’s first token arrives after 200 ms and then one token every 25 ms, the reply is 40 tokens, each hop costs 20 ms. The clock starts when the user stops talking.

StepEventAddsClock (streamed)
1Endpointer hears 300 ms of silence and declares end of turn300 ms300 ms
2Streaming STT finalises; most words were already transcribed50 ms350 ms
3Transcript reaches the LLM20 ms370 ms
4LLM’s first token200 ms570 ms
5First clause done: 5 more tokens × 25 ms125 ms695 ms
6Clause reaches TTS20 ms715 ms
7TTS plays its first audio80 ms795 ms, under 800
8Same stack, no streaming: 300 + 150 STT + 20 + (200 + 39 × 25) + 20 + 200 TTS—1,865 ms
9Streamed, with a 200 ms endpoint instead of 300−100 ms695 ms

Row 8 is the page’s sequential model with a full 40-token reply: 1,175 ms of generation alone puts it more than a second over budget. Streaming moves the user’s wait from “whole reply” to “first clause”, so only the LLM’s time to first token plus a few tokens counts. Rows 1 and 9 show the cost the page’s formula leaves out. Endpointing is the largest single line here, and it is pure waiting. After first audio, generation is far ahead of speech: 40 tokens is roughly 30 words, about 12 seconds of speech at 150 words per minute, produced in just over one second. Generation speed stops mattering; time to first token is what counts.

Trade-offs

Cost and trade-offs: every latency lever has a price

Here Time is the effect on time to first audio, Space is what you pay for it, and Why is the trade-off.

CaseTimeSpaceWhy
Smaller or faster LLMCuts time to first token and per-token timeAnswer quality, tool-use reliabilityOften the right first move, since the LLM is usually the bottleneck. Check quality on real calls, not on benchmarks.
Stream every stageWait drops from the whole reply to the first clause (rows 7 and 8)Engineering: partial transcripts, chunked TTS, cancellationEvery stage must handle being cut off mid-stream when the user interrupts.
Shorter endpoint silenceSaves its full length (row 9)Cuts off users who pause mid-thoughtSemantic turn detection, a model that judges whether the sentence sounds finished, lets you wait less on complete sentences and longer on trailing ones.
Start the LLM on partial transcriptsOverlaps STT and LLMWasted tokens when the transcript changesA speculative start: if the final words change the meaning, throw the draft away and restart.
Colocate servicesRemoves hop time (rows 3 and 6)Less freedom to mix vendors and regionsThree vendors in three regions can spend more on hops than one stage takes.
Speech-to-speech modelRemoves two stage boundariesLess control: no text transcript in the middle for logging, guardrails or tool calls unless the model provides oneFewer hops and more natural prosody, in exchange for a pipeline you can inspect less.
Filler phrase or cached audioPerceived wait near zero for that turnCan sound canned if overusedPre-synthesised “let me check that” covers a slow tool call, but it does not make the real answer any faster.

Measure the 95th percentile, not the mean. A pipeline that averages 700 ms but hits 1,500 ms on one turn in twenty will feel broken to most callers within a few minutes.

In the wild

Where this shows up in production and interviews

  • Phone agents

    Call-centre and booking agents run over the phone network, which adds its own transport and buffering delay before your pipeline even starts. That leaves less of the 800 ms for STT, LLM and TTS, and is why phone deployments push hardest on streaming and colocation.

  • Transport: WebRTC vs WebSockets

    In the browser and in apps, audio usually travels over WebRTC. It was built for live media: it runs over UDP, uses a jitter buffer, and includes echo cancellation, so the agent does not hear its own voice and interrupt itself. WebSockets work and are simpler, but run over TCP, where one lost packet holds up everything behind it.

  • Barge-in

    When the user talks over the agent, three things must happen fast: stop playback, cancel the in-flight LLM and TTS streams, and keep only the part of the reply that was actually spoken in the conversation history. Get the last step wrong and the agent later refers to things the user never heard. Voice frameworks such as LiveKit Agents and Pipecat exist largely to handle this.

  • The interview version

    In “design a voice assistant”, draw the pipeline, write a per-stage budget like the table above including endpointing and hops, and say which stages stream. Then cover interruption, how you would measure p95 time to first audio per turn, and what happens when a tool call takes two seconds.

Self-check

Check yourself

In the streamed timeline above, the LLM’s per-token time doubles from 25 ms to 50 ms. What is the new time to first audio?

Only the five tokens after the first one are on the critical path, so step 5 grows from 125 to 250 ms. Time to first audio becomes 920 ms, over budget. The rest of the reply still arrives faster than it can be spoken.

Your stages measure 150 / 700 / 200 ms and you have a week. Do you spend it on a faster TTS voice or on the LLM?

The LLM. Even removing TTS entirely leaves 850 ms, still over 800. Halving the LLM to 350 ms gives 700 ms. Cut the bottleneck first, as the page says, then make sure the LLM streams so its first token is what counts.

Users complain the agent interrupts them when they pause to think. Latency is fine. What do you change?

The endpointing. The silence threshold is too short for mid-sentence pauses. Lengthening it costs every turn that much time, so the better fix is semantic turn detection: wait less after a complete sentence, longer after “so I was wondering if…”.

After a barge-in, the agent says “as I mentioned, the fee is waived”. The user never heard that. What went wrong?

The agent saved the whole generated reply to the conversation history, not just the part that was played before the interruption. On barge-in, cut the assistant message to the text actually spoken, so the model’s memory matches what the user heard.

Frequently asked

Quick answers

What is a voice AI agent?

A pipeline that hears you (STT), thinks (LLM), and speaks back (TTS), fast enough to feel like a conversation.

Why does latency matter?

The user waits for all three stages, and human dialogue breaks down past ~800 ms — so the sum of stage times decides whether it feels alive.

How do you cut latency?

Find the bottleneck (usually the LLM), shave that first, cut network hops, and use streaming so the stages overlap.

What is streaming?

Each stage emits partial output as it works, so they overlap — the user hears a reply while the LLM is still generating it.

Finished this one? 0 / 209 Handbooks done
NextThe Agentic Coding Handbook Next on the “Shipping an AI product” ladder · rung 4 of 4

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks