Whisper: Robust Speech Recognition
Whisper is an open-source automatic speech recognition (ASR) system developed by OpenAI in 2022, trained on 680,000 hours of multilingual and multitask supervised audio data scraped from the internet. It matters because it dramatically democratized high-quality speech transcription — previously requiring expensive, domain-specific fine-tuning — by achieving near-human accuracy out of the box across dozens of languages. The counterintuitive fact: Whisper was not trained with any special tricks for robustness; its remarkable noise tolerance emerged purely from the sheer diversity and scale of its training data.
Whisper treats speech recognition not as a specialized audio-engineering problem, but as a sequence-to-sequence translation problem — the same fundamental task as translating French to English. The model takes a short audio chunk, converts it to a visual representation called a spectrogram, and then uses a standard Transformer encoder-decoder to "translate" that image of sound into text. The magic is that by training on an enormous, messy, real-world dataset spanning 99 languages, accents, background noise, and recording conditions, the model learned robustness as a side effect — not as a design goal. The "aha moment" is realizing that the same architecture that powers language translation also powers state-of-the-art speech recognition, unified under one elegant framework.
How It Works
Whisper's pipeline has three major stages: audio preprocessing, encoding, and decoding. Let's walk through each.
Stage 1: Audio → Mel Spectrogram
Raw audio is a waveform — a list of amplitude values over time. Whisper first converts this into a log-mel spectrogram, which is essentially a heatmap showing which frequencies are present at each moment in time. This gives the model a 2D "image" of the sound that is much easier to learn from than raw waveform values. The key parameters: audio is resampled to 16,000 Hz, then split into 25ms windows with 10ms hops, producing an 80-channel mel filterbank. Each 30-second clip becomes a matrix of shape `(80, 3000)`.
Explanation: Each cell in the mel spectrogram is the log-energy of the audio signal at time t and mel-frequency band f, where W is a triangular filterbank that mimics how human ears perceive pitch.
- X_mel(t, f): the spectrogram value at time step t and frequency band f
- STFT(x): Short-Time Fourier Transform of the raw audio signal x — converts a time window to frequency components
- W(f, k): mel filterbank weights mapping FFT bins k to mel frequency bands f
- ε: a small constant to avoid log(0)
Stage 2: Encoder (Listening)
The spectrogram is fed into a Transformer encoder — the same architecture used in vision transformers. Two 1D convolutional layers first compress the spectrogram along the time axis, then sinusoidal positional embeddings are added, and finally a stack of Transformer encoder blocks processes it. This produces a rich sequence of hidden representations — a compressed, learned understanding of "what was said."
Explanation: Each position in the encoded audio attends to every other position, computing a weighted average of values V based on how well queries Q match keys K — this lets the model relate distant sounds to each other.
- Q, K, V: Query, Key, Value matrices derived from the input via learned linear projections
- d_k: dimension of the key vectors (used for scaling to prevent vanishingly small gradients)
- softmax(...): normalizes attention scores to sum to 1, creating a probability distribution
Stage 3: Decoder (Speaking)
The decoder autoregressively generates text tokens one at a time, each attending to both the previously generated tokens (self-attention) and the encoder's audio representations (cross-attention). Special tokens control the task: `<|transcribe|>` means write what you hear; `<|translate|>` means translate to English; `<|en|>` sets the language.
Explanation: At each decoding step, the model computes a probability distribution over its entire vocabulary, picking the most likely next word given both the audio context and everything it has already written.
- token_t: the text token being predicted at step t
- token_{<t}: all previously generated tokens (the partial transcript so far)
- h_t^{dec}: the decoder's hidden state at step t, which fuses audio and text information
- W_o: the output projection matrix mapping hidden states to vocabulary logits
A Minimal Working Example
```python
# Install: pip install openai-whisper import whisper
# Load the model (sizes: tiny, base, small, medium, large) model = whisper.load_model("base")
# Transcribe an audio file result = model.transcribe("my_audio.mp3") print(result["text"])
# Translate from another language to English result = model.transcribe("french_speech.mp3", task="translate") print(result["text"])
# Access per-segment timestamps for segment in result["segments"]: print(f"[{segment['start']:.1f}s → {segment['end']:.1f}s] {segment['text']}") ``` ```python
# More control: manual spectrogram and decoding import whisper import numpy as np model = whisper.load_model("small")
# Load and pad/trim audio to exactly 30 seconds audio = whisper.load_audio("speech.wav") audio = whisper.pad_or_trim(audio)
# Convert to log-mel spectrogram → shape (80, 3000) mel = whisper.log_mel_spectrogram(audio).to(model.device)
# Detect language from first 30s _, probs = model.detect_language(mel) detected = max(probs, key=probs.get) print(f"Detected language: {detected}") # e.g. 'fr', 'de', 'ja'
# Decode with beam search options = whisper.DecodingOptions(beam_size=5, fp16=False) result = whisper.decode(model, mel, options) print(result.text) ```
Alec Radford is a research scientist at OpenAI best known for pioneering large-scale unsupervised and weakly supervised learning, most notably leading development of the GPT series (GPT-1 through GPT-3) and the CLIP vision-language model before Whisper. His key contribution to Whisper was the insight that training a standard encoder-decoder Transformer on weakly supervised internet audio data at massive scale — rather than carefully curated, labeled datasets — would yield a generalist speech recognition system that transfers robustly to real-world conditions. Remarkably, Whisper was trained without any domain-specific audio augmentation or clever ASR tricks: the architecture is nearly identical to a standard sequence-to-sequence Transformer.
Intuition
Imagine you're a highly experienced court stenographer who has attended thousands of hearings in every imaginable setting — noisy courtrooms, quiet offices, phone calls with bad connections, speakers with strong accents. Over time, you've become so familiar with the patterns of human speech that you can transcribe accurately even when audio quality is poor, because you've learned the likely flow of words in context. Whisper works exactly this way. The encoder is like your ears and auditory cortex — it listens to a 30-second chunk of audio and builds a rich internal representation of "what sounds happened." The decoder is like your typing fingers — it generates words one at a time, each word informed both by the sounds it heard AND the words it has already typed (context matters enormously: "I scream for ice cream" sounds identical but the context makes the meaning clear). The spectrogram is like reading sheet music instead of listening to raw sound — it turns the audio into a picture that's much easier to reason about. Just as a musician reading sheet music can tell at a glance what a passage sounds like, the model reads the spectrogram image and "hears" the speech. Finally, the special control tokens (`<|transcribe|>`, `<|translate|>`, `<|en|>`) are like giving the stenographer an instruction card at the start: "Write in Spanish," or "Translate everything to English." The same trained model handles multiple tasks simply by changing which instruction card it receives.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Transformer Architecture · wav2vec 2.0 · CLIP: Contrastive Language-Image Pretraining · Sequence-to-Sequence Learning · Automatic Speech Recognition