Skip to content

A voice agent that shows its work

A reimplementation of a public-service voice kiosk project using public data. Feed it an FAQ and it becomes a voice agent that shows per-stage latency and per-sentence evidence for every answer.

Client
Public-service civil kiosk project (reimplemented with public data)
Role
Design, implementation, measurement, deployment
Stack
Python · FastAPI · Whisper · Supertonic · onnxruntime · BM25
A voice agent that shows its work

By the numbers

Every figure is a measured value with a source. Values from the rebuilt environment are marked as such.

Time to first audio p50 · local, LLM stub, 50 questions × 3 runs
871.1ms
4,986.1ms → 871.1ms
  • Time to first audio p50 (LLM stub)Reproducible measurement

    4986.1 → 871.1 ms

    ./bench/run.sh --config before·after, ./bench/summarize.sh (local CPU, 50 questions × 3 runs, 2026-10)

  • Time to first audio p50 / p95 (Qwen summarization)Reproducible measurement

    4135.6 / 6399.3 → 2121.2 / 3100.2 ms

    ./bench/run.sh with LLM_BACKEND=qwen, bench/results/summary.md (API key required)

  • Colloquial question retrieval top1 (BM25)Reproducible measurement

    0.289

    uv run python scripts/eval_colloquial.py --faq data/faq/faq.jsonl --eval tests/fixtures/faq_eval_colloquial.jsonl

  • Public server synthesis time per answer, speak_msProduction measurement

    15.1 s → 6.2 s → 4.4~4.7 s

    Same question, 1 run, on the Cloud Run public demo, docs/deploy.md section 11 (2026-10-29)

Original project figures

  • Original environment total voice response timeOriginal project

    10.52 s → 7.40 s

    Development log (private). Different hardware and models, not reproducible

Two lanes, the bell that rings first

How this project works, redrawn as one machine. Left alone it tours itself; press or drag to take over.

How it was solved

01Problem

Synthesizing the whole answer delays the first sound

When the whole answer is synthesized at once, nothing plays until synthesis ends. A 577-character answer stayed silent for over 14 seconds on CPU. In voice, how soon the first sound plays decides how fast it feels.

02Judgment

Cut the time to first audio, not the total time

Total synthesis time was left as it was. The target was the time the user waits for the first audio. A bench that sends the same 50 questions × 3 runs to before and after got the same weight as the feature.

03Principle

Numbers that got worse go in the same table

Per-sentence synthesis raises the total response p50 from 4986.1 ms to 5402.4 ms. That is the cost of an earlier first sound, so it stays in the same table.

04Structure

Sentence streaming and an early first-chunk split

The answer is split into sentences, and each sentence goes out over SSE as a complete WAV. With LLM summarization the first sentence ended late and p50 reached 2755 ms, so the first chunk alone is cut after a comma or connective ending once it has 15 characters.

05Result

Time to first audio p50 4986.1 → 871.1 ms

Time to first audio p50 became 871.1 ms with the LLM stub and 2121.2 ms with Qwen summarization. These are reimplementation measurements on a local CPU, 50 questions × 3 runs.

Real screens

1. Situation

The starting point was a civil-service voice kiosk I worked on in practice. A citizen asks a question out loud, and the kiosk answers out loud, grounded in a civil-service FAQ. I rebuilt this from scratch on a public civil-service FAQ, then widened it into "a transparent voice agent builder that turns an FAQ into an agent."

There were three problems to solve. The first was latency. In voice, when the first sound plays decides how the system feels, and typical builders don't show per-stage timing. The second was hallucination. In domains like civil services, hospitals, or internal company rules, an ungrounded answer is unusable. Every sentence should show its evidence, and with no evidence the agent should say it doesn't know. The third was quality checking. I wanted a number that tells whether an agent built from my documents is usable, without speaking to it dozens of times.

The constraints were clear too. It had to run on a CPU machine with no GPU (16 GB RAM), and audio never leaves the machine.

2. Scoping

I left out PDF and URL input, barge-in and automatic turn detection, an embeddable widget, sign-up, and multilingual support. Kiosk screen integration was cut as well. Instead, a measurement tool that "runs the same question set before and after, side by side" got the same weight as the features.

Retrieval started with BM25 alone. At 575 entries, retrieval latency was not a measured bottleneck, and the accuracy ceiling was exposed as a number and deferred to the next stage. The public demo enforces per-visitor and per-day limits inside a single process, with no external accounts or Redis.

3. Build

