TAI BUI
Back to curriculum
LearnPython

Neural Audio Codecs — EnCodec, SNAC, Mimi, DAC and the Semantic-Acoustic Split

By 2026, audio generation is almost all tokens. EnCodec, SNAC, Mimi, and DAC turn continuous waveforms into discrete sequences a transformer can predict. The semantic-vs-acoustic split, first codebook as semantic, the rest as acoustic, is the most important architectural shift for audio since the Transformer itself.

TIME: ~60 minutesPREREQUISITES: Phase 6 · 02 (Spectrograms), Phase 10 · 11 (Quantization), Phase 5 · 19 (Subword Tokenization)

Learning Objectives

  • Explain why LLM-style audio models need a neural audio codec, and why splitting a semantic codebook from acoustic codebooks fixes the blurry-speech problem pure reconstruction codecs hit.
  • Describe how Residual Vector Quantization (RVQ) cascades small codebooks into a large effective vocabulary, and compute how a codec's frame rate determines LM sequence length and generation cost.
  • Compare EnCodec, DAC, SNAC, and Mimi on frame rate, bitrate, and reconstruction quality, and pick the right codec for a given generative or compression task.
  • Encode and decode audio with EnCodec, and split Mimi's semantic codebook 0 from its acoustic codebooks 1-7 in code to see why corrupting one destroys intelligibility while the other barely matters.

The Problem

Language models work on discrete tokens. Audio is continuous. Any LLM-style model for speech or music (MusicGen, Moshi, Sesame CSM, VibeVoice, Orpheus) needs a neural audio codec first: a learned encoder that discretizes audio into a small vocabulary of tokens, plus a matching decoder that reconstructs the waveform.

Two families have emerged:

  1. Reconstruction-first codecs, like EnCodec and DAC, optimize for perceptual audio quality. Their tokens are "acoustic": they capture everything, including speaker identity, timbre, and background noise.
  2. Semantic-first codecs, like Mimi (Kyutai) and SpeechTokenizer, force the first codebook to encode linguistic and phonetic content, often by distilling from WavLM. The rest of the codebooks handle acoustic detail.

The 2024-2026 insight: a pure reconstruction codec gives you blurry speech when you try to generate from text. The LLM over codec tokens has to learn both language structure and acoustic structure in the same codebook, and that doesn't scale. Splitting them into a semantic codebook 0 and acoustic codebooks 1-N is what makes Moshi and Sesame CSM work.

Warm-up0/3
1. What is the main trade-off when continuous values are quantized to a small fixed set of allowed values?Warm-up
A number line from 0 to 1 with five orange tick marks at 0, 0.25, 0.5, 0.75 and 1, three blue input points at 0.10, 0.42 and 0.86 above it, and a question mark under each input asking what is stored.
Typed example values, for illustration.
2. Why do language models work on tokens from a fixed vocabulary rather than on raw continuous values?Warm-up
Two input rows. The first is the words the cat sat on the, the second is five decimal numbers. Each has an arrow to a question mark labelled what follows.
Typed examples, for illustration.
3. What does a spectrogram show about an audio signal?Warm-up
A heat map image of a one second audio clip with time along the bottom from 0 s to 1 s, three horizontal bands of brightness that step upward, a question mark beside the vertical axis and a question mark beside a column of brightness colours.
Computed with numpy from a synthetic clip of three steady tones. The axes and colours are left unnamed.
Check: The Problem0/3
1. What problem does a neural audio codec solve for LLM-style audio models like MusicGen, Moshi, and Sesame CSM?Define
Three boxes in a row: an audio waveform, a dashed highlighted box containing a question mark, and an LLM-style model such as MusicGen or Moshi, joined by arrows.
Schematic. The dashed box is left open.
2. Why do pure reconstruction codecs produce blurry speech when you generate from text?Explain
A pipeline of text, an LM, a small grid of codec tokens, a decoder and speech, with text saying the generated speech sounds blurry and a question mark asking why.
Schematic. The token grid is drawn small and not to scale.
3. A team trains a TTS LM on EnCodec tokens. Reconstruction is excellent, but speech generated from text is blurry. Which ingredient is missing?Analyze
A pipeline of text, an LM trained on EnCodec tokens, an EnCodec decoder and speech. Two text lines say reconstruction is excellent and generated speech is blurry. A dashed box labelled missing ingredient has a question mark.
Schematic of the situation in the question.

The Concept

