Sub topic 1
What Automatic Speech Recognition Does
Automatic speech recognition (ASR) converts spoken audio into written text. This chapter builds the working model you need for the rest of the tutorial: what goes into an ASR system, what comes out, how older and newer designs differ, and where errors come from. Later chapters cover Whisper's specific design and code.
Prerequisites
This chapter assumes you have:
- Basic Python, including installing packages with pip.
- Familiarity with audio files and formats such as WAV and MP3.
- A general idea of what a neural network is.
- Command-line basics.
No signal-processing background is needed. Terms such as "spectrogram" are introduced briefly here and explained fully in the next chapter.
The task in one sentence
An ASR system takes a waveform, which is a sequence of numbers describing air pressure over time, and returns a sequence of words. A typical recording has 16,000 numbers per second. A typical transcript has about 2 to 3 words per second. The system must compress a very long, noisy numeric sequence into a short symbolic one.
This is hard for several reasons:
- Variable speaking rate. The same word can last 150 ms or 600 ms.
- No gaps between words. Speech is continuous. Silence does not reliably mark word boundaries.
- Speaker variation. Voices, accents, and recording devices change the signal a lot for the same words.
- Homophones. "Their" and "there" sound identical. Only context separates them.
- Noise and overlap. Background sound and simultaneous speakers corrupt the signal.
Inputs and outputs
The input is an audio signal. The output depends on what you ask for, and it is useful to separate the possible outputs.
| Output | What it contains | Typical use |
|---|---|---|
| Plain transcript | Words, usually with punctuation and casing | Notes, search, captions text |
| Segment timestamps | Text plus start and end time for each phrase | Subtitles, jumping to a moment |
| Word timestamps | Start and end time for each word | Karaoke-style highlighting, editing audio by text |
| Language label | The detected spoken language | Routing, filtering |
| Translation | Text in another language (for Whisper, English) | Understanding foreign speech |
ASR is not the same as several neighboring tasks:
- Speaker diarization answers "who spoke when". It labels speakers. It does not produce words.
- Speech synthesis (text-to-speech) runs the opposite direction.
- Natural language understanding extracts meaning or intent from text. It usually runs after ASR.
- Voice activity detection decides only whether speech is present in a stretch of audio.
A complete product, such as a meeting-notes tool, usually chains several of these. ASR is one stage.
The classic pipeline
For decades, ASR systems were built from separately trained parts.
- Feature extraction turned the waveform into short frames of frequency information.
- An acoustic model estimated which phonemes (basic speech sounds) each frame likely contained.
- A pronunciation lexicon mapped phoneme sequences to words.
- A language model scored how likely a word sequence was in the target language.
- A decoder searched for the word sequence with the best combined score.
This design works, but each part needs its own data and tuning. A pronunciation lexicon needs expert-written entries, and new languages need new work in every stage. Errors in early stages also pass to later ones.
End-to-end neural ASR
Modern systems train one neural network to map audio features directly to text. There are three common families.
| Family | Idea | Trade-off |
|---|---|---|
| CTC (connectionist temporal classification) | The model predicts a character or token for each audio frame and collapses repeats and blanks | Fast and simple. Each output is predicted independently of the others, so it often needs an external language model |
| Transducer (RNN-T) | Combines an audio encoder with a prediction network that sees previous outputs | Good for streaming. More complex to train |
| Attention-based encoder-decoder | An encoder reads the whole audio. A decoder writes text one token at a time while attending to the encoder output | Strong accuracy and built-in language modeling. Slower, and not naturally streaming |
Whisper belongs to the third family. Its decoder works like a text language model that is conditioned on the audio. That is why Whisper produces punctuation and capitalization, and why it can also produce fluent text that was never spoken. Chapter on limitations covers that failure mode in detail.
Streaming versus offline recognition
Two usage modes shape which model you pick.
- Offline (batch) recognition processes a complete recording. The model can look at the whole file, which improves accuracy. Podcast transcription is an example.
- Streaming recognition emits words while the person is still talking. It has latency limits and cannot see future audio. Live captions and voice assistants need it.
Whisper was designed for offline use on fixed windows of 30 seconds. You can approximate streaming by transcribing short chunks repeatedly, but the model is not built for it, and results near chunk edges are less reliable. Keep this in mind when you decide whether Whisper fits a project.
Where the training data comes from
ASR models learn from pairs of audio and transcript. The data can be:
- Fully supervised: carefully human-transcribed corpora. Quality is high, but the amount is small, often hundreds to thousands of hours.
- Self-supervised: large amounts of unlabeled audio used to pre-train, followed by fine-tuning on a smaller labeled set.
- Weakly supervised: very large amounts of audio paired with imperfect transcripts, such as subtitles collected from the internet.
Whisper takes the weakly supervised route, with a very large and varied dataset. The trade-off is noisier labels in exchange for robustness across accents, noise, and domains. The architecture chapter returns to this.
How to judge an ASR system
The standard metric is word error rate (WER). You align the model output (the hypothesis) with a human transcript (the reference) and count three kinds of mistakes:
- S: substitutions, where a wrong word replaces the right one.
- D: deletions, where a word was missed.
- I: insertions, where an extra word was added.
WER = (S + D + I) / N, where N is the number of words in the reference. If the reference is "the quick brown fox" and the output is "the quick brown box", then S = 1, D = 0, I = 0, N = 4, and WER = 0.25.
You can compute this with the jiwer library:
import jiwer
reference = "the quick brown fox"
hypothesis = "the quick brown box"
print(jiwer.wer(reference, hypothesis))This prints 0.25.
Some details matter when you compare numbers:
- WER can exceed 1.0, because insertions count as errors. A system that outputs many extra words can score above 100%.
- Casing, punctuation, and number format ("10" versus "ten") change the score unless you normalize both texts first. Always apply the same normalization to reference and hypothesis.
- A WER of 5% on clean read speech says little about performance on noisy phone calls. Compare systems on data that resembles your own.
- WER treats all words equally. Missing "not" and missing "the" cost the same, although the first reverses the meaning.
A later chapter covers evaluation in more detail.
Common sources of error
Knowing the typical error types helps you diagnose problems later.
- Acoustic mismatch. Noise, echo, low-bitrate compression, or a distant microphone degrade the signal.
- Rare vocabulary. Names, product terms, and jargon are often misspelled, because the model has seen them seldom.
- Accent and dialect. Accuracy drops for speech styles that were underrepresented in training.
- Language mix. Code-switching between languages within a sentence confuses language-dependent decoding.
- Silence and non-speech. Some models write text for audio that has no speech. This is a known risk with generative decoders.
- Overlapping speakers. Two people talking at once usually yields one garbled or partial transcript.
Most of these can be reduced by better audio capture, which is often cheaper than switching models. A close microphone and a quiet room help more than a bigger model.
Where Whisper fits
The rest of this tutorial uses Whisper, which is a family of attention-based encoder-decoder models. In terms of this chapter:
- It is end-to-end. No separate lexicon or acoustic model.
- It is weakly supervised, trained on a large multilingual set.
- It is mainly offline and works on 30-second windows.
- It transcribes in many languages and can translate speech to English.
- It does not label speakers.
The first call is short. You will unpack each part in later chapters.
import whisper
model = whisper.load_model("base")
result = model.transcribe("audio.mp3")
print(result["language"])
print(result["text"])This requires the openai-whisper package and ffmpeg installed on your system, because ffmpeg decodes the audio file. The result dictionary holds the detected language, the full text, and a list of timed segments.
Exercise
A reference transcript has 10 words. A system's output has 1 substituted word, 1 deleted word, and 2 inserted words relative to the reference. What is the WER, and why can WER be greater than 1.0?
Show answer
WER = (S + D + I) / N = (1 + 1 + 2) / 10 = 0.4, or 40%. WER can exceed 1.0 because insertions add errors without reducing the reference length N. If a system outputs many extra words, the error count can be larger than the number of reference words.
Exercise
You need live captions with under one second of delay for a conference talk. Based on this chapter, name one reason a plain 30-second-window Whisper setup may be a poor fit, and one alternative approach.
Show answer
Whisper is designed for offline recognition on 30-second windows. It sees a whole window before decoding, so it adds delay, and chunking audio into short pieces to fake streaming gives less reliable text at chunk edges. An alternative is a streaming-oriented model such as a transducer (RNN-T) system. Another option is to accept a few seconds of delay by chunking carefully. end