Neural Audio Codecs and Audio Tokens
Sound does not fit in a box of tokens
A large language model (LLM) can really only do one thing: predict the next token, the next slot in a finite dictionary of symbols. For text this is natural: a text is already a sequence of characters or words, hence a sequence of discrete symbols, you can number them, there is a finite supply, and the model only has to name a number.
Audio is a nightmare for that machinery, and it is worth seeing exactly why. Sound is a continuous, high-rate signal. Speech sampled at 24 kHz means 24,000 decimal numbers per second. Two obstacles, then, not one:
- Length. Feeding those 24,000 numbers per second straight into a Transformer would blow up its context window within a handful of seconds of audio.
- Kind. A Transformer cannot emit an arbitrary decimal number. Its final layer picks a slot from a finite list. It is a slot-namer, not a value-calculator.
The second obstacle is the fundamental one, and it is what gives this chapter its name. For a language model to handle sound, the continuous signal must first be converted into a sequence of discrete symbols: the equivalent of text tokens, but for audio.
So the central question is: how do we turn sound into a handful of symbols per second, drawn from a finite dictionary, without losing the sound?
We want to write sound in an invented alphabet. Every few milliseconds we pick one "letter" out of a few thousand options. The string of letters has to be short enough for a Transformer to digest, yet rich enough that we can reconstruct the original sound from it. That is exactly what a neural audio codec does.
And note that this alphabet is in no way natural: nobody decides in advance what letter no. 417 means. The dictionary is learned during training, alongside the encoder and the decoder.
If the quantization concepts lesson has already gone past your eyes, you have met this chapter's governing idea, applied to something else.
There, the job was to fit a model's weights into 8-bit or 4-bit integers, and the trick was: you do not store the value, you store its position on a graduated ruler. The integer is not the weight, it is the number of the nearest graduation; you keep the width of one graduation alongside it in order to recover a value.
Here it is the same gesture, with two differences. First, we are not quantizing learned weights but a signal, incoming audio. Second, the graduations are not evenly spaced along a line: they are points sitting anywhere in a multi-dimensional space, and the "graduation number" is the index of the nearest point in a learned dictionary. That is called vector quantization rather than scalar.
But the essential part is identical: the number transmitted is not the value, it is an address in a catalogue. Hold on to that sentence and you hold the chapter.
The neural audio codec: an autoencoder that compresses into codes
A neural audio codec is an autoencoder trained to do three things, end to end:
- Encoder: it reads the waveform (the continuous signal) and produces, at a much slower rate, a sequence of vectors that summarize the sound. For an exact order of magnitude: the EnCodec paper states that its encoder outputs 75 steps per second for audio at 24 kHz. We have gone from 24,000 values per second to 75 vectors per second.
- Quantizer: it replaces each continuous vector with the nearest code in a finite dictionary called a codebook. This is where (and only where) the discrete tokens are born.
- Decoder: it reconstructs the waveform from those codes.
The whole thing is trained so the reconstructed sound matches the original as closely as possible, the reconstruction loss, the gap the model is asked to shrink. Almost always an adversarial discriminator is added, borrowed from generative adversarial networks (GANs). The GAN principle in one sentence: two networks are trained side by side, one that makes and one that judges, the judge learning to tell real sound from reconstruction while the maker learns to fool it. Only the "judge" half is used here, as a training signal, and its effect is to push perceived quality up rather than raw numerical fidelity.
SoundStream (Google, 2021) laid down the modern recipe: fully convolutional encoder, residual vector quantization, decoder, adversarial training. Its abstract reports a single model able to operate at variable bit rates from 3 to 18 kbit/s (kilobits per second, the classic measure of audio compression) and to run in real time on a smartphone CPU.
EnCodec (Meta, 2022) took it up, refined it and popularized it; it became the default codec for many speech-generation systems. The paper covers 24 kHz mono and 48 kHz stereo audio.