CategoryWhatWhy
AdoptedWhisper (STT), Supertonic (TTS), onnxruntime, BM25, Qwen summarization, Cloud RunA combination that runs on CPU and keeps audio local
FixedPinned onnxruntime thread count, container host binding, non-root execution permissionsProblems that actually occurred in the public deployment
Built myselfSentence-level SSE streaming, early split of the first chunk, a leak metric and a colloquial eval set, tuning of the don't-know threshold, a report card, dependency-free rate limiting and bot blockingNothing off the shelf fit what I needed to measure or how to defend a public service

Answers are split into sentences (merged under 10 characters, split over 150 characters), and each sentence is sent over SSE as a complete WAV. WebSocket and PCM chunk streaming were compared and rejected. For rate limiting, I compared slowapi and fastapi-limiter, then wrote my own to fit the single-process constraint.

4. What broke

Doubting an accuracy of 1.000. On a rule-generated eval set, top1 came out at 1.000. My hypothesis was that the questions contained the indexed topic names almost verbatim. I defined a leak metric for how much of the correct topic name's text leaks into the question, and it measured 0.815. I wrote 46 colloquial questions from briefs that hid the topic names, and froze them in a commit before measuring. The result was top1 0.289 (leak 0.210), and I published that number as is. The report card always carries a note that this is not real-world accuracy.

Sentence streaming alone was not enough. Once Qwen summarization was added, "start synthesis whenever the LLM finishes a sentence" put time to first audio p50 at 2755 ms, over the 2200 ms budget. For short answers, the first sentence only finished right before the LLM did, leaving nothing to overlap. I made only the first chunk split early, after a comma or connective ending once it reached 15 characters or more, and p50 dropped to 2121.2 ms.

A bigger CPU was not the answer. On the public demo, synthesizing one answer took 15.1 s with long gaps between sentences. The cause was onnxruntime's default thread count over-allocating on 2 vCPU. I pinned threads to 2 and switched to gen2. I also measured CPU 4 myself: 4 threads were about 2x slower than 2 threads, and CPU 4 + 2 threads matched CPU 2. I went back to CPU 2. Early splitting made the first sentence sound cut off mid-way, so I turned it off on the public demo and compensated by adding "first sentence around 30 characters" to the prompt.

5. Results

Reimplementation

MetricValueScopeSource
Time to first audio p50 / p95 (LLM stub)4986.1 → 871.1 / 8220.0 → 2214.4 msLocal CPU, 50 questions × 3 runs./bench/run.sh, ./bench/summarize.sh
Total response p50 (LLM stub)4986.1 → 5402.4 msSame as above. Grew because of per-sentence synthesisSame as above
Time to first audio p50 / p95 (Qwen summarization)4135.6 / 6399.3 → 2121.2 / 3100.2 msLocal, 50 questions × 3 runs, errors 0/150bench/results/summary.md
Colloquial retrieval top10.289575 public FAQ entries, 46 questionsscripts/eval_colloquial.py
Don't-know threshold 0.20Answerable rows kept 11/11, out-of-scope caught 7/8civil-kiosk presetscripts/tune_unknown.py
Public server speak_ms15.1 s → 6.2 s → 4.4~4.7 sCloud Run, same questiondocs/deploy.md section 11
Time to first audio, final public config4.4~5.2 s (synthesis ratio 0.41~0.48x)Cloud Run, CPU 2, threads 2Development log (private)

The longer total response is the price of bringing the first sound forward, and it stays in the same table.

Original environment

MetricBeforeAfter
Total voice response time10.52 s7.40 s
Average TTS response time4.61 s2.35 s

Different hardware, models, and real-user questions, so these cannot be compared with the reimplementation table above.

6. If I did it again

Time to first audio in the public environment (4.4~5.2 s) is slower than the local Qwen measurement (p50 2121.2 ms). That is the cost of turning off early splitting for unbroken intonation. I would cut the number of TTS steps and compare faster LLM candidates on the same bench.

Colloquial top1 of 0.289 comes from failing to connect synonyms (like "day off" and "closed"). I would compare morphological analysis and an embedding hybrid before and after on the same set. The eval questions were written by AI and the audio is synthetic too, so the first step is replacing them with a set of consented human utterances.

Evidence checking uses bigram overlap, so it can miss paraphrases with the same meaning. With 1 instance and in-memory state, redeploying wipes the rate-limit counters, and cold start time has not been measured yet. I would move the counters to shared storage and then consider horizontal scaling.