How can faster-whisper transcribe a recording locally and send microphone speech to a webpage in segments?

July 24, 2025

I was curious about how commercial interview assistants worked. How could the page show what someone had just said while they were still explaining the question? I found a recording of a mock interview in English and ran a small experiment.

The recording is only about 35 seconds long. The interviewer asks the candidate to design an online reading app and says they'll paste the requirements into CoderPad's shared editor. Converting speech into text is called automatic speech recognition (ASR). I'd looked into Whisper while choosing models for a local client. Now I wanted to try it: could it recognize this recording on my computer? If I switched to a microphone, could I see words appear while I spoke?

Which files do I need when the model download stalls?

I used Python's sounddevice to capture audio and faster-whisper for recognition. Installing both packages still leaves the model weights: the parameters Whisper learned during training and needs for inference. Pass a model name such as "base" to WhisperModel and it looks up the corresponding model. My Hugging Face download wasn't going smoothly, so I asked: if I download it manually, should I get GGUF, ONNX, or something else?1

The answer depends on the software running the weights. Underneath faster-whisper is CTranslate2, the CT2 in my search for base ct2 whisper. Systran distributes a converted multilingual base model. On its files page, model.bin holds the weights, config.json contains configuration, and tokenizer.json and vocabulary.txt help turn recognition results back into text. I put the four files in one model directory and pointed the loader directly at it. One line of the script prints Loading Whisper 'small', which on its own suggests I was loading a different model. The actual loader receives a directory path, and the checksum of the weights in it matches the official base model.2

What can I rule out by testing the same recording first?

I first looked for English test audio, then researched how to record the sound my Ubuntu computer was playing. OBS can capture desktop audio. I had saved an MKV recording, so I extracted its audio with FFmpeg and saved it as testinterview.mp3. Even with the microphone unplugged, I now had an input with known contents that I could replay from the start every time.3

To make a sample the same way, replace the input filename with your recording:

ffmpeg -i interview.mkv -vn testinterview.mp3

-vn makes FFmpeg skip the video, and the output filename's extension specifies MP3. This simplified file test uses the model and sample from that experiment. It runs on a general-purpose processor (CPU), with int8 telling the engine to use 8-bit integer arithmetic for suitable operations. The language parameter en tells the model the recording is in English.1

from faster_whisper import WhisperModel

model = WhisperModel("./model", device="cpu", compute_type="int8")
segments, info = model.transcribe("testinterview.mp3", language="en")
for segment in segments:
    print(f"{segment.start:.1f}–{segment.end:.1f} 秒  {segment.text}")

One easily missed detail in the official usage notes: “the transcription only starts when you iterate over it”. The segments result is a generator: transcription starts producing text segments when the program reaches the loop and asks for them one at a time. Running only the assignment and seeing a quiet screen hasn't tested recognition yet.1

I tried the same MP3 with both zh and en. File mode lets me specify a language, listen to the same passage repeatedly, and compare outputs. I now had a definite test: with English selected, could it transcribe the online reading app question? Once file mode produced text, if microphone mode still did nothing, I had a reason to check whether sound was reaching the program first.

While the microphone is recording, which segment does Whisper hear each time?

During capture I first hit PortAudio library not found. PortAudio is the library sounddevice uses to communicate with system audio devices. The error occurs when opening the input. Changing Whisper's recognition language can't fix it. Only after the program can open an input device is it worth checking whether the microphone is capturing speech.

I added a volume meter to the script. For each audio block, it estimates volume with the root mean square of the samples and draws a row of blocks in the terminal that changes with the volume. If the blocks jump when I speak, the program is receiving a changing signal. Tapping the microphone I actually want to use also tells me which input is selected. That explains why device selection came next: I had two microphones, and the service later let me specify the input with MIC_DEVICE.

The capture script samples one channel at 16,000 samples per second. Each time it collects a full second, it puts those samples in a two-second buffer, pushes out the oldest second, and passes the entire buffer to the model. If I speak continuously for three seconds, the second recognition pass hears seconds 0 to 2, and the third hears seconds 1 to 3. The middle second appears in both inputs. This gives words that cross a boundary a little context, but consecutive outputs can repeat or revise the same word.

The actual code separates capture and recognition. Each time it receives a second of audio, the capture callback copies the samples into a queue and returns to take the next block. The recognition side takes the data out of the queue. The excerpt below updates the buffer, with variable names adapted to their roles. Here window is a two-second mono array initially filled with zeros, and incoming holds one second of samples just taken from the queue.

count = len(incoming)
window[:-count] = window[count:]      # 保留上一轮的后一秒
window[-count:] = incoming.reshape(-1)
segments, _ = model.transcribe(window, language="en")
for segment in segments:
    print(segment.text)

With each new second of sound, then, the script recognizes the most recent two seconds again, and text appears incrementally. Two seconds is the amount of audio handed to the model at a time. How long the text actually takes to appear also depends on how fast the computer processes a segment. Continuous captions would also need a policy for deciding which words are final and which the next pass may overwrite.

How do results reach a webpage that's already open?

Recognition runs on the backend. What the page needs is the newly recognized text. I exposed an /events endpoint in the Python FastAPI service. The browser connects to it with EventSource and keeps that connection open. Each time the server recognizes a segment, it writes a message in server-sent events (SSE) format. The direction suits captions: the backend captures sound, and the browser only has to receive updates.

For example, the server might send data: online reading application followed by a blank line, which ends the event. The page's onmessage handler receives it, appends event.data to the list, and displays a new text bubble.4 Even if two pages are open, the backend needs only one capture and recognition pipeline. It sends each subscriber its own copy of the result.

For this small experiment, I repeatedly tested the same recording from the command line. For microphone tests I selected one input, set the script to recognize English, and sent segments containing text to the page. The bubbles appeared in order of arrival. Whether a bubble sits on the left or the right doesn't establish who said a line. To determine the speaker that way, you'd need to know where the sound came from at capture time.

Footnotes

  1. Klein, G. (2025, January 1). faster-whisper 1.1.1 [Python package documentation]. PyPI. Usage / Faster-whisper, “Warning: segments is a generator” paragraph; model names and download directories in the same version's source. ↩ ↩2 ↩3

  2. Systran. (2023, November 23). faster-whisper-base [Model repository, revision ebe41f7]. Hugging Face. File listing; weight file SHA-256. ↩

  3. Joemamma1080. (2015, January 21). How can I record audio only? [Forum discussion]. OBS Forums. Original thread. See also Ji m. (2022, May 25). How to Record Your Desktop with Audio in Ubuntu 22.04 LTS. UbuntuHandbook. Recording the desktop with sound. ↩

  4. Hickson, I. (Ed.). (2015, February 3). Server-Sent Events [W3C Recommendation]. W3C. Section 4, the EventSource interface; section 6, event stream format. ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-07-24). How can faster-whisper transcribe a recording locally and send microphone speech to a webpage in segments?. https://caiborui.com/blog/2025-07-24-zh-faster-whisper-microphone-web-transcription-entrans

@misc{borui2025-c4dd36d0,
  author = {borui},
  title = {{How can faster-whisper transcribe a recording locally and send microphone speech to a webpage in segments?}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-07-24-zh-faster-whisper-microphone-web-transcription-entrans}
}