Residual Vector Quantization (RVQ)
The tricky part is step 2. How do you replace a continuous vector with a code from a finite dictionary without losing too much information?
Plain vector quantization (VQ) takes the vector and replaces it with the nearest codebook entry. The problem: to approximate rich sound well, you would need a gigantic codebook (millions of entries), which is impractical.
Residual Vector Quantization (RVQ) solves this with an idea that fits in three beats:
Approximate the signal with a first symbol. Look at what is left over, the gap between the signal and that first approximation. Approximate that leftover with a second symbol. Repeat.
The word residual means nothing more than that leftover. No level ever sees the original signal: it only sees what the previous levels failed to represent.
The analogy: paying Β£87.43 with the change you happen to have. First the largest note that fits, Β£50. Β£37.43 is left over: that is the residual. Largest note that fits into it, Β£20. Β£17.43 left. Then Β£10, Β£5, Β£2, Β£1β¦ No single denomination is worth Β£87.43, but their sum gets as close as you like, and all you need to transmit is the list of denominations used. You never send the amount: you send a sequence of choices from a finite catalogue.
Concretely, to quantize a vector with codebooks :
Every symbol, spelled out:
- , the vector the encoder produced for one instant of sound, the thing we are trying to represent;
- , the -th codebook: a fixed list of vectors, learned during training and then frozen, our "catalogue of denominations" at level ;
- , at the start everything remains to be represented, so the first residual is the vector itself;
- , the code retained at level : the entry of nearest to the incoming residual. "Nearest" here means ordinary Euclidean distance;
- , the new residual, obtained by plain subtraction: what this level failed to render, and what the next level will have to handle.
Read back as one sentence: at each stage, take what is left, find the most similar code in that stage's catalogue, and subtract to see what is still left.
The final approximation is the sum of the chosen codes, and the residual keeps shrinking as you add levels:
Watch out for one confusion, the learned-versus-computed one: the codebooks are learned parameters, frozen after training and identical for every recording. The codes and residuals are computed on the audio at hand, they change at every instant of every file. And what actually gets transmitted is not even but its row number in : the decoder owns the same catalogue, so a number is all it needs to recover the vector.
Each level therefore produces one token (the index of the chosen code in its codebook). A single instant of sound is not described by one token but by a stack of tokens: the first level gives the coarse skeleton, the next levels add the fine detail.
Three numbers from the EnCodec paper are enough to recover its published bit rates. The paper states that its models use codebooks of 1,024 entries each, "i.e. 10 bits per codebook", as it puts it, since writing a number between 0 and 1,023 takes 10 bits (). And that the encoder outputs 75 steps per second at 24 kHz.
With 8 levels of residual quantization: bits per second, that is 6 kbit/s. Exactly one of the bit rates the paper announces. Double the number of levels and you double the rate, 16 levels give 12 kbit/s, 32 levels give 24 kbit/s, and that is indeed the published grid.
So where does the compression come from? From comparing with the starting point: 24,000 values per second at even 16 bits apiece is 384,000 bits per second. We are dividing by 64. That is what a neural codec does, in one calculation.

Powerful: with 8 codebooks of 1,024 entries, the number of distinct sounds representable at a given instant is , roughly . A single codebook with that reach would need a million billion billion entries, unsearchable. By stacking levels instead of enlarging the catalogue, you multiply the possibilities instead of adding them. That is the whole trick.
Costly: the language model sitting on top now faces several token streams at every time step, not one. Either it predicts them in parallel, which complicates the architecture, or it lays them out end to end, which multiplies sequence length by the number of levels and slows generation accordingly. This is RVQ's Achilles heel, and the reason some recent systems try to avoid it, see the single-stage codec of Voxtral TTS on the Voxtral page.
Semantic tokens vs acoustic tokens
Not all tokens carry the same information. Modern speech systems distinguish two families:
- Semantic tokens: they capture content and meaning, which words, which phonemes, which intonation. They typically come from a self-supervised speech model (HuBERT, w2v-BERT: models trained to predict masked chunks of sound, with no transcript at all, which pushes them to retain linguistic content and ignore timbre), not from a codec. They are stable and few, but they do not contain enough to reconstruct the exact timbre of a voice.
- Acoustic tokens: these are the RVQ codes from a codec like SoundStream or EnCodec. They capture timbre, voice color, fine detail, what makes the sound render well. But on their own they are hard to generate coherently across a whole sentence.
Hence the combined idea, popularized by systems such as AudioLM: first generate the semantic tokens (decide what to say and how, in terms of meaning and rhythm), then generate the acoustic tokens conditioned on them (dress that skeleton with the right timbre). This is exactly the "semantic β coarse β fine" staging found in text-to-speech (TTS) models like Bark, described on the TTS page.
AudioLM (Borsos et al., 2022)| Token type | What it encodes | Where it comes from | How many |
|---|---|---|---|
| Semantic | Meaning, phonemes, prosody | Self-supervised model (HuBERT, w2v-BERT) | Few, one stream |
| Acoustic | Timbre, sonic detail | Neural codec (RVQ) | Many, several levels |