Four codec landscape: EnCodec, DAC, SNAC (multi-scale), Mimi (semantic+acoustic)

The core trick: Residual Vector Quantization (RVQ)

One giant codebook would need millions of codes to sound good, so modern audio codecs skip that entirely and use RVQ instead: a cascade of small codebooks. The first codebook quantizes the encoder output, the second quantizes what's left over (the residual), and so on down the cascade. Each codebook holds 1024 codes, so 8 codebooks give you an effective vocabulary of 1024^8 = 10^24.

At inference time, the decoder just sums every chosen code per frame to reconstruct the audio.

The four codecs that matter in 2026

EnCodec (Meta, 2022). The baseline: an encoder-decoder over the waveform with an RVQ bottleneck. Runs at 24 kHz, supports up to 32 codebooks, and defaults to 4 codebooks at 1.5 kbps. Architecture is 1D conv + transformer + 1D conv. MusicGen is built on it.

DAC (Descript, 2023). RVQ with L2-normalized codebooks, periodic activation functions, and improved losses. It has the highest reconstruction fidelity of any open codec: with 12 codebooks it's sometimes indistinguishable from the original speech. Runs at 44.1 kHz full-band.

SNAC (Hubert Siuzdak, 2024). Multi-scale RVQ, where the coarse codebooks operate at a lower frame rate than the fine ones. That models audio hierarchically: a coarse "sketch" at roughly 12 Hz plus detail at 50 Hz. Orpheus-3B uses it because that hierarchical structure maps well onto LM-based generation.

Mimi (Kyutai, 2024). The most consequential of the four for 2026. 12.5 Hz frame rate (extremely low), 8 codebooks at 4.4 kbps. Codebook 0 is distilled from WavLM, trained to predict WavLM's speech-content features, while codebooks 1-7 are acoustic residuals. This split powers Moshi (Lesson 15) and Sesame CSM.

Frame rates matter for language modeling

Lower frame rate = shorter sequence = faster LM.

CodecFrame rate1 s = N framesGood for
EnCodec-24k75 Hz75music, general audio
DAC-44.1k86 Hz86high-fidelity music
SNAC-24k (coarse)~12 Hz12AR-LM efficient
Mimi12.5 Hz12.5streaming speech

At 12.5 Hz, a 10-second utterance comes out to only 125 codec frames, a length a transformer predicts easily.

Semantic vs acoustic tokens

frame_t → [semantic_token_t, acoustic_token_0_t, acoustic_token_1_t, ..., acoustic_token_6_t]
  • Semantic token (codebook 0 in Mimi). Encodes what was said: phonemes, words, content. Distilled from WavLM via an auxiliary prediction loss.
  • Acoustic tokens (codebooks 1-7). Encode timbre, speaker identity, prosody, background noise, fine detail.

An AR LM predicts the semantic token first (conditioned on text), then predicts acoustic tokens (conditioned on semantic + speaker reference). This factorization is why modern TTS can zero-shot-clone voices: the semantic model handles content; the acoustic model handles timbre.

2026 reconstruction quality (bits per sec, lower bitrate is better)

PESQ and ViSQOL are automated scores (roughly 1-5) that estimate how a human listener would rate reconstructed audio, without needing an actual listening panel.

CodecBitratePESQViSQOL
Opus-20kbps20 kbps4.04.3
EnCodec-6kbps6 kbps3.23.8
DAC-6kbps6 kbps3.54.0
SNAC-3kbps3 kbps3.33.8
Mimi-4.4kbps4.4 kbps3.13.7

Traditional codecs like Opus still win per bit on perceptual quality. Neural codecs win somewhere else entirely: discrete tokens (which Opus never produces) and generative-model quality (what an LM can actually do once it has those tokens).

