Drills D04

Voice assistant

Design a voice assistant that customers can call or talk to in the app, in Hindi, English or a mix, to check account status and do simple actions. It has to feel like a conversation, not an IVR menu.

45 minutes · revise 14.03 · 14.04 · 14.05 · 31.08 · 10.04 · 29.07 · 29.03

Voice is a latency problem first and an LLM problem second. A text chatbot that takes 3 seconds feels fine; a voice agent that pauses 3 seconds feels broken. The interviewer wants a stage-by-stage latency budget, a clear view of cascade versus speech-to-speech, and the details that only show up in audio: endpointing, barge-in, echo, numbers read aloud, and code-mixed speech.

Clarify and scope

Baseline architecture

A streaming cascade: speech-to-text, LLM, text-to-speech, each streaming into the next, with a turn manager in the middle.

 caller audio (WebRTC / SIP) ─► echo cancel + noise suppress
   ─► VAD (speech / silence frames)
   ─► streaming STT ── partial transcripts ──┐
                    └─ final transcript ─────┤
   turn manager:                             ▼
     endpointing: silence ≥ T ms OR semantic "turn complete" model
     barge-in: user speech during playback ─► stop TTS, cancel LLM,
               truncate assistant history to what was actually heard
   ─► agent: system prompt (spoken style, cached) + state + last turns
        tools: get_account, get_status, block_card (confirm + OTP), transfer
        LLM streams tokens ─► sentence chunker (first clause ASAP)
   ─► text normaliser (numbers, currency, dates → speakable words)
   ─► streaming TTS ─► audio frames ─► caller
   side channels: transcript + timings ─► trace; transfer ─► human queue

The multimodal chapter covers the two pipeline styles in depth.

Key choices and trade-offs

Cascade versus speech-to-speech. A realtime speech-to-speech model takes audio in and produces audio out. It can be faster, keeps prosody and emotion, and handles interruptions natively. The cascade gives control: pick the best speech-to-text for Hindi and code-mixing, put text guardrails and retrieval between stages, keep exact transcripts for audit, and swap any stage independently. For a regulated customer-service use with tools and Indian languages, start with the cascade and keep a speech-to-speech prototype to compare on latency and task success. Check current offerings and prices; this area changes every few months.

Endpointing is the biggest latency lever. The system cannot reply until it decides the user has finished. A fixed silence threshold of a few hundred milliseconds either cuts off people who pause mid-sentence or feels sluggish. Combine VAD silence with a semantic end-of-turn signal (does the partial transcript look complete?), and use a longer threshold after the assistant asks for a number, because people pause while reading digits.

Barge-in. When the user speaks over the assistant, stop playback within about 100 to 200 ms, cancel generation, and record only the part of the reply that was actually played. If the history keeps the full unplayed reply, the model believes it said things the user never heard. Ignore backchannels (“haan”, “hmm”, “okay”) by requiring a minimum speech duration or a meaningful partial transcript. Echo cancellation stops the assistant’s own voice from triggering barge-in on speakerphone.

Speculation on partial transcripts. Start retrieval or even the LLM call on a stable partial transcript, and discard the work if the final transcript differs. It trades tokens for latency.

Write for the ear. The prompt asks for short sentences, no markdown, no lists, one question at a time. A normaliser turns “Rs 1,250.50” and “12/03” into words the TTS will say correctly in the caller’s language, and spells account numbers digit by digit.

Confirm before acting. Read back the action and the key entity (“Block the card ending 4 3 2 1?”) and require an explicit yes. Speech-to-text errors on digits are common; confirmation turns them into a retry instead of a wrong action.

Evals

Guardrails and fallbacks

Observability and cost

One trace per call with per-turn spans: VAD end, STT final, LLM first token, first TTS audio byte, playback start, barge-in events. Store transcripts with timings. Dashboards: voice-to-voice gap per stage, transfer rate and reason, task success, reprompt rate, STT confidence distribution, cost per call minute.

The numbers

Concurrency (Little’s law).

call minutes/day     20,000 calls × 3 min        = 60,000 min
peak hour            12% × 60,000                = 7,200 min in 60 min
concurrent calls     7,200 / 60                  ≈ 120 at peak (plan for 2-3× bursts)
each call holds      1 STT stream + 1 TTS stream + intermittent LLM calls

Latency budget (targets; measure each stage).

endpointing wait after speech ends       300-600 ms   (biggest lever)
STT final after endpoint                 100-300 ms
LLM time to first token                  300-600 ms
tokens until first speakable clause      100-200 ms
TTS time to first audio                  100-300 ms
network + jitter buffer                  50-150 ms
total voice-to-voice                     ~0.95-2.15 s → tighten endpointing,
                                         speculate, use a smaller LLM

Cost per 1K call minutes (check current prices; units differ by vendor):

STT     1,000 × P_stt_per_min           (often billed on all streamed audio)
TTS     assistant talks ~40% of the time at roughly 150 words/min
        ≈ 60 words × ~6 chars = 360 chars per call minute
        → 0.36M chars × P_tts_per_M_chars
LLM     ~4 turns/min × ~3K input tokens (history re-sent) = 12K in, ~320 out
        → 12 × P_in + 0.32 × P_out   (P per million tokens)
total   = 1,000 × P_stt + 0.36 × P_tts + 12 × P_in + 0.32 × P_out
        + telephony per-minute charges

Usually speech, not tokens, dominates. Prompt caching of the system prefix and trimming history keep the LLM term small as calls get longer.

Follow-ups they will ask

How to bring in your own work

You have shipped voice in and out, but not a realtime voice agent. Be exact about the difference.

What else transfers is latency engineering and bilingual handling:

esc

Narrow with repo:jm layer:eval q:naive mine · ↑↓ to move, enter to open