How these tokens feed an audio LLM
Once sound is turned into tokens, audio becomes "just one more language" for a Transformer. The same "predict the next token" scheme works:
- Speech generation / TTS: you give the model the text (text tokens) plus optionally a few seconds of reference voice (acoustic tokens), and it predicts the stream of audio tokens. The codec's decoder turns those tokens back into sound. This is how systems like VALL-E work.
- Audio understanding: you encode the sound into tokens and place them in an LLM's context, which can then summarize, transcribe, or answer questions about the recording.
- End-to-end audio models: a single Transformer handles both text and audio tokens, enabling voice assistants that listen and reply within the same model.
Once sound is discretized, you inherit the whole LLM machinery for free: attention, pretraining, autoregressive generation, mixing text + audio in the same context. The codec does the dirty work of compression; the Transformer only ever sees a sequence of symbols.
Beyond RVQ: compact tokenizers and flow-matching generation
RVQ works well but drags two burdens: the stack of tokens per time step (long sequences, slow generation) and codes that are hard to interpret. Several recent approaches try to shed it.
- More compact tokenizers, sometimes with a single code per time step (instead of an RVQ stack), accepting a lower bit rate in exchange for a much shorter sequence that is easier for an LLM to model. Some also aim for more interpretable codes, closer to phonemes.
- Generation by flow matching rather than stacked codes. Instead of predicting acoustic tokens level by level, you directly generate the continuous representation of the sound (e.g. a spectrogram or continuous features), starting from noise and following a learned velocity field, exactly the mechanism described in the Score-based models and flow matching chapter. This is the approach of F5-TTS: no pyramid of discrete codes, a single continuous generation process, then a vocoder to go back to sound.
The payoff: fewer stages, fewer seam artifacts between levels, and often excellent quality. The trade-off: flow-matching generation is not naturally autoregressive token by token, which changes how you embed it in an LLM and how you handle streaming latency.
The fundamental trade-off: bit rate, quality, latency
The whole design of an audio tokenizer is a balancing act between three forces:
| Lever | If you increase it | Consequence |
|---|---|---|
| Token rate (tokens/second, RVQ levels) | More tokens | Better quality, but longer sequences and slower generation |
| Audio quality | More faithful | Demands more tokens or a heavier decoder |
| Latency | Lower | Forces a lower rate or streaming generation, at the cost of quality |
A real-time TTS for a voice assistant favors latency and accepts a modest rate. An audiobook-production system favors quality and tolerates slower offline generation. There is no universally optimal setting: the right tokenizer depends on the use case.
Key takeaways
- A language model only handles discrete tokens, but audio is a continuous, high-rate signal (24,000 values per second at 24 kHz), so it must first be turned into a sequence of discrete symbols.
- A neural audio codec (SoundStream, EnCodec) is an autoencoder that compresses sound into discrete codes and reconstructs it, almost always with an adversarial discriminator for perceived quality.
- Residual Vector Quantization (RVQ) quantizes in several passes (approximate, look at what is left, approximate that leftover) producing a stack of tokens per time step: powerful for quality, costly for sequence length. The symbol transmitted is never the value, it is an address in a learned dictionary, just as in weight quantization.
- We distinguish semantic tokens (meaning, content) from acoustic tokens (timbre, detail); speech systems combine them (decide what to say, then dress it in the right sound).
- Once discretized, audio becomes "one more language": a Transformer can both generate (TTS) and understand it with the same next-token mechanics.
- Recent approaches aim to drop RVQ: more compact/interpretable tokenizers, or flow-matching generation (see the dedicated chapter), at the cost of a different rate / quality / latency trade-off.
1. Why must audio be converted into discrete tokens before being handed to a language model?
2. In a residual-quantization codec, what is actually transmitted to the decoder for each instant of sound?
3. What does the third quantization level of an RVQ stack Β« see Β»?
4. Why do systems like AudioLM generate semantic tokens first, then acoustic tokens?
5. With 8 codebooks of 1,024 entries, why is RVQ so powerful, and what is its price?