Search

Search papers and lessons

Automatic Speech Recognition

Level 3 · 10 min read

Automatic speech recognition turns a recording of speech into text by reading the sound in short time slices and predicting the letters, usually with a neural network trained on paired audio and transcripts.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Probability
  • Algorithms
  • Linear algebra
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

Automatic speech recognition (ASR) is the task of turning a recording of someone talking into written text. The system cuts the audio into short time slices, turns each slice into numbers, and predicts the letters or words that were said. Modern systems are neural networks trained on many hours of recordings that come with their transcripts.

Builds on: Time-Frequency Representation, Recurrent Neural Network, Connectionist Temporal Classification (CTC), Edit Distance · Leads to: speech assistants, captioning and dictation tools, and the speech front ends of multimodal language models

Where it's used

Phone dictation and voice assistants. When you dictate a message, the phone converts the audio to text on the device or in a data centre, then the text is handled like any typed input. The system has to work with many accents, background noise and fast speech, all within a fraction of a second of delay.

Automatic captions. Video platforms generate captions for uploaded videos with ASR. The captions are imperfect, so the system also has to decide where sentences end and how to write names; models that predict likely word sequences help with this, see Language Model. Captioning is a good test of accuracy, because readers notice every wrong word.

Call centres and meeting notes. Companies transcribe calls to search them, count topics and check compliance. Here the recordings are noisy and two people often talk at once, so the error rate on real calls is usually higher than on clean studio speech. Teams that compare ASR systems report word error rate on their own call recordings, not on benchmark sets.

How it works

Take a tiny clip and follow it through the system. The example uses round numbers; a real system uses the same steps with more and larger numbers.

  1. Record the sound as numbers. A microphone turns air pressure into a waveform: a list of samples, one per tick of the clock. At 16,000 samples per second, a one-second clip is a list of 16,000 numbers. Check: a 2-second clip has 32,000 samples.
  2. Cut the waveform into short overlapping frames. Take a window of 25 milliseconds and slide it forward by 10 milliseconds each time. Each window becomes one frame. Check: a 1-second clip gives about 100 frames, one every 10 milliseconds.
  3. Turn each frame into a spectrum. A short-time Fourier transform measures how strong each frequency is inside the window. Stacking the frames side by side gives a Time-Frequency Representation, a picture called a spectrogram with time across and frequency up. Vowels show as bands of energy at particular frequencies, and that is what lets the network hear them.
  4. Read the frames in order. A network reads the spectrogram one frame at a time, keeping a memory of what came before. A Recurrent Neural Network does this directly. Modern systems use a Transformer that looks at all frames at once. Either way, the output for each frame depends on the frames around it, so a short sound can be read in context.
  5. Output one symbol per frame. For each frame, the network produces a score for every symbol in its alphabet. The alphabet is 26 letters, a space and a special blank symbol. A Softmax turns any list of scores into positive numbers that add to one, so each frame ends up with a probability for each symbol. The blank means "nothing new in this frame".
  6. Collapse the frames into text. The network produces one symbol per frame, so a word stretched over 30 frames gives 30 symbols. Connectionist Temporal Classification (CTC) (CTC) removes the repeats and then removes the blanks. Two letters that really are doubled must be split by a blank, which is why "hello" needs a blank between the two l's.
  7. Score the transcript against the truth. Compare the output with a reference transcript using Edit Distance: count the insertions, deletions and substitutions needed to turn one into the other, then divide by the number of words in the reference. This is the word error rate, the usual score for ASR.
flowchart LR
  A[waveform samples] --> B[frames every 10 ms]
  B --> C[spectrogram]
  C --> D[network reads frames]
  D --> E[one symbol per frame, with blanks]
  E --> F[CTC collapse to text]

The network is trained by gradient descent on pairs of audio and transcript. The loss compares the probabilities the network gives to the correct transcript, summed over every way the frames could line up with its letters. This is what CTC makes possible without someone marking the letter boundaries by hand.

