/experiments/5_8_realtime/

Section 5.8: first-word and final-transcript latency of real-time speech recognition, and whether a name list helps more during or after recognition

Files in this folder

File / folderDescriptionSize
πŸ“ ../Up one level-
πŸ“ sample_output/Subfolder-
πŸ“„ README.md9.6 KB
πŸ“„ live.py4.4 KB
πŸ“„ memos_en.json11.2 KB
πŸ“„ memos_zh.json9.3 KB
πŸ“„ requirements.txt52 B
πŸ“„ run.py12.3 KB

README.md

5.8 Real-time speech recognition: transcribing while you speak, and where the vocabulary list goes

This folder answers two engineering questions about real-time speech recognition (ASR). First, where latency goes in a streaming pipeline: how long after you start speaking the first words appear, and how long you wait after stopping for the finalized transcript. Second, where a proper-noun vocabulary list belongs: passed directly into the speech recognizer via terms, applied afterward by a post-ASR correction LLM, or both, and what each choice costs in accuracy and post-stop wait time.

There are two scripts:

Hardware requirements

Everything runs over APIs, so any computer works. Using live.py with live speech requires a working microphone input device.

Setup and usage

cd 5_8_realtime
uv venv && source .venv/bin/activate      # Or use python3 -m venv .venv if uv is not installed
uv pip install -r requirements.txt
export AI_BUILDER_TOKEN=sk_your_key

python run.py --lang en                   # English sample memos
python run.py --lang zh                   # Mandarin Chinese sample memos (~6 min, ~$0.20)
python live.py --language en              # Speak English into your mic; press Enter when done
python live.py                            # Default --language is zh
python live.py --language en --terms names.txt   # Pass a vocabulary list during ASR (one term per line)

On first run, run.py automatically downloads the 38 sample voice memos from Module 2 (about 13 MB per language) into audio_en/ or audio_zh/, and runs only the 23 memos that mention colleague names. Audio frames are sent at real-time speaking speed (0.1 seconds per chunk) to simulate a live speaker, so streaming each memo takes as long as the recording itself.

The real-time endpoint offers two models: gpt-live-transcribe (the default dedicated real-time transcription model) and --model gpt-realtime (a general-purpose real-time multimodal model).

What you should see

Reference outputs from our runs on 2026-10-23 (recorded on a Mac Studio calling AI Builder Space, two passes each in English and Mandarin Chinese) are in sample_output/. Across the 23 name-bearing memos, run.py scores 31 colleague name mentions and 20 technical term mentions:

Configuration Colleague names right (English, 2 runs) Colleague names right (Mandarin Chinese, 2 runs) Post-stop wait for final text
No vocabulary list 3/31, 3/31 3/31, 3/31 ~0.9-1.0 s
ASR terms only 26/31, 27/31 22/31, 24/31 ~0.8-1.0 s
Post-ASR LLM correction (deepseek) 20/31, 21/31 22/31, 23/31 ~2.5-2.8 s
Both: ASR terms + post-ASR LLM correction 27/31, 28/31 30/31, 29/31 ~2.2-2.5 s
(Reference) Batch upload after speaking, no list 3/31, 3/31 4/31, 4/31 ~1.4-3.1 s

With gpt-live-transcribe, the first incremental words appear about 1.0-1.2 seconds after speech starts (1.2 s median in the English runs, 1.0-1.2 s in the Chinese runs), and draft text continues streaming while you speak. Once speech ends, the finalized transcript arrives in under 1 second, faster than waiting to upload the full clip after speaking.

Key observations from the runs:

Files in sample_output/ and ground-truth inputs

Using your own data

run.py takes two custom inputs: a directory of <id>.wav recordings and a ground-truth JSON file formatted like memos_en.json:

{"people": {"Colleague Name": "role description"}, "terms": ["Term1", "Term2"],
 "memos": [{"id": "001", "text": "Verbatim transcript of what was spoken in this recording"}]}

Run it with python run.py --lang en --audio my_audio_dir --memos my_memos.json (pass --lang zh for Chinese recordings; zh is the default if --lang is omitted). Both the ASR terms list and the post-ASR correction vocabulary list are built from people and terms. Only memos whose ground-truth text mentions at least one name in people are included in the comparison.

Recordings must be 24 kHz, mono, 16-bit WAV files. Convert phone recordings (such as .m4a) first with ffmpeg:

ffmpeg -i recording.m4a -ar 24000 -ac 1 -sample_fmt s16 recording.wav

Scoring rule: if a vocabulary item appears n times in the ground-truth script and k times in the model transcript, it counts as min(n, k) hits. English uses case-insensitive whole-word matching, and Chinese uses case- and space-insensitive substring matching, matching the scoring in Module 2.

The microphone capture path in live.py was verified on a Mac using a virtual audio device (playing recorded audio into the virtual device and capturing from it), and has not been tested with a live speaker talking into a physical microphone.