A design exercise. Read the brief, sketch your answer, then read on. The speech models themselves (streaming ASR, TTS, speech-to-speech) are taught in 26.e and 26.f; this lesson designs the system.
Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Voice-to-voice latency | Time from the user stopping speaking to the first sound of the agent’s reply. The number users feel. |
| ASR | Automatic speech recognition: audio in, text out. A streaming ASR emits partial text while the person is still speaking. |
| TTS | Text-to-speech: text in, audio out. A streaming TTS starts speaking before the whole sentence is written. |
| Cascaded pipeline | ASR → LLM → TTS as three separate models, streamed into each other. |
| Speech-to-speech model | One model that takes audio tokens in and produces audio tokens out, with no text step in between. |
| End-of-turn detection | Deciding that the user has finished speaking: a silence timer (VAD, voice activity detection), often helped by a model that judges whether the sentence is complete. |
| Barge-in | The user interrupting while the agent is speaking. The agent must stop at once. |
| WebRTC | The browser and phone standard for real-time audio and video over the internet, built for low latency rather than reliability. |
1. What is it? The brief#
REQUIREMENTS
Product: a voice agent for customer support, by phone and in an app
Scale: 20,000 concurrent calls at peak; average call 4 minutes; peak/average 2.5
Languages: English and Spanish at launch
Latency: voice-to-voice p50 < 800 ms, p95 < 1,200 ms; barge-in stops audio in < 200 ms
Function: looks up orders and changes bookings through tools
Quality: task success and correct tool calls on our support evals; natural voice
Compliance: calls recorded with consent; personal data stays in-region
QUESTION: design it. API or self-hosted? Cascaded or speech-to-speech? Where do the GPUs go?Facts checked on 13 November 2026.
2. Why does it matter?#
Voice is the least forgiving latency target in inference:
- Conversation has a rhythm. Across languages, people typically answer each other after gaps of around 200 ms (Stivers et al., 2009). A machine that takes a second feels slow; two seconds feels broken, and users start talking over it.
- Every stage adds latency, and they run in series: network, end-of-turn detection, recognition, the language model, speech synthesis, network again. The budget must be divided before anything is built.
- Tail latency is heard. A p99 of 3 seconds means one turn in a hundred has an awkward silence; in a 4-minute call with 20 turns, one call in five hits it.
- It is stateful and long-lived. A call is a streaming session for minutes, with interruptions, tool calls and a growing context.
3. Simple analogy#
A simultaneous interpreter at a conference. They do not wait for the speaker’s whole speech, nor even the whole sentence; they start once they know where the sentence is going, and they stop instantly when the speaker changes direction. A voice agent has to do the same across three models and two network hops, and the audience notices every pause.
4. Tiny example: the latency budget#
The first thing to write in the design doc, before choosing models:
uplink (client → edge) 40 ms
end-of-turn detection 250 ms ← the largest single item
ASR final transcript 60 ms
LLM time to first token 150 ms
LLM first speakable phrase 120 ms
TTS time to first audio 80 ms
downlink + jitter buffer 70 ms
────────
voice-to-voice p50 770 msThe values are typical p50s for a cascaded pipeline, not measurements. Two lessons fall out: the GPU stages are less than half the budget, and the biggest single item is deciding that the user has stopped talking.
5. Technical explanation: the design#
Architecture#
flowchart LR PH["Phone / app"] -->|"WebRTC or SIP"| EDGE["Regional media edge<br/><small>audio in/out, recording</small>"] EDGE --> ORCH["Voice orchestrator<br/><small>turn-taking, barge-in, state</small>"] ORCH --> ASR["Streaming ASR<br/><small>partials every ~100 ms</small>"] ORCH --> LLM["LLM<br/><small>low batch, speculative decoding</small>"] LLM <--> TOOLS["Tools<br/><small>orders, bookings</small>"] ORCH --> TTS["Streaming TTS<br/><small>phrase by phrase</small>"] ORCH -.->|"option"| S2S["Speech-to-speech API<br/><small>gpt-realtime class</small>"] class PH,EDGE io class ORCH warn class ASR,LLM,TTS compute class S2S,TOOLS memory
Cascaded or speech-to-speech?#
| Cascaded (ASR → LLM → TTS) | Speech-to-speech | |
|---|---|---|
| Latency | sum of stages; tunable stage by stage | one model; can be lower |
| Control | text in the middle: log, filter, check tool calls | harder to inspect and guard |
| Model choice | best ASR, LLM and voice separately; easy to swap | one vendor’s model |
| Paralinguistics (tone, emotion, laughter) | mostly lost at the text step | kept |
| Self-hosting | well-understood open components | fewer open options; full-duplex research models such as Kyutai’s Moshi exist |
| Cost per minute | low if self-hosted (section 6) | API pricing per audio token |
For customer support, where tool calls must be correct and logged and personal data must be filtered, a cascaded pipeline is the default, with a speech-to-speech API as an option for launch or for markets where you have no voice model. Frameworks such as Pipecat and LiveKit Agents implement the orchestration layer and support both.
The components#
Media edge. Calls arrive over WebRTC (app) or SIP (phone network) at a regional edge close to the caller. Network round trips are part of the budget: serve each region from GPUs in that region, which also satisfies data residency (23.f, 23.i).
Orchestrator. The heart of the system, and mostly not ML:
- Turn-taking. A VAD with a short silence threshold plus a small model that judges whether the utterance is complete. Too eager and the agent interrupts; too slow and it lags. This is the biggest latency lever.
- Speculative start. Begin the LLM on the ASR partial before the turn is confirmed, and discard the result if the user keeps talking. It wastes some GPU time to save 100–200 ms.
- Barge-in. When the user speaks over the agent: stop audio playback at once, cancel LLM and TTS generation, and propagate the cancellation so GPUs stop working (20.e). Then trim the conversation history to what was actually played, or the agent will believe it said things the user never heard.
- Phrase streaming. Send text to TTS at the first phrase boundary, not the end of the reply.
- Fillers for tools. A tool call that takes 2 s needs a spoken “let me check that” so the line is never silent.
ASR. Streaming, with partial transcripts every ~100 ms and a fast final after end of turn. GPU-hungry at scale because every call streams audio all the time.
LLM. The latency-critical part is time to first token and the first dozen tokens, not throughput. Run at low batch with short contexts (a call’s history is a few thousand tokens), prefix caching for the system prompt (12.m), and speculative decoding (13.n). A medium-size model fine-tuned for the support domain usually beats a large general one on both latency and task success. An SRAM-machine tier (7.k) is an option where per-token speed is the binding constraint.
TTS. Streaming, with low time to first audio. Voice quality is product-critical; evaluate it with listeners, not only metrics.
SLOs#
| SLO | Target |
|---|---|
| Voice-to-voice latency | p50 < 800 ms, p95 < 1,200 ms, measured at the client |
| Barge-in reaction | audio stops < 200 ms after user speech starts |
| Call continuity | 99.9% of calls end normally (not dropped by the system) |
| Task success, tool-call accuracy | on the support eval set, no regression (Module 28) |
| ASR word error rate | per language, tracked weekly |
Failure and overload#
- No queueing. A voice call cannot wait in a queue for a GPU. Admission happens at call start: if capacity is short, route to another region, a fallback API, or a human queue (20.c).
- Per-stage health. Losing TTS mid-call is worse than never starting; keep spare capacity per stage, not only overall.
- Graceful degradation: a smaller LLM, then a speech-to-speech API, then “please hold for an agent”.
6. Under the hood: budget, API cost and self-hosted cost#
The program sums the latency budget, prices a call on OpenAI’s realtime models using their published audio token rates (1 token per 100 ms of user audio, 1 per 50 ms of assistant audio, with the whole conversation re-sent each turn, mostly as cached input), and sizes a self-hosted cascade. Prices are list prices checked on 13 November 2026; the latency values and streams-per-GPU figures are assumptions to replace with your own measurements.
// voice.go — latency budget and cost per minute for a real-time voice agent.
package main
import (
"fmt"
"math"
)
func main() {
// 1. Voice-to-voice latency: from the user stopping speaking to the first agent audio.
// Typical p50 values for a cascaded pipeline, ASSUMED; measure your own.
budget := []struct {
stage string
ms float64
}{
{"uplink: client → edge (WebRTC)", 40},
{"end-of-turn detection (silence + turn model)", 250},
{"ASR final transcript after end of turn", 60},
{"LLM time to first token (2k-token context)", 150},
{"LLM first ~12 tokens (a speakable phrase) at 100 tok/s", 120},
{"TTS time to first audio", 80},
{"downlink + jitter buffer", 70},
}
total := 0.0
for _, b := range budget {
total += b.ms
fmt.Printf(" %-56s %4.0f ms (total %4.0f)\n", b.stage, b.ms, total)
}
fmt.Printf("voice-to-voice p50 ≈ %.0f ms; people leave ~200 ms gaps between turns\n\n", total)
// 2. Cost per call minute. A turn every 12 s: 5 s of user audio, 5 s of agent audio.
// The whole conversation is re-sent each turn, mostly as cached input.
// OpenAI audio tokens: user 1 per 100 ms, assistant 1 per 50 ms; prices checked 13 Nov 2026.
type rt struct {
name string
in, cached, out float64 // $ per million audio tokens
}
const turnsPerMin = 5.0
const userTok, agentTok = 50.0, 100.0 // per turn
for _, m := range []rt{{"gpt-realtime-2.1", 32, 0.40, 64}, {"gpt-realtime-2.1-mini", 10, 0.30, 20}} {
for _, minutes := range []float64{2, 10} {
cost, history := 0.0, 0.0
for t := 0.0; t < minutes*turnsPerMin; t++ {
cost += (userTok*m.in + history*m.cached + agentTok*m.out) / 1e6
history += userTok + agentTok
}
fmt.Printf("%-22s %2.0f-min call: $%.3f per minute\n", m.name, minutes, cost/minutes)
}
}
// 3. Self-hosted cascade for 20,000 concurrent calls at peak. Streams per GPU are ASSUMED.
const peakCalls, peakToAvg = 20000.0, 2.5
stages := []struct {
name string
perGPU float64 // concurrent calls one H100 can serve within the latency budget
}{{"streaming ASR", 200}, {"LLM (~30B, low batch for TTFT)", 300}, {"streaming TTS", 100}}
gpus := 0.0
for _, s := range stages {
g := math.Ceil(peakCalls / s.perGPU / 0.7)
gpus += g
fmt.Printf(" %-32s %5.0f GPUs\n", s.name, g)
}
minutes := peakCalls / peakToAvg * 60 * 730 // call minutes per month
month := gpus * 2.80 * 730 * 1.18 // H100 contract price, +18% platform (23.c)
fmt.Printf("self-hosted: %.0f GPUs, $%.2fM/month for %.0fM call minutes → $%.4f per minute\n",
gpus, month/1e6, minutes/1e6, month/minutes)
}Output:
uplink: client → edge (WebRTC) 40 ms (total 40)
end-of-turn detection (silence + turn model) 250 ms (total 290)
ASR final transcript after end of turn 60 ms (total 350)
LLM time to first token (2k-token context) 150 ms (total 500)
LLM first ~12 tokens (a speakable phrase) at 100 tok/s 120 ms (total 620)
TTS time to first audio 80 ms (total 700)
downlink + jitter buffer 70 ms (total 770)
voice-to-voice p50 ≈ 770 ms; people leave ~200 ms gaps between turns
gpt-realtime-2.1 2-min call: $0.041 per minute
gpt-realtime-2.1 10-min call: $0.047 per minute
gpt-realtime-2.1-mini 2-min call: $0.014 per minute
gpt-realtime-2.1-mini 10-min call: $0.018 per minute
streaming ASR 143 GPUs
LLM (~30B, low batch for TTFT) 96 GPUs
streaming TTS 286 GPUs
self-hosted: 525 GPUs, $1.27M/month for 350M call minutes → $0.0036 per minuteHow to read it:
- The budget closes at p50 but with little room. 770 ms against an 800 ms target leaves 30 ms. The p95 is where it fails: end-of-turn detection and LLM time to first token both have long tails. The first engineering work goes into the turn detector and the LLM’s tail latency.
- API cost per minute grows with call length, because the whole conversation is re-sent every turn. Caching keeps the growth small: from 4.1 to 4.7 cents a minute on the flagship model. Text instructions, tool definitions and telephony are extra and not included.
- The self-hosted cascade is an order of magnitude cheaper per minute (about 0.4 cents) on these assumptions, before the team that runs it. At 350 million call minutes a month, that is roughly $15M a month on the flagship API against about $1.3M self-hosted. Even if every streams-per-GPU figure is four times too optimistic, self-hosting still wins at this volume.
- TTS needs the most GPUs in this sizing. Voice models vary enormously in cost; benchmark several before fixing the architecture.
- The decision follows the brief: start on a speech-to-speech API to learn the product (31.c), then move the cascade in-house per region once volume and evals justify it. Data residency may force in-region self-hosting earlier.
7. Performance implications#
- Optimise the tail, not the mean. Voice users hear p95 and p99. Low batch sizes, isolated GPU pools per stage and no co-located batch work keep tails short (20.k).
- Speculative start and phrase streaming cut perceived latency more than faster kernels.
- Context stays short, so the LLM is decode-bound at low batch: memory bandwidth per user matters (2.e). This is where SRAM machines and speculative decoding pay.
- Region placement is latency. A GPU 80 ms of network away has spent a tenth of the budget before it starts.
8. Production implications#
- Measure latency at the client, per stage, with traces (23.h). Server-side numbers miss the network and the jitter buffer.
- Record and evaluate calls (with consent): task success, tool-call accuracy, interruptions, silences longer than 2 s.
- Capacity is per region and per stage, with admission at call start (23.b).
- Rollouts are per call: never change models in the middle of a call (20.j).
- Plan the peaks: support traffic follows business hours and incidents. An outage elsewhere in the company can double call volume in minutes.
9. Common mistakes#
- Optimising the GPU stages and ignoring end-of-turn detection, the largest latency item.
- Waiting for the full LLM reply before starting TTS.
- Not cancelling work on barge-in. GPUs keep generating speech nobody hears, and the history records words never played.
- Measuring latency on the server. Users hear the network and jitter buffer too.
- Queueing calls for GPUs. Admit or redirect at call start instead.
- Silence during tool calls.
- Choosing speech-to-speech for a workflow that needs inspectable, correct tool calls, without a plan for guarding them.
10. Hands-on exercise#
- Run
voice.go. Cut end-of-turn detection to 150 ms with a better turn model. What p50 do you get? What new risk appears? - Compute the cost of a 30-minute call on the flagship model. Why does the per-minute cost rise?
- Make the LLM stage serve only 75 calls per GPU (a larger model). How many GPUs, and what cost per minute?
- Design the barge-in path in detail: which component detects it, which messages cancel what, and how the history is trimmed.
- Write the admission policy for a region at 95% of capacity.
11. Interview questions#
- Draw the latency budget for a voice agent. Which item is largest, and how do you shrink it?
- Cascaded or speech-to-speech: which would you choose for customer support, and why?
- What has to happen, end to end, when the user interrupts the agent?
- Why should a voice platform never queue calls for GPUs?
- Why does the per-minute cost of a realtime API rise with call length?
- At what scale would you move from a voice API to a self-hosted pipeline?
12. Further reading#
Checked on 13 November 2026.
- Universals and cultural variation in turn-taking in conversation (Stivers et al., PNAS 2009) — the ~200 ms gap between turns across ten languages.
- OpenAI: voice latency and cost guide — audio token rates and why each turn re-sends the conversation.
- OpenAI API pricing — gpt-realtime-2.1 audio at $32 input, $0.40 cached, $64 output per million tokens; mini at $10 / $0.30 / $20.
- Pipecat and LiveKit Agents — open-source voice-agent orchestration frameworks.
- Moshi (Kyutai) — an open full-duplex speech-to-speech model.
- 26.e (streaming speech recognition), 26.f (TTS and real-time voice), 12.p (streaming), 20.e (cancellation and timeouts), 7.k (SRAM machines for per-user speed).