Check: The Concept0/16
1. How does Residual Vector Quantization (RVQ) work?Define
A row of five boxes: audio waveform, encoder, a highlighted box labelled RVQ, decoder, audio waveform, joined by arrows. A question mark under the RVQ box asks how it works.
Schematic of an encoder-decoder codec with a quantizer in the middle.
2. What does a codec's frame rate measure?Define
A one second waveform with an arrow into a box labelled EnCodec-24k, frame rate 75 Hz, and an arrow out to a question mark asking what the 75 counts.
Schematic. Waveform is typed, not recorded.
3. What makes Mimi's codebook 0 different from its other seven codebooks?Define
Speech goes into a Mimi encoder, which outputs one frame drawn as a column of 8 cells for codebooks 0 to 7. Codebook 0 is outlined in orange and a question mark asks how it differs from codebooks 1 to 7.
Schematic of one frame of Mimi tokens.
4. What do the acoustic codebooks (codebooks 1-7 in Mimi) encode?Define
A grid of 8 rows labelled cb 0 to cb 7 and 6 columns for six frames. Row 0 is dim, rows 1 to 7 are outlined in orange with a bracket and a question mark asking what they encode.
Schematic. Six frames drawn for illustration.
5. What are PESQ and ViSQOL used for?Define
An original waveform goes into a codec box and a slightly different reconstructed waveform comes out. An arrow from the reconstruction points to a box labelled PESQ / ViSQOL with a question mark beside it.
Schematic. Both waveforms are typed curves.
6. What is EnCodec?Define
A title EnCodec above three boxes: 1D conv, transformer, 1D conv, with text saying it is an encoder-decoder over the raw waveform with a quantizer bottleneck, running at 24 kHz with up to 32 codebooks. A question mark asks who built it and what it is known for.
Architecture strip as the lesson lists it.
7. What is Mimi?Define
A speech waveform with an arrow to a grid of 5 columns and 8 rows of identical cells, then an arrow to a question mark. Text says 8 tokens per frame, 5 frames drawn, and asks what this codec is.
Schematic. Five frames drawn for illustration.
8. What makes DAC (Descript Audio Codec) notable among open codecs?Define
44.1 kHz audio goes into a box labelled DAC, Descript 2023, with a question mark on the output. Below, a bar spans 0 Hz to 22,050 Hz, the frequencies a 44.1 kHz signal can contain. A text asks what makes the codec notable.
Schematic. 22,050 Hz is half the sampling rate.
9. Why does each RVQ codebook quantize the residual left by the previous one instead of the original signal again?Explain
A frame x goes into codebook 1, which returns c1. A dashed path leads through a question mark to codebook 2, which returns c2. Text asks what codebook 2 should be given.
Schematic. The question mark is the input being asked about.
10. Why does a lower codec frame rate make LM generation cheaper?Explain
Two rows. Each takes a 10 second clip into a codec and then an LM, ending in a question mark labelled cost. The first codec is Mimi at 12.5 Hz, the second is EnCodec-24k at 75 Hz.
Schematic. Frame rates are from the lesson's table.
11. Why does Orpheus-3B use SNAC?Explain
A pipeline of five boxes joined by arrows: text, Orpheus-3B, tokens, a highlighted SNAC decoder, and audio. A question mark under the SNAC box asks why this codec.
Schematic.
12. In what order does an AR LM generate tokens in the semantic-acoustic factorization?Explain
A text prompt goes into an AR LM, which fills a column of 8 cells labelled cb 0 to cb 7. Each cell has a label reading step question mark. Text asks in what order the LM fills them.
Schematic.
13. Using the reconstruction-quality table, which codec has the highest PESQ and ViSQOL scores, despite not being a neural codec?Apply
A table of five codecs with their bitrates and two score columns, PESQ and ViSQOL, whose cells all show question marks.
Scores deliberately hidden; the lesson's table has them.
14. Using the reconstruction-quality table, which statement is true?Apply
A bitrate axis from 0 to 20 kbps with five labelled points: SNAC-3kbps at 3, Mimi-4.4kbps at 4.4, EnCodec-6kbps and DAC-6kbps at 6, Opus-20kbps at 20. Text notes the PESQ of each is to be read from the lesson's table.
Bitrates from the lesson's table. Scores deliberately hidden.
15. Each RVQ codebook holds 1024 codes. Roughly how many distinct code combinations can 2 codebooks express?Apply
Two columns, codebook 1 and codebook 2, each listing code 0, code 1, code 2, an ellipsis and code 1023. Text says one frame picks one code from each, and a question mark asks how many distinct pairs there can be.
Schematic.
16. You need a TTS system that clones a new speaker's voice zero-shot from a short reference clip. Which design fits?Design
Text to say and a short reference clip of a new speaker both feed a dashed box labelled TTS system, design question, whose output is new speech. A note says the speaker was never seen in training.
Schematic. Waveforms are typed.

Build It

Step 1: encode with EnCodec

python
from encodec import EncodecModel
import torch
 
model = EncodecModel.encodec_model_24khz()
model.set_target_bandwidth(6.0)  # kbps
 
wav = torch.randn(1, 1, 24000)
with torch.no_grad():
    encoded = model.encode(wav)
