Mental model
Speech recognition turns sampled audio into linguistic tokens, but reliable output depends on more than a decoder. A service must control sample rate, channel layout, framing, language and task tokens, chunk overlap, timestamps, and evaluation. Whisper converts log-Mel audio features into encoder states and generates text autoregressively; windowing and decoding policies shape both latency and error patterns.
Theory
A microphone signal is continuous, while a digital model receives samples at a fixed rate. Whisper resamples audio to 16,000 samples per second and computes an 80-channel log-magnitude Mel spectrogram using 25-millisecond windows with a 10-millisecond stride. Short-time Fourier analysis turns each window into frequency energy; Mel filters group that energy into perceptually spaced bands, and a logarithm compresses dynamic range. A small convolutional stem then downsamples the feature sequence before positional information and Transformer encoder blocks are applied.
This front end is sensitive to input handling. A stereo file cannot safely be treated as one long mono stream, and interpreting 48 kHz samples as 16 kHz changes both pitch and duration. If channels are mixed, phase cancellation can erase speech; selecting one channel can be safer when microphones have separate speakers. Clipping, low signal-to-noise ratio, background music, and reverberation alter the spectral pattern the model sees. Resampling must interpolate at the correct rate; merely changing metadata does not resample samples.
The encoder-decoder contract
The encoder represents the audio segment as contextual states. The decoder predicts text tokens one at a time while attending to those states and its previous output. Task and language tokens can specify whether the output should be transcription or translation; optional timestamp tokens associate text segments with positions in the current audio window. This sequence-to-sequence design supports several speech tasks through a shared model interface, but it does not make every transcript equally reliable. Ambiguous names, overlapping speakers, domain jargon, and long silences can still produce plausible but wrong text.
Whisper training uses 30-second audio segments. Long-form inference must therefore decide how to split audio, preserve enough overlap to avoid cutting words, carry context forward, and reconcile repeated or missing text at boundaries. Small windows reduce the time before the first result but offer less context. Large windows can improve context continuity while increasing memory use and delaying output. A timestamp is relative to the segment unless the serving application adds the segment’s offset to produce a recording-wide time.
A concrete error calculation
Suppose a held-out call set contains 400 reference words. After the same text normalization is applied to reference and hypothesis, the system has 12 substitutions, 8 deletions, and 4 insertions. Its word error rate is 24 divided by 400, or 6 percent. If a new normalization rule removes punctuation in hypotheses but not references, the score becomes meaningless; if the evaluation set includes only clean scripted speech, it may also miss failures on telephone audio or accented speakers. Keep the normalizer and domain slices fixed across model comparisons.
Here , , and are the counts of substitutions, deletions, and insertions after word-level edit-distance alignment; is the number of reference words. WER is a percentage of word edits, not a calibrated probability that an utterance is correct. A value can exceed 100 percent when insertions are numerous.
Trade-offs
For interactive dictation, smaller chunks can lower time to the first partial transcript, but provide less acoustic context and create more boundaries to reconcile. A longer window gives the decoder more context and reduces seam work, while delaying feedback and increasing temporary activation memory. Quantized weights can make a browser model fit on more devices, but the right choice depends on error rate for names, accents, and noisy speech. Compare warm and cold latency, peak memory, and normalized WER on the same consented audio slices before selecting a default.
Inference example
This Node example uses the documented Transformers.js ASR pipeline and WAV conversion path. It converts an input file to float samples at Whisper’s expected rate and produces a transcript. The first run downloads model weights; production services should pin a model revision, control the cache, and measure warm and cold-start behavior separately.
javascriptimport { readFile } from "node:fs/promises";import { pipeline } from "@huggingface/transformers";import wavefile from "wavefile";const wav = new wavefile.WaveFile(await readFile("support-call.wav"));wav.toBitDepth("32f");wav.toSampleRate(16000);const decoded = wav.getSamples();const channels = Array.isArray(decoded) ? decoded : [decoded];if (channels.length !== 1) {throw new Error("select one speaker channel or explicitly downmix before ASR");}const mono = channels[0];if (mono.length === 0) throw new Error("audio file contains no samples");const transcribe = await pipeline("automatic-speech-recognition","Xenova/whisper-tiny.en");const result = await transcribe(mono);console.log(result.text.trim());
Failure modes and misconceptions
A pipeline can return fluent text for a clipped file, an unsupported accent, or a noisy recording. Treat the output as a hypothesis: preserve source audio under the retention policy, record model and preprocessing versions, and provide a review path for consequential uses. Never infer a speaker’s identity from a transcript. For call analytics, diarization and speaker labels are separate tasks with their own error modes; a transcript alone does not establish who said a sentence.
Chunking creates a trade-off between context and responsiveness. Too little overlap can delete words at boundaries, while too much can duplicate phrases. A model that fits once may exceed browser memory when several audio jobs run concurrently. Quantized weights reduce download and memory size but may change accuracy; benchmark WER, first-result latency, total real-time factor, and memory on the actual device. If users need streaming feedback, partial text must be marked provisional because later context may revise it.
Training and evaluation also need careful separation. Near-duplicate recordings or the same speaker appearing across splits can make scores optimistic. Compare systems on a fixed, consented dataset stratified by language, channel, noise, and utterance length. Normalize text consistently, inspect deletion-heavy and insertion-heavy cases separately, and set task-specific acceptance criteria instead of relying on one average WER.
Decision scenario
A browser voice-note tool now receives 25-minute multilingual meetings. The current 30-second windows repeat phrases at joins and display each chunk’s timestamps from zero. Before enabling the feature, add measured overlap and alignment-based reconciliation, convert chunk-local times to recording offsets, and evaluate normalized WER plus boundary errors by language and noise. Keep the feature in a limited rollout until those checks pass; a fluent transcript alone does not prove the timing or words are reliable.
Learning outcomes
- Explain how sample rate, channels, windowing, and log-Mel features define an ASR model’s input.
- Trace Whisper’s encoder, task-conditioned decoder, and chunk-relative timestamps.
- Calculate WER and design evaluation slices that expose domain shift and boundary errors.