Say you record someone saying "send the letter". It's a two-second clip from a laptop microphone, and you'd like a program to write down those fifteen characters. Later you'd like to go the other way: hand the program the same fifteen characters and have it say them out loud. Neither job is obvious, because to a computer the recording is nothing but a long list of numbers, and nothing in that list says where one word ends and the next begins.
This chapter follows that one clip through three problems. First is speech recognition, turning audio into text, and it's where most of the ideas live. Second is speech synthesis, or text-to-speech, and it runs the same story in reverse. Third is joining the two with a language model to build a voice agent that you can talk to in real time, where the difficulty changes from "is the model good?" to "how long does the whole loop take?"
Recognition has an interesting history. For about thirty years it was a chain of separately trained parts glued together when you ran it. Then a 2006 idea called CTC let one network learn from nothing more than recordings and their transcripts, a design called the Conformer (2020) became the standard way to listen, and Whisper (2022) showed that feeding an ordinary transformer huge amounts of messy, imperfectly labeled audio could beat careful design. Today the usual recipe is self-supervised pretraining or large-scale weak supervision, and the frontier is agents that listen, think and speak back with the timing of a conversation.
If you want one sentence for an interview, it's this: modern speech AI is end-to-end neural networks eating what used to be separate signal-processing and language-modeling pipelines, one stage at a time. We'll build up to it by starting with what the clip looks like to a computer and what that makes hard.
01From sound to a spectrogram, and the problem it leaves
What the microphone gives us
A microphone measures air pressure many times a second, and each measurement is one number. The list of those numbers over time is called the waveform, and each number in it is a sample. Typical speech audio is recorded at 16,000 samples per second, so our two-second clip is a list of 32,000 numbers. (The sampling rate has to be at least twice the highest frequency you care about, or you lose information you can never get back. That's the sampling theorem in one sentence.)
If you plotted those 32,000 numbers you'd see a wiggly line, and staring at it tells you almost nothing. Two sounds that are very different to the ear can produce waveforms that look like similar squiggles. What separates a "sh" from an "ah" is which frequencies carry the energy, and raw amplitude smears that information across the whole line instead of showing it. So the first step in nearly every audio model is to compute the frequencies.
Looking at frequencies
Chapter 01's Fourier transform is the tool for this. It takes a stretch of waveform and reports how much energy sits at each frequency, as if the sound were a mix of pure tones of different pitches and it told you how loud each tone is. Here's the smallest possible test of it. The code builds one second of a pure 440 Hz tone (the note A above middle C) as 16,000 samples, runs np.fft.rfft (the transform for real-valued signals), and uses rfftfreq to label each output with its frequency in Hz. Then it asks which frequency has the most energy.
Try it Find the pitch of a tone with a Fourier transform
import numpy as np
sr = 16000 # 16,000 samples per second
t = np.arange(sr) / sr # one second of time stamps
wave = np.sin(2 * np.pi * 440 * t) # a pure 440 Hz tone
spectrum = np.abs(np.fft.rfft(wave))
freqs = np.fft.rfftfreq(len(wave), 1 / sr)
print("samples in one second:", len(wave))
print("loudest frequency:", freqs[spectrum.argmax()], "Hz")
440.0 Hz. That waveform is 16,000 numbers that look like nothing by eye, and the transform turns them into one strong component at 440 Hz. Speech recognition builds on the same step, applied to short overlapping windows of audio.Notice what happened: 16,000 numbers that told us nothing by eye became one clear answer. Speech is harder than a single tone, because the frequencies change many times a second as we move from one sound to the next. A single transform over the whole two seconds would average all of that away and tell us which frequencies occurred but not when. So we cut the waveform into short, overlapping windows of roughly 20 to 25 milliseconds each, about as long as speech stays stable, and run the transform on every window. Each window answers "how much energy is present at each frequency, right now?"
Stack the answers side by side in time and you get a spectrogram. Time runs along one axis, frequency along the other, and brightness shows energy, so it's a photograph of the sound. A mel-spectrogram additionally warps the frequency axis to match how human hearing resolves pitch, with much finer resolution at low frequencies than at high ones. That also turns out to be a more efficient input for a model to learn from. Our clip, cut into frames, becomes a grid of about 200 columns, each describing a few hundredths of a second of "send the letter".
This is why almost every audio architecture, from the hand-built MFCC features of the classical pipeline (MFCCs are hand-engineered features approximating human auditory perception, computed for each frame) through Whisper's input features, starts from some form of spectrogram. The default is starting to shift, since models like wav2vec 2.0, which we'll meet in section 05, learn useful representations directly from the raw waveform.
The problem the spectrogram leaves open
Now we have 200 frames and a transcript, "send the letter", 15 characters long. A speech recognizer is trained on pairs like this, so it has to learn which sounds produce which letters. The trouble is that the training data doesn't say which of the 200 frames belong to which of the 15 characters. This is the alignment problem. Different speakers say the same words at different speeds, so the boundaries shift constantly, and one speaker might spend thirty frames on the "e" in "the" while another spends five.
Why not just label every frame by hand?
You could, and for decades people effectively did. Marking where each sound starts and ends for every training example is slow, expensive and brittle, and it's exactly the kind of labeling step you'd like a neural network to make unnecessary. The older systems found a way around the problem without removing it, and it's worth seeing how, because it explains what CTC changed.
For about three decades, recognition meant a pipeline of separately trained parts. GMM-HMM was the classical baseline, and it had three components doing three jobs. The MFCC features described above came first. A Gaussian Mixture Model then scored how well each frame's features matched each phoneme sub-state (a phoneme is a basic unit of sound, like the "s" in "send"). A Hidden Markov Model handled the temporal sequencing, meaning which state can follow which and for how long, which was the alignment machinery. At decode time all of this was combined with a separate pronunciation lexicon and an n-gram language model (a table of how likely words are to follow each other).
That's three components with three different training objectives, joined by a search algorithm and never trained together against the one thing you care about, a correct transcript. Deep neural networks were the first big neural win, replacing the GMM's scores with a network's, but the HMM alignment machinery and the separately trained language model stayed where they were. So the question for the next section is whether a single network could learn from (audio, transcript) pairs alone, with the alignment worked out on its own.
02CTC: summing over every alignment
Graves and colleagues answered that question in 2006 with CTC, short for connectionist temporal classification. It was popular in deep speech recognition from about 2014 to 2016, with Baidu's Deep Speech line of work as the canonical example. Its trick is to stop insisting on one correct alignment. Instead, the network outputs a guess at every frame, and training rewards it for every possible alignment that spells out the right transcript.
Here's how that works for "send the letter". At each of the 200 frames the network produces a probability for every character in the alphabet plus one extra symbol, the blank, meaning "nothing new is being said in this frame". Picking one symbol per frame gives a path, a 200-symbol string. Most paths are nonsense, but many different paths mean the same thing: spending ten frames on the "s" and ten on "e", or six on "s" and fourteen on "e", should both give the transcript starting "se". We need a rule that maps all of those paths to the same text.
That's the collapsing rule, which chapter 07 covers in full. Given one path, first merge adjacent repeated labels into one, then delete every blank. Take the word "letter" from our clip and write the blank as a dash. The paths l-e-t-t-e-r and lleet-ttterr both collapse to "letter", while letter with no blank collapses to "leter". The blank between the two t's is what stops them merging, and it's the only way CTC can write the same character twice in a row.
With that rule, the training objective follows. The network's probability of the correct transcript y is the total probability of every path that collapses to it:
- π one specific frame-level path: a label, or the special blank symbol, chosen at every one of the T encoder frames.
- P(π∣x) the network predicts each frame's label independently given the audio x, so a path's probability is just the product of every frame's chosen-label probability.
- ℬ(·) the collapse rule: merge adjacent repeated labels into one, then drop every blank. A blank inserted between two identical labels is exactly what lets CTC output the same character twice in a row (like the two t's in "letter") without the collapse rule merging them away.
- ℬ⁻¹(y) the set of every path that collapses to the target transcript y. Summing all of their probabilities means the network never has to be told which exact frame-to-character alignment is "the" right one, only that the total probability mass over every alignment consistent with y should be high.
- computing it naively, that set is enormous. But a forward-backward dynamic program, the same family of trick as HMM forward-backward, computes the full sum and its gradient in time linear in T. You don't need to derive it in an interview; know that it's tractable and isn't brute-forced.
Read the equation from the inside out. scores one path, collects every path that spells our transcript, and the sum adds their scores. Training pushes that total up, so no frame-level label is ever needed. The network is free to decide for itself that the "s" lands on frames 4 to 9, and different speakers can put it elsewhere. You'll see this in practice in the project in section 10, where the network's per-frame output turns out to be mostly blanks with narrow spikes on the letters.
Why did training end-to-end beat the old pipeline?
In the GMM-HMM pipeline, an error made by the acoustic model had no way of being corrected by a later stage, because no stage had ever been trained against the thing you care about, getting the final transcript right. Errors compounded silently down a chain of independently optimized components. CTC, and the two designs we'll meet next, fix this the same way: train the entire network directly against the real objective, so the system as a whole can compensate for weaknesses anywhere in it.
CTC has one assumption that costs something, though. Look at the "P(π∣x)" line above: each frame's label is chosen independently given the audio. The network can't use the characters it has already written to help decide the next one, so knowledge about language, like which letters tend to follow "th", is mostly unmodeled. That limitation drives the next section.
03Fixing what CTC leaves out: attention, RNN-T and the Conformer
CTC was originally built on recurrent networks and later on convolutional or Conformer encoders. In every case it turns audio into per-frame guesses and leaves language structure to a separate model. Two designs tried to put that language structure inside the network.
Treating transcription like translation
Attention-based encoder-decoder recognition, the Listen-Attend-Spell family of the mid-2010s, treats transcription like translation. An encoder reads the audio into a sequence of vectors. Then a decoder, using the attention mechanism from chapter 08, generates characters or subwords one at a time and attends back over the entire encoded audio at every output step. Because the decoder conditions on its own previous outputs, it drops CTC's independence assumption, which tends to help accuracy.
The price is that the decoder wants to see the whole utterance before it can attend well. For our two-second clip that's fine, but for a live caption or a voice agent it means waiting for the speaker to finish before any text appears, so streaming needs extra engineering.
Keeping the language model and streaming together
RNN-T, the Transducer (Graves, 2012; adopted widely for recognition from around 2017 on), was built specifically to fix that. It has three pieces: an audio encoder, a prediction network that behaves like a small language model over the labels emitted so far, and a joint network that combines the two frame by frame. Two properties follow. It only ever needs audio up to the current point, so it's naturally streaming. And because the prediction network already models dependencies between output labels, it leans less heavily on an external language model than CTC typically does. That's why RNN-T became the default recipe for on-device and other latency-sensitive streaming recognition.
Building a better listener
CTC, RNN-T and attention decoders differ in how they produce text, but all of them start from an encoder that turns spectrogram frames into richer vectors. The Conformer (Gulati et al., 2020) is that encoder, not a full recognition system, and it slots into a CTC, RNN-T or attention-decoder head interchangeably. Its idea is to use two tools in the same block. Convolution, which slides a small filter along time with the same weights at every position, is excellent at local acoustic patterns, such as the shape of one phoneme, roughly independent of which frame it starts on. Self-attention, as in chapter 08, is excellent at global context, using the rest of the utterance to work out what an ambiguous or noisy sound probably was. Combining both made the Conformer the dominant encoder within a couple of years of publication. Section 11 returns to why those two tools suit the two timescales of speech.
So now we have three ways to produce the text and one good encoder to feed any of them. Which do you pick? The answer depends on what you're building, and the next section lays the options side by side.
04Choosing between CTC, RNN-T and attention
Each of the three designs comes down to a few questions: can it produce output before the audio ends, what does it assume about how audio lines up with text, how long does it take, and does it need a separate language model to be accurate. The table answers those for each design.
| CTC | RNN-T | Attention seq2seq | |
|---|---|---|---|
| Streaming-capable | Yes, with a causal encoder | Yes, natively — built for it | Not naturally — decoder wants the full encoded utterance |
| Alignment assumption | Monotonic; per-frame labels treated as independent | Monotonic; label dependencies modeled by the prediction network | None enforced — decoder can attend anywhere, which is more flexibility than speech needs |
| Typical latency | Low — single forward pass, frame-synchronous | Low — designed for incremental, on-device decoding | Higher — best accuracy historically came from seeing the whole utterance |
| Needs an external LM for best accuracy | Often — frame independence leaves output-level language structure mostly unmodeled | Less so — the prediction network already behaves like a small LM | Less so — the decoder conditions on its own previous outputs |
Reading across the table, you can see the pattern we've been following. CTC is the simplest and streams with a causal encoder (one that only looks at past frames), but it often needs an external language model fused in for its best accuracy. RNN-T streams natively and carries a language model inside, so it wins on-device and in real-time work. Attention seq2seq historically gave the best offline accuracy because the decoder can look at everything, and that same freedom is what makes streaming awkward. If you can wait for the whole recording, as with meeting transcripts, you can pick the most accurate model and ignore streaming entirely.
Accuracy on a benchmark is the thing models get compared on, but it hides a problem you meet as soon as you deploy one. Recognition accuracy degrades on accents, domains and languages that were underrepresented in the training data. A model can look excellent on an aggregate benchmark and still fail badly for one accent, or in a noisy room it barely saw. That's why per-subgroup error rates matter more than one blended number. That points at the training data more than at the architecture, and it brings up the biggest shift in recent years.
05Scale and unlabeled audio: Whisper and wav2vec 2.0
Everything so far improved recognition by changing the architecture. Whisper (Radford et al., 2022) changes the axis of improvement entirely. It's a fairly ordinary encoder-decoder transformer, with no CTC and no exotic alignment trick beyond ordinary cross-attention. What's unusual is the data: roughly 680,000 hours of audio scraped from the web, paired with whatever transcripts already existed for it. That's weak supervision, since the labels aren't carefully curated, and the data spans dozens of languages and several tasks trained jointly, including transcription, translation and language identification.
Why would messy data beat careful architecture?
Careful architecture tuning historically bought accuracy on whichever benchmark or domain it was tuned against. But real-world audio has enormous unmodeled variability that any curated, clean training set under-represents by construction: accents, background noise, code-switching (switching languages mid-sentence), cheap microphones and non-native speakers. Training on hundreds of thousands of hours of diverse, messy internet audio exposes the model to that variability during training, instead of hoping it generalizes from a clean benchmark. Empirically, Whisper generalizes remarkably well zero-shot to accents, noise and languages it was never specifically tuned for. It's the lesson the LLM world learned around the same time (see 10): scale and data diversity often beat architectural cleverness for robustness. It just costs far more compute and data-collection effort to pull off.
Whisper still needs transcripts, even if they're weak ones. Could a model learn from audio with no transcripts at all, the way BERT learns from unlabeled text (see 03)? wav2vec 2.0 (Baevski et al., 2020) does exactly that. A convolutional network first turns the raw waveform into a sequence of latent audio representations, which get quantized, meaning each is snapped to the nearest entry in a learned discrete codebook. Spans of the latent sequence are then masked, and the masked sequence goes through a transformer. At each masked position the model has to identify which quantized latent, out of a set of distractors, was there, using a contrastive loss. That's the speech analogue of BERT-style masked prediction, and no transcripts are needed during pretraining, only audio. Fine-tune the result on a comparatively small amount of labeled (audio, transcript) data afterward, and it reaches accuracy that would otherwise need far more labels from scratch.
HuBERT takes a related route to the same goal. It clusters audio features into discrete pseudo-labels first, then trains masked prediction of those cluster assignments. The underlying bet is the same as in wav2vec 2.0: most of what a speech model needs to learn doesn't require a single transcript. Between them, self-supervised pretraining and large-scale weak supervision are now the default recipe for recognition, and they leave our clip's transcription in good shape. What about the reverse direction?
06Running it backwards: text to speech
Take the fifteen characters "send the letter" and ask for audio. Synthesis went through the same three eras as recognition, roughly on the same clock. Concatenative synthesis (before the 2010s) spliced together short units of pre-recorded human speech. It was intelligible but had audible seams at every splice point. Parametric synthesis replaced the recordings with a statistical model predicting acoustic parameters and fed them to a vocoder, a component that turns parameters into a waveform. It was more flexible, but it tended to sound flat and robotic, the classic "text-to-speech voice". Neural TTS (2016 onward) replaced both stages with learned models and is the reason synthetic voices now sound close to human.
Two models, not one
Modern neural TTS still typically uses two specialized models. The first is an acoustic model. It predicts a mel-spectrogram from text, the same kind of picture we computed from audio in section 01 but now generated. Tacotron-style systems do this autoregressively (one frame at a time, each depending on the last) with an attention mechanism, and that can occasionally skip or repeat words if the alignment goes wrong. FastSpeech-style systems instead predict a duration for each phoneme up front and generate the whole spectrogram in parallel. That's faster and structurally immune to that failure. For our clip, "the" gets a short duration and the stretched "e" in "letter" gets a longer one, and the spectrogram is laid out accordingly.
A second model, the vocoder, converts that mel-spectrogram into an actual waveform. WaveNet generates raw audio samples autoregressively via dilated causal convolutions, one sample at a time, with extremely high quality but slow output. HiFi-GAN generates the whole waveform in a single parallel forward pass using a GAN-based objective (a generator trained against a discriminator, as in chapter 12). That's dramatically faster, and it became the standard production vocoder.
Why two models instead of one?
Predicting a mel-spectrogram is a text-alignment and prosody problem (prosody is the rhythm, stress and intonation of speech), running at about 80 to 100 frames a second. Synthesizing the waveform means producing tens of thousands of raw amplitude samples a second that match that spectrogram. Those are different output rates and different failure modes, so specializing each model beats forcing one to do both, and it lets you swap a vocoder without retraining the acoustic model. VITS-style systems, which train a single end-to-end model for both jobs, show that the split is a good engineering default and not a hard requirement, and it's still the default for good reasons.
Splitting synthesis in two also makes zero-shot voice cloning straightforward. Instead of training a dedicated model per speaker, you condition the acoustic model (and sometimes the vocoder) on a speaker embedding extracted from a short reference clip. A few seconds of someone's voice is enough to synthesize new speech in that voice, with no additional training for that speaker.
One failure sits outside the neural models altogether. TTS mispronounces rare words, proper nouns and numbers, and part of the cause is that the input has to be turned into speakable words first. Text normalization means rewriting "$42.50", "3/14" or "Dr." as the words you'd say, and it's a real, unglamorous failure surface. Now that we can listen and speak, there are a few smaller models that sit around both.
07The models around the edges
Real products need more than recognition and synthesis. One group answers "who is speaking?", and it's often lumped together as "speaker stuff" even though it's three problems. Speaker identification picks one identity out of a known, enrolled set. Speaker verification is a binary same-or-different check against one claimed identity. Speaker diarization works out who spoke when across a whole recording, with no prior enrollment. The first two usually embed a few seconds of audio into a fixed-size speaker vector and compare it by similarity to an enrolled reference. Diarization instead segments the audio and clusters the segment embeddings into speaker groups. Overlapping speech breaks that segment-and-cluster assumption, because a segment can no longer be assigned cleanly to one speaker, so handling it well needs either source separation up front or a diarization model built to output more than one label at once.
A second group decides when to listen. Voice activity detection (VAD) is the gatekeeper in front of nearly every speech system. It's a small, fast classifier that decides, frame by frame, whether a chunk of audio contains speech at all, so a pipeline can avoid running expensive recognition on silence. It's also the first ingredient in endpointing, the decision about whether the user just finished talking or only paused. Keyword spotting is VAD's narrower cousin: an always-on, low-power model listens for one specific wake word so the rest of the system can stay asleep until it's needed, under a much tighter compute and battery budget than a full recognizer ever has.
Audio rarely arrives clean, and three tools address that. Speech enhancement predicts and removes noise, typically by estimating a mask over the spectrogram (which time-frequency cells are noise and which are speech) and reconstructing a cleaner waveform from the masked result. That measurably improves both perceived quality and downstream recognition accuracy. Source separation is the harder version of the same problem, for when there's no single clean target and you need to recover several overlapping signals, such as multiple speakers or speech mixed with music. Beamforming works from a microphone array, using the small timing and phase differences between microphones to boost sound arriving from one direction and suppress the rest.
Not all audio understanding is about words. Sound event detection identifies and timestamps non-speech events such as glass breaking, a dog barking or a smoke alarm, and audio tagging does the coarser version, labeling a whole clip. Music and general audio generation extend the generative toolkit from chapter 12 to sound, using autoregressive or diffusion-based models over learned discrete audio tokens, in the spirit of wav2vec 2.0's quantized latents, trained to produce new, coherent audio instead of recognizing existing audio. With all these pieces on the table, we can wire the main ones into something you can talk to.
08Chaining it into a real-time voice agent
Wire a speech recognizer, a reasoning model (a large language model, as in chapter 10) and a speech synthesizer together and you have a voice agent. Imagine our caller finishing "send the letter" and waiting for a reply. Past this point the interesting engineering problem stops being any individual model and becomes the pipeline itself, because the delay the caller feels is the sum of every stage's delay.
Each stage has its own job in that latency budget. VAD gates the whole pipeline and drives endpointing, the decision that the user has finished a turn instead of merely pausing. Streaming recognition emits partial hypotheses continuously, so the "final" transcript step is fast instead of starting from nothing. The reasoning stage should start generating and streaming tokens the moment enough transcript is available, without waiting for every downstream step to settle. TTS mirrors that on the way out, streaming audio sentence by sentence as the response text arrives, instead of waiting for the entire reply before synthesizing anything. What matters for the reasoning stage is time-to-first-token and not total generation time, since the response can start being spoken before it's fully generated.
Because the budget is additive, a fast LLM doesn't help if endpointing alone waits an extra beat to be sure the caller is done, and a fast TTS model doesn't help if it sits idle waiting for the whole response text. Building a system that feels responsive means attacking every stage's latency at once, and pipelining each stage so it starts consuming partial output from the previous one the moment that output exists.
Interrupting the agent
Barge-in, shown as the dashed loop in the diagram, is easy to leave out and expensive to leave out. VAD has to keep listening even while the agent is talking. The instant it detects real user speech, the system needs to stop audio playback and cancel or redirect the in-flight generation. That's a full-duplex design requirement as well as a speed problem: a pipeline can hit every individual latency target and still feel broken if it can't be interrupted the way a person would be. Chain VAD, recognition, an LLM and TTS sequentially without designing for interruption, and the agent will talk over the user or ignore them. That's a full-duplex gap and not a model-quality gap.
Does lower word error rate always mean a better voice agent?
Not necessarily. Word error rate (WER) counts the substitutions, deletions and insertions in a transcript against a reference, divided by the number of reference words, and it's the field's default accuracy number. A system with excellent WER but poorly tuned endpointing, cutting people off mid-sentence or waiting too long before responding, or with no barge-in handling at all, will feel worse to talk to than one with a slightly higher error rate and well-tuned turn-taking. Once accuracy is reasonably good, latency and turn-taking usually dominate how "smart" a voice agent feels far more than the last few points of WER do.
Where this is heading
Fully end-to-end speech-to-speech models, with audio in, audio out and no intermediate text, are an active frontier. Collapsing the recognition, LLM and TTS pipeline into one model can cut latency and preserve paralinguistic information (tone, emphasis, hesitation) that a text bottleneck throws away. As of 2026, though, cascaded pipelines are still the more controllable and more widely deployed default in production, mainly because each stage stays independently debuggable, swappable and auditable. Treat "speech-to-speech has already replaced cascaded pipelines" as an overclaim if you see it stated flatly.
09Summary
- Audio models work on spectrograms, not raw samples. Short overlapping windows of 20 to 25 milliseconds each go through a Fourier transform, and stacking the results gives energy by frequency over time.
- Recognition has an alignment problem. The training data doesn't say which frames belong to which characters, and speakers talk at different speeds.
- The classical pipeline never trained as one piece. GMM-HMM, a lexicon and an n-gram language model were joined only at decode time, so errors in one stage couldn't be corrected by another.
- CTC sums over every alignment. A blank symbol and a collapsing rule map many frame-level paths to one transcript, and training raises the total probability of all of them, so no frame labels are needed.
- RNN-T and attention encoder-decoders add the language structure CTC lacks. RNN-T streams natively, while attention decoders usually want the whole utterance.
- The Conformer is the standard encoder. Convolution handles local acoustic patterns and self-attention handles global context, and it works with any of the three heads.
- Whisper bet on data over architecture. About 680,000 hours of messy, weakly labeled multilingual audio gave robustness that careful tuning on clean benchmarks didn't.
- wav2vec 2.0 and HuBERT learn from audio without transcripts by predicting masked pieces, the speech version of BERT.
- TTS usually uses two models, an acoustic model from text to mel-spectrogram and a vocoder from spectrogram to waveform, because the two problems run at different rates and fail in different ways.
- A voice agent's latency adds up across VAD, ASR, the LLM and TTS. Streaming every stage and handling barge-in matter more than shaving the last bit of WER off one model.
- Cascaded pipelines are still the production default in 2026, while end-to-end speech-to-speech models are the active frontier.
10Build this
CTC's sum over alignments is easy to state and hard to believe. One plot of the network's per-frame output settles it in a way no derivation can.
Train a small CTC recognizer on spoken digits, transcribing each clip as the spelled-out word: "three", "seven", "zero". Ten words, a couple of dozen output symbols, clips under a second. The task is trivial on purpose. What you are here to look at is the per-frame output distribution, because that is where the alignment the training data never supplied shows up.
- Get a small spoken-digit corpus, a few thousand short recordings. Label each with its spelled-out word. Your output alphabet is the handful of letters those ten words use, plus one blank symbol.
- Convert each clip to a log-mel spectrogram with
torchaudio. That is the representation from section 01, and it is the one part you should let a library handle. - Encoder: a couple of 1D convolutions and a small bidirectional GRU, then a linear layer to one logit per symbol per frame. Nothing Conformer-sized is needed: a few hundred thousand parameters is plenty.
- Before training, implement the CTC forward recursion by hand for one (audio, transcript) pair. Check your log-probability against what
nn.CTCLossreports on that same pair. That is the marginalization in section 02, computed rather than recited. - Train with
nn.CTCLoss. Then plot the per-frame softmax as a heatmap: symbols down one axis, frames across the other, one plot per clip. - Now break it. Delete the blank from the output alphabet and retrain, keeping everything else fixed.
Where this runs in production
A caller finishes a sentence. VAD and endpointing decide whether they're done talking or only pausing. Streaming ASR, which has been emitting partial hypotheses the whole time, finalizes the transcript quickly since it isn't starting from scratch.
The reasoning stage begins generating a response. What matters here is time-to-first-token, not total generation time, since the response can start being spoken before it's fully generated. Streaming TTS begins synthesizing audio for the first sentence or chunk as soon as enough text exists, rather than waiting for the complete reply, so audio starts playing well before the LLM has finished.
The budget across the whole loop is additive: a fast LLM doesn't help if endpointing alone waits an extra beat to be sure the caller is done, and a fast TTS model doesn't help if it's sitting idle waiting for the entire response text instead of being fed sentence by sentence.
Building a system that feels responsive means attacking every stage's latency at once, rather than optimizing any one model in isolation: streaming ASR partials, low time-to-first-token, sentence-level streaming TTS, and fast, well-tuned endpointing. Pipeline each stage so it starts consuming partial output from the stage before it the moment that output exists.
11The four things that decide real speech systems
Everything above is the standard tour. These four are what separate someone who has read about speech from someone who has shipped it.
Streaming or offline: the axis everything else hangs off
The first question to ask of any speech system is not how accurate it is. It is this: can it emit output before the audio finishes?
That single constraint eliminates most of the design space, because it decides what the encoder is allowed to see.
- Causal encoder. Each frame attends only to frames before it. Zero added latency, worst accuracy. A phoneme is often only disambiguated by what comes after it.
- Limited lookahead. Each frame sees a bounded window of future frames, usually via chunked attention, which is the working compromise in production.
- Full bidirectional. Every frame sees the whole utterance. Best accuracy, and unable to stream by construction.
Lookahead is the amount of future audio the model waits for before committing to an output. It is not an abstract knob. It is paid directly in wall-clock latency, and the user feels every millisecond of it.
Whisper is not merely tuned for offline use. Its encoder has a fixed 30-second input window, with positional embeddings sized to match. Audio shorter than that is zero-padded up to 30 seconds before the model sees it.
So the model always processes a 30-second block. Transcribing an hour-long recording means sliding that window and stitching the pieces together.
It is a fine design for batch transcription of a podcast and the wrong shape for an agent that has to answer in 300 milliseconds. See the model card for the input spec.
RNN-T sits at the opposite end, and its dominance on-device is not an accident. It consumes audio frame by frame, its memory footprint stays bounded no matter how long the utterance runs, and its prediction network supplies language-model-like behaviour without a separate LM to ship and fuse.
Why the Conformer's two halves match speech's two structures
Speech carries information at two very different timescales, and they want different machinery.
- Local, on the order of tens of milliseconds. Phoneme identity lives in the formant pattern of a short window. It is also translation-invariant: an /s/ is an /s/ wherever in the utterance it lands.
- Global, on the order of seconds. Speaker identity, prosody, and sentence-level context. Whether "read" is past or present tense may only be resolvable from a clause several words away.
Convolution is the natural fit for the first. Weight sharing across time is the translation-invariance assumption, stated as an architecture.
Self-attention is the natural fit for the second, because it reaches any distance in one hop.
Run only a transformer and it must learn local acoustic structure from scratch, with no inductive bias pointing at it. Run only a CNN and long-range context needs a very deep stack of dilations to reach. The Conformer stops treating this as a choice.
Neural audio codecs: the move that turned sound into tokens
Most treatments skip this piece, and it is the reason audio joined the LLM era at all.
A language model predicts the next token from a finite vocabulary. Audio is continuous, and arrives as tens of thousands of floating-point samples per second. The two do not obviously fit together.
A neural audio codec closes that gap: it learns to compress a waveform into a short sequence of discrete codes, and to reconstruct listenable audio from those codes alone.
The standard mechanism is residual vector quantization, and the idea is a cascade:
- The first codebook quantizes the encoder output. Coarse, and wrong by some residual.
- The second codebook quantizes that residual, correcting the first stage's error.
- The third corrects what is still left, and so on down the stack.
- Summed back together, the stages converge on the original representation.
Why a cascade and not one enormous codebook? High fidelity needs a very large number of distinct codes. A single flat codebook of that size is impractical to store, search and train. Several small codebooks compose to cover the same space.
SoundStream (Zeghidour et al., 2021) established the pattern, running at variable bitrates from 3 kbps to 18 kbps, streamable, and fast enough for real time on a smartphone CPU. EnCodec (Défossez et al., 2022) followed the same RVQ recipe.
Once audio is a sequence of discrete tokens, every trick from language modelling transfers directly: next-token prediction, scaling laws, and a shared vocabulary with text.
AudioLM made the split explicit: take discretized activations from a masked language model pretrained on audio to carry long-term structure, and codec codes to carry fidelity. Then treat generation as a language modelling problem over that combined sequence.
This is also what makes end-to-end speech-to-speech tractable instead of aspirational. Moshi is a speech-text foundation model built for real-time dialogue, with no text bottleneck sitting in the middle of the loop.
The evaluation trap: what word error rate does not measure
WER counts substitutions, deletions and insertions against the reference, divided by the number of reference words. It is the field's default number, and it is useful. It is also narrower than most people reporting it seem to realise.
- It usually ignores punctuation and casing. Standard WER is computed on normalized text, lowercased and stripped. "lets eat grandma" and "let's eat, Grandma" can score identically.
- Every word weighs the same. Dropping "not" and dropping "the" cost exactly one error each. Only one of them inverts the meaning of the sentence.
- It says nothing about who spoke. A perfect transcript with every speaker label wrong scores a perfect WER. Diarization has its own metric, diarization error rate, for exactly this reason.
- One aggregate number hides the distribution. Strong average WER is compatible with failing badly on one accent or one noise condition.
The practical consequence: pick the metric that matches the thing you are shipping. For a medical or legal transcript, error rate on entities and numbers matters far more than the blended figure. For a voice agent, intent accuracy after the LLM reads the transcript is closer to the truth than WER ever gets.
12Where you meet this in the wild
Speech is unusual in that the same handful of models get deployed under wildly different constraints. The model matters less than the latency budget it has to live inside.
The pattern to notice is that the deployment constraint picks the architecture. Streaming or batch, on-device or cloud, general vocabulary or specialised: answer those three and the shortlist is usually down to one.
- Voice is the natural interface. Hands or eyes are busy, or typing is not available to the user at all.
- The audio already exists and is unsearchable. Transcription converts a dead archive into something you can index, search and analyse.
- You need what text throws away. Tone, hesitation, emphasis and who spoke are all lost the moment audio becomes a transcript.
- Latency is generous. Batch transcription lets you use the largest, most robust model available and ignore the streaming constraint entirely.
- A form field would do. For structured input, typing is faster and a dropdown has no error rate at all.
- Your vocabulary is mostly rare proper nouns and you have no adaptation data. Generic ASR will mangle exactly the words you care about, and headline WER will hide it.
- No transcription error is tolerable and there is no human in the loop to catch one.
- Audio cannot leave the device for privacy or regulatory reasons and you have no on-device compute budget to spend.
13Interview questions
BeginnerWhat's the difference between a waveform and a spectrogram, and why do most audio models use the spectrogram?
A waveform is amplitude over time — one number per sample. A spectrogram is energy per frequency, over time, produced by running a Fourier transform over short overlapping windows of the waveform (the short-time Fourier transform). Models learn far more easily from the spectrogram because it exposes frequency-domain structure — the stuff that actually distinguishes phonemes and pitch — directly, instead of forcing the network to rediscover that structure from raw amplitude on its own.
BeginnerWhy does CTC solve the alignment problem in ASR?
Because you don't know, and the training data doesn't tell you, which audio frames correspond to which output characters — speakers vary in speed, so there's no fixed frame-to-character mapping. CTC sidesteps needing that mapping by having the network output a label (or a blank) at every frame, defining a collapsing rule (merge adjacent repeats, drop blanks) that maps many different frame-level paths to the same final transcript, and training by summing the probability over every path that collapses to the correct transcript. The network only ever needs (audio, transcript) pairs — never frame-level alignment labels.
IntermediateHow does wav2vec 2.0's pretraining objective work, and why is it called the BERT of speech?
A CNN feature encoder turns raw audio into a sequence of latent representations, which get quantized into a learned discrete codebook. Spans of that latent sequence are masked, the masked sequence goes through a transformer, and the model has to identify which quantized latent — out of a set of distractors — was actually at each masked position, using a contrastive loss. Like BERT, it learns a representation purely from unlabeled data by predicting masked content from context, letting you fine-tune on far less labeled (audio, transcript) data afterward than training from scratch would need.
IntermediateWhy does neural TTS typically use two separate models instead of one end-to-end model?
An acoustic model predicts a mel-spectrogram from text — a text-alignment and prosody problem running at maybe 80–100 frames a second. A vocoder converts that spectrogram into a raw waveform — tens of thousands of amplitude samples a second that have to actually match it. Different output rates, different failure modes, different enough problems that specializing each one, and being able to swap a vocoder without retraining the acoustic model, tends to beat forcing one model to do both. Single-stage systems like VITS show the split isn't mandatory, but it's still the more common production default.
IntermediateCTC, RNN-T, and attention-based seq2seq are all valid ways to build a neural ASR system — how do you choose?
If you need streaming and low latency — on-device, real-time transcription — RNN-T is usually the strongest default, since it's built to process audio incrementally and its prediction network already captures label dependencies without leaning as hard on an external language model. CTC also streams reasonably well with a causal encoder and is simpler to implement, but often needs an external LM fused in for the best accuracy. Attention-based seq2seq historically gave the best offline accuracy by letting the decoder attend over the full utterance, but that same flexibility makes it the most awkward of the three to make truly streaming.
DeepDesign a low-latency real-time voice agent — what are the pieces, and where does the latency actually come from?
VAD gates the pipeline and drives endpointing — deciding the user is actually done talking, not just pausing. Streaming ASR emits partial hypotheses continuously so the final transcript is fast rather than computed from scratch. The reasoning stage should start streaming tokens as soon as it has enough transcript, and TTS should synthesize sentence by sentence as those tokens arrive rather than waiting for the full response. The latency budget is additive across every stage, so optimizing any single model in isolation — a faster LLM, say — barely moves the needle if endpointing or non-streaming TTS is the actual bottleneck. On top of that, the system needs full-duplex barge-in: VAD has to keep listening even while the agent is speaking, and detecting real user speech mid-playback needs to immediately cancel audio output and redirect the in-flight generation. Get every latency number right and skip barge-in, and the agent will still feel broken the first time someone interrupts it.
DeepWhy did Whisper's "scale over cleverness" approach outperform more architecturally sophisticated but narrowly-trained ASR systems on real-world robustness?
Curated, clean ASR training sets under-represent the variability real-world audio actually has — accents, background noise, code-switching, cheap microphones, non-native speakers. No amount of architecture tuning against a clean benchmark teaches a model to handle variability it never saw during training. Training on roughly 680,000 hours of diverse, messy, weakly-labeled real internet audio exposes the model directly to that variability, so robustness comes from what the model was trained on rather than how cleverly it was built. It's the same lesson the LLM world converged on around the same time: scale and data diversity often beat architectural sophistication for generalization, at the cost of far more compute and data-collection effort.