codes, scale = encoded[0]
# codes: (1, n_codebooks, n_frames), dtype=int64

n_codebooks=8 at 6 kbps. Each code is 0-1023 (10-bit).

Step 2: decode and measure reconstruction

python
with torch.no_grad():
    wav_recon = model.decode([(codes, scale)])
 
from torchaudio.functional import compute_deltas
import torch.nn.functional as F
 
mse = F.mse_loss(wav_recon[:, :, :wav.shape[-1]], wav).item()

Step 3: the semantic-acoustic split (Mimi-style)

python
from moshi.models import loaders
mimi = loaders.get_mimi()
 
with torch.no_grad():
    codes = mimi.encode(wav)  # shape (1, 8, [email protected])
 
semantic = codes[:, 0]
acoustic = codes[:, 1:]

Semantic codebook 0 is WavLM-aligned. You can train a text-to-semantic transformer with a much smaller vocabulary than going direct-to-audio, then let a separate acoustic-to-waveform decoder condition on a speaker reference.

Step 4: why AR LM over codec tokens works

For a 10 s speech clip at Mimi's 12.5 Hz × 8 codebooks:

N_tokens = 10 * 12.5 * 8 = 1000 tokens

1000 tokens is a trivial context for a transformer. A 256M-parameter transformer can generate 10 seconds of speech in milliseconds on a modern GPU.

Check: Build It0/4
1. In the Build It EnCodec example at 6 kbps, what does each entry of `codes` hold?Apply
Three lines of the lesson's EnCodec code with the codes line highlighted, then a grid of 8 codebook rows by 9 visible frame columns with one cell marked with a question mark, and a note of 75 frames for 1 second and 8 codebook rows.
Code copied from the lesson. 75 frames = 1 s at 75 Hz.
2. In Step 3, `mimi.encode(wav)` returns codes of shape (1, 8, frames). What is the shape of `acoustic = codes[:, 1:]`?Apply
The lesson's code lines for mimi.encode and the slice codes[:, 1:], above a grid of 8 codebook rows numbered 0 to 7 by 9 visible frame columns, an axis note, and a question mark asking for the shape of acoustic.
Code copied from the lesson. Nine frames drawn.
3. A 10-second clip is encoded with EnCodec-24k at 75 Hz using 8 codebooks (6 kbps). How many tokens does an LM over it see?Apply
A 10 second waveform, then a box EnCodec-24k at 75 Hz with 8 codebooks at 6 kbps, an arrow to an LM box and on to a question mark labelled tokens.
Schematic. Waveform is typed.
4. A 10-second speech clip is encoded with Mimi (12.5 Hz, 8 codebooks). How many tokens does the LM see?Apply
A 10 second speech waveform goes into a box Mimi with 12.5 Hz and 8 codebooks, then into an LM box, with a question mark and text asking how many tokens the LM sees.
Schematic. Waveform is typed.

Use It

Map problem → codec:

TaskCodec
General music generationEnCodec-24k
Highest-fidelity reconstructionDAC-44.1k
AR LM over speech (TTS)SNAC or Mimi
Streaming full-duplex speechMimi (12.5 Hz)
Sound-effect library with textEnCodec + T5 condition
Fine-grained audio editingDAC + inpainting

Rule of thumb: if you're building a generative model, start with Mimi or SNAC. If you're building a compression pipeline, use Opus.

Check: Use It0/3
1. Per the Use It rule of thumb, when should you reach for Opus instead of a neural codec like Mimi or SNAC?Analyze
A speech or music task box with two arrows: one to Mimi or SNAC, labelled neural codecs, and one to Opus, labelled traditional codec. A question mark sits beside each branch, and text asks when each fits.
Schematic.
2. You are building a full-duplex voice assistant that must stream speech in real time. Which codec fits best?Design
Two lanes, user and assistant, with overlapping waveforms to show both streams running at the same time, and a dashed box labelled audio codec, which one, with a question mark.
Schematic. Waveforms are typed.
3. You must support fine-grained audio editing, such as inpainting a segment, with minimal audible loss. Which codec fits?Design
A waveform with a middle segment outlined in red dashes and labelled segment to inpaint, a dashed box labelled codec, which one, with a question mark, and a note that the edit must leave minimal audible loss.
Schematic. Waveform is typed.