The math

Let the waveform be x1,…,xTx_1, \dots, x_T and the spectrogram frames f1,…,fN\mathbf{f}_1, \dots, \mathbf{f}_N, where NN is the number of frames. Let the network output, for each frame nn and each symbol kk in the alphabet A\mathcal{A} (which includes the blank), a probability pn(k)p_n(k). The probabilities for one frame sum to one.

Step 5 in symbols: the frame probabilities

The network gives a distribution over the alphabet for each frame. Writing zn\mathbf{z}_n for its raw scores, the Softmax is

pn(k)=exp⁡(zn,k)∑j∈Aexp⁡(zn,j).p_n(k) = \frac{\exp(z_{n,k})}{\sum_{j \in \mathcal{A}} \exp(z_{n,j})}.

Each pn(k)p_n(k) lies between 0 and 1, and the probabilities over kk add to 1.

Step 6 in symbols: alignments and collapse

An alignment is a choice of one symbol πn\pi_n per frame, so a path π=(π1,…,πN)\pi = (\pi_1, \dots, \pi_N). Its probability, if the frames are treated as independent given the input, is ∏npn(πn)\prod_n p_n(\pi_n). The collapse map B\mathcal{B} removes repeated symbols and then blanks. For example B(h,h,−,e,e,l,−,l,o)=hello\mathcal{B}(h, h, -, e, e, l, -, l, o) = \text{hello}, where −- is the blank. The probability of a transcript yy is the sum over every path that collapses to it:

P(y∣x)=∑π : B(π)=y∏n=1Npn(πn).P(y \mid x) = \sum_{\pi \,:\, \mathcal{B}(\pi) = y} \prod_{n=1}^{N} p_n(\pi_n).

CTC computes this sum with dynamic programming, so it does not list every path.

Step 7 in symbols: word error rate

If the reference has WW words and the best alignment of hypothesis to reference needs SS substitutions, DD deletions and II insertions, the word error rate is

WER=S+D+IW.\text{WER} = \frac{S + D + I}{W}.

A WER of 0.1 means about one word in ten is wrong. It can exceed 1 when the output has many insertions.

Worked examples

Example
1. Counting errors in a short transcript

Reference: "the cat sat". Hypothesis: "the cat sat down".

  1. The reference has W=3W = 3 words.
  2. The hypothesis adds one word, "down", at the end. That is one insertion, so I=1I = 1, with S=0S = 0 and D=0D = 0.
  3. The word error rate is (0+0+1)/3=1/3(0 + 0 + 1) / 3 = 1/3, about 0.33.

Interpretation: one extra word in a three-word reference gives a WER of one third. Short references make WER jumpy, so a score on a few words says little.

Example
2. Collapsing a frame sequence to a word

The network outputs one symbol per frame. Here are 9 frames, with the blank written as -:

h,h,−,e,e,l,−,l,oh, h, -, e, e, l, -, l, o

  1. Merge runs of the same symbol: h,−,e,l,−,l,oh, -, e, l, -, l, o. The two hh's became one, and the two ee's became one.
  2. Remove the blanks: h,e,l,l,oh, e, l, l, o.
  3. Read the result as text: "hello".

Interpretation: the blank between the two ll's is what keeps them as a double letter. Without it, step 1 would merge them into a single ll, and the output would read "helo".

Example
3. Frames in a realistic clip

A video call produces a 10-second clip at 16,000 samples per second. The system uses a 10-millisecond hop and a 28-symbol output alphabet: 26 letters, a space and a blank.

  1. The clip has 10×16000=16000010 \times 16000 = 160000 samples.
  2. One frame every 10 milliseconds gives 10/0.01=100010 / 0.01 = 1000 frames.
  3. Each frame gets 28 probabilities, so the network produces 1000×28=280001000 \times 28 = 28000 numbers for the clip.
  4. Each frame's 28 probabilities add to 1, so the network makes 1000 separate choices. CTC then collapses them into text. A spoken word that lasts 0.3 seconds covers 30 frames.

Try it: how many frames does a 4-second clip at a 10-millisecond hop produce? Answer: 4/0.01=4004 / 0.01 = 400 frames.

Common mistakes and tradeoffs

It is tempting to think that ASR is "matching the sound of each word in a dictionary". In fact modern systems never see a dictionary of words; they output letters, one symbol per frame, and CTC or a decoder such as Beam Search assembles the text. This is why a system can spell a name it has never seen as a whole word.

It is tempting to think that a low word error rate on a benchmark means a low rate on your audio. In fact error rates rise with noise, accents, overlapping speakers and domain words such as drug names. Measure on recordings like the ones you will use.

It is tempting to think that the blank is an error token. In fact the blank is what lets the network say nothing for a frame, and it is the only way to write a double letter. Without it, CTC cannot represent "hello".

Tradeoffs. CTC is simple and fast, and it does not need a separate alignment step, but each frame is labeled on its own, so the output has no built-in way to model whole-sentence structure. Encoder-decoder models with Attention Mechanism read the whole input and write text autoregressively, which handles context well at a higher cost in time. Many systems add a Language Model to pick between candidate transcripts, because a word that sounds right may not fit the sentence. Use CTC when latency and simplicity matter; use an encoder-decoder with a strong language prior when accuracy on long, varied speech matters more.

History

Early machines recognised spoken digits. In the early 1950s, Bell Labs built a system that recognised a single speaker saying the digits, and IBM's early-1960s "Shoebox" recognised 16 spoken words. These systems matched sound patterns to stored templates, and they worked only for one speaker.

From the 1970s to the 2000s the standard approach was the Hidden Markov Model. It modelled speech as a hidden chain of sound states, with separate parts for sounds, pronunciations and language. It worked, but each part was built and tuned by hand.

Around 2009 to 2012, neural networks replaced the sound models in these systems and cut error rates sharply, which drew wide attention. Connectionist temporal classification in 2006 had already offered a way to train a network on unaligned audio and text, and later work on large recurrent and transformer networks made it the basis of end-to-end systems. Systems such as Whisper, released in 2022, train one network on large collections of audio with transcripts. Whisper's training data covers hundreds of thousands of hours of audio.

Recap

Read next: Connectionist Temporal Classification (CTC) for the training objective, then Attention Mechanism for the encoder-decoder alternative. Robust Speech Recognition via Large-Scale Weak Supervision applies these ideas at very large scale.

Check yourself

QuestionWhat does the blank symbol do in a CTC output?Show answer
It marks a frame that adds no new letter. It lets the network write a double letter, because the blank separates two identical symbols, and the collapse step removes blanks at the end.
QuestionA reference has 8 words. A hypothesis has 1 substitution, 1 deletion and 2 insertions compared with it. What is the word error rate?Show answer
The WER is (1+1+2)/8=4/8=0.5(1 + 1 + 2) / 8 = 4/8 = 0.5.
QuestionA system collapses the frame sequence a,a,−,−,b,−,aa, a, -, -, b, -, a with −- as the blank. What text does it produce?Show answer
Merge repeats: a,−,b,−,aa, -, b, -, a. Remove blanks: a,b,aa, b, a. The output is "aba".
QuestionWhy does a clip at 16,000 samples per second with a 10-millisecond hop produce 100 frames per second, not 16,000?Show answer
The frames are windows that slide forward by 10 milliseconds, so there is one frame every 10 milliseconds, which is 100 per second. Each frame contains many samples, the 25-millisecond window, rather than one sample each.
QuestionA company's call-centre transcripts have a much higher error rate than the vendor's benchmark. Give two reasons why this is expected, and one thing it suggests about how to evaluate.Show answer
Real calls have background noise and overlapping speech, and they contain accents and domain terms the benchmark may not cover. This suggests measuring WER on a sample of the company's own recordings, not relying on the benchmark score.

Sources