Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

aliasing
The false low tones that appear when a signal is sampled too slowly for the frequencies it contains.
amplitude
How far a wave swings from its resting point; the loudness of a sound.
ASR (automatic speech recognition)
The task of turning recorded speech into written words by machine.
Fourier transform
A calculation that splits a signal into the pure frequencies that add up to it.
frequency
How many times a wave repeats each second; one hertz is one repeat per second.
mel scale
A pitch mapping built to match how human hearing spaces low sounds further apart than high ones.
MFCC
A compact set of numbers that describes the shape of a short sound's energy across the mel scale.
phoneme
The smallest unit of sound that can change a word's meaning in a language.
sample rate
How many measurements of a continuous signal are taken each second.
spectrogram
A picture of how a signal's energy at each frequency changes over time.
streaming
Processing audio as it arrives, in small pieces, instead of waiting for the whole recording.
waveform
A plot of a signal's amplitude over time.
window
A short slice of a signal, faded at the edges, that one analysis step examines.
word error rate
The number of word insertions, deletions and swaps needed to turn a transcript into the correct text, divided by the number of correct words.

Speech and audio from the ground up

Capstone: features and word error rate

Build the whole chain once: samples to frames to mel to cepstra, then references and hypotheses to an honest table of mistakes.

Part 10 of 10

Intermediate18 min readBack to Courses

Two halves that meet at a number

The capstone has two halves that meet at a number. The first is a feature extractor: audio in, a matrix of coefficients out. The second is an error report: references and hypotheses (the correct and the produced transcripts) in, a table of mistakes and a corpus rate out. Neither is impressive alone. Together they are the smallest complete speech pipeline, and every production system is a larger version of the same shape. The interfaces between the halves are where most integration bugs live. The shape is the lesson; the size is a small matter.

The extractor is tiny on purpose: one channel, 8 kHz, 256-sample frames, 20 mel bands and 13 cepstral coefficients (a compact summary of the spectrum). The numbers are small enough to print and large enough to be real. The report is honest on purpose: it shows the corpus rate, each utterance and the worst case. A capstone is not a demo; it is a claim you can check. Keep the setup next to the output so the claim can be reproduced.

The extractor, step by step

The pipeline is the one from the course, in order. Frame the signal with overlap, apply a Hann window, take the magnitude spectrum, apply a mel filterbank, take the log, and apply the DCT. The DCT (a cosine transform) packs the shape into few numbers. Each step has a setting, and every setting belongs in the setup. The output is a matrix with one row per frame and one column per coefficient. Print the shape before the values; a transposed matrix is the most common bug in audio code. A shape of (frames, coefficients) is the convention most libraries follow.

Two details decide whether the numbers mean anything. The first is consistency: the same sample rate, window and mel count must be used wherever the features are compared. The second is scale: log energies can be negative, and a model may expect a particular normalisation. Standardise per utterance or per dataset, but write down which. A feature matrix is not self-describing, and a future reader will not guess the settings from the shape.

The same chain in two libraries

import torchaudio
from jiwer import wer

waveform, sr = torchaudio.load("speech.wav")
mel = torchaudio.transforms.MelSpectrogram(sample_rate=sr, n_mels=40)(waveform)
print(mel.shape)
print(round(wer("the quick brown fox", "the quik brown box"), 3))

The whole feature chain

Run the extractor and read the shape and the first frame. Then halve the hop and confirm the number of frames roughly doubles while the coefficients stay the same width.

Output
Click "Run" to execute your code

The report refuses a single number

The report starts with the corpus rate and then refuses to stop there. For each utterance it prints the reference length, the edits and the rate. It totals substitutions, deletions and insertions separately, because a system that deletes endings and one that inserts filler need different fixes. It names the worst utterance, since that is where the next hour of work should go. A table of numbers is more useful than a single score. The worst case is usually more informative than the mean.

Then slice. Group the utterances by speaker, channel or noise level, and report the worst group with its size. A group of three is a hint; a group of three hundred is a finding. Keep the references and hypotheses as files so the report can be rerun after a change. The point of the report is not to certify the system; it is to make the next change measurable. A baseline you cannot rerun is a memory, not a baseline.

Do not tune the extractor and the decoder against the same utterances you report. Hold out a set, freeze it, and touch it once. Otherwise the number measures how long you looked, not how well the system works.

Reproducibility and limits

Reproducibility is a feature of the pipeline, not an afterthought. Pin the sample rate, the frame length, the hop, the mel count and the normalisation in one place, and print them with the result. A different NumPy version should not change a number that matters. Keep a tiny fixed example with known output so a refactor that silently changes the features fails a test. The fixture is worth more than a long comment.

The limits are part of the result. This extractor has no delta features (the change from frame to frame), no voice activity detection and no noise robustness. The report has a handful of utterances and no confidence intervals (a range around each estimate). Say so. A small system that states its scope is more trustworthy than a large one that hides it, and the next engineer can see exactly which assumption to revisit. The capstone is finished when the limits are as clear as the numbers. Write the limits before the summary, so they cannot be forgotten.

The error report

Run the report and read the totals. Then change one hypothesis to delete a word and confirm the deletion count rises while the substitution count does not.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

Which sequence describes the capstone feature extractor?