Pitfalls

  • Too many codebooks. Adding codebooks increases fidelity linearly but LM sequence length linearly too. Stop at 8-12.
  • Frame-rate mismatch. Training LM on 12.5 Hz Mimi then fine-tuning on 50 Hz EnCodec fails silently.
  • Assuming all codebooks equal. In Mimi, codebook 0 carries content; losing it destroys intelligibility. Losing codebook 7 is barely noticeable.
  • Using reconstruction quality as the only metric. A codec can have great reconstruction but be useless for LM-based generation if the semantic structure is bad.
Check: Pitfalls0/6
1. Why does corrupting Mimi's codebook 0 destroy intelligibility while corrupting codebook 7 barely matters?Explain
Two experiments labelled A and B. Each shows a grid of 8 codebook rows by 4 frames with one row outlined in red dashes: row 0 in A and row 7 in B, replaced by random integers. An arrow labelled decode leads to a question mark asking about the decoded clip.
Schematic. Four frames drawn for illustration.
2. What do the 'too many codebooks' and 'frame-rate mismatch' pitfalls warn about?Explain
Two panels. Pitfall 1 shows chips for 4, 8, 12 and 32 codebooks with a question mark. Pitfall 2 shows an LM trained on Mimi at 12.5 Hz and then fine-tuned on a codec with another frame rate, with a question mark asking what each pitfall warns about.
Schematic.
3. Why is reconstruction quality alone a poor metric when choosing a codec for generative modeling?Explain
A candidate codec box with an arrow to a highlighted reconstruction score box and a dashed link through a question mark to a dashed box labelled works for LM-based generation. Text asks whether the score is enough to pick a codec.
Schematic.
4. After corrupting one Mimi codebook and decoding, the clip sounds like static in a voice's tone and the words are gone. Which codebook was corrupted?Analyze
A grid of 8 codebook rows labelled cb 0 to cb 7 by 6 frames, with a question mark asking which row was corrupted, and a box below describing the decoded clip as static in a voice's tone with the words gone.
Schematic. Six frames drawn.
5. An LM trained on Mimi tokens is fine-tuned on tokens from a codec with a different frame rate. No error is raised but the output is wrong. What is the likely cause?Analyze
Two rows of token cells across the same span. The first row, Mimi at 12.5 Hz, has wide cells. The second, another codec with a different frame rate, has narrower, more numerous cells. Text says no error is raised and the output is wrong, and a question mark asks for the likely cause.
Schematic. Cell counts are illustrative, not the actual rates.
6. A team raises a speech codec from 8 to 32 codebooks hoping the LM output improves. What does the lesson's reasoning predict?Analyze
Two rows with the same speech input and frame rate. The first uses a codec with 8 codebooks and the second 32 codebooks. Each feeds an LM box and ends in a question mark. Text asks what happens on the LM's side.
Schematic.

Ship It

Save as outputs/skill-codec-picker.md. Pick a codec for a given generative or compression task.

Author's Note

If you only do one of the exercises below, do the third one. Reading that codebook 0 carries meaning and codebook 7 carries fine acoustic detail is one kind of understanding. Listening to a clip with codebook 0 replaced by noise, then a clip with codebook 7 replaced by noise, is a different kind entirely. The first will sound like static wearing a voice's clothes. The second will sound almost normal. That gap is the whole argument for splitting semantic tokens from acoustic ones, and no PESQ or ViSQOL number will make the point as fast as your own ears will.

Exercises

  1. Easy. Run code/main.py. It implements a toy scalar + residual quantizer and measures reconstruction error as you add codebooks.
  2. Medium. Install encodec and compare 1, 4, 8, 32 codebooks on a held-out speech clip. Plot PESQ or MSE vs bitrate.
  3. Hard. Load Mimi. Encode a clip. Replace codebook 0 with random integers; decode. Then replace codebook 7 similarly. Compare the two corruptions: codebook 0 corruption should destroy intelligibility, while codebook 7 corruption should barely change anything.

Key Terms

TermWhat people sayWhat it actually means
RVQResidual quantizationCascade of small codebooks; each quantizes the previous residual.
Frame rateCodec speedHow many token-frames per second. Lower = faster LM.
Semantic codebookCodebook 0 (Mimi)Codebook distilled from SSL features; encodes content.
Acoustic codebooksEverything elseTimbre, prosody, noise, fine detail.
PESQ / ViSQOLPerceptual qualityObjective metrics correlating with MOS.
EnCodecMeta codecThe RVQ baseline; used by MusicGen.
MimiKyutai codec12.5 Hz frame rate; semantic-acoustic split; powers Moshi.

Further Reading

Code

Ships With