Skip to content

Audio, speech, music, and audio-language systems · Streaming speech and multimodal audio systems · AUD067 · Model

Mimi streaming semantic–acoustic codec

A streaming neural audio codec combining perceptual reconstruction with semantic representation distillation. It supplies low-frame-rate acoustic tokens used by Moshi while retaining more content-related information in…

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

A streaming neural audio codec combining perceptual reconstruction with semantic representation distillation. It supplies low-frame-rate acoustic tokens used by Moshi while retaining more content-related information in a designated codebook. It is a compression/tokenization model, not the dialogue language model that predicts those tokens.

Question / hypotheses

Can a causal codec retain useful speech semantics and sound quality at a small token rate and bounded buffering delay? Evaluate rate, reconstruction quality, and downstream information preservation; there is no built-in statistical null hypothesis.

Architecture / computational structure

A streaming convolutional encoder/decoder augmented with Transformer processing surrounds residual quantization. The first semantic-oriented codebook is trained using a speech representation target, with remaining acoustic information carried by the quantized representation. Cached causal state is part of streaming inference and must be reset between unrelated recordings.

Assumptions

The released operating design uses 24 kHz audio and 12.5 token frames per second. Preserve channel, waveform normalization, active-book count, and streaming state. A semantic distillation target does not make tokens a transcript, and perceptual quality does not guarantee exact preservation of every measurable acoustic feature.

Formula / computational definition

A core design combines adversarial/feature-matching acoustic training with semantic distillation: L=λaLadv+λfLFM+λsLsemantic\mathcal L=\lambda_a\mathcal L_{adv}+\lambda_f\mathcal L_{FM}+\lambda_s\mathcal L_{semantic}, with the implementation’s quantization handling. Nominal token payload is R=fQlog⁡2KR=fQ\log_2K, where ff is frames/s, QQ active books, and KK codes/book.

Parameters and notation

Learned parameters include convolutional/Transformer encoder and decoder weights, quantizer embeddings, and training discriminators/projections. Hyperparameters include rate/stride, book count and size, causal context, distillation weighting, and chunk size. Eight 2048-entry books at 12.5 Hz imply 1100 bits/s of raw code indices before framing or transport overhead.

Fitting, fine-tuning, and adaptation

Codec adaptation updates encoder, quantization, decoder, and loss-balancing components using matched authorized audio. Keep the semantic teacher fixed unless deliberately redesigning distillation. Freeze Mimi when training a downstream token language model; fine-tuning the codec changes token meanings and can invalidate previously trained token predictors.

How to use and calibrate

Measure reconstruction listening quality, content retention, speaker/channel artifacts, rate–quality tradeoffs, codec delay, and encode/decode throughput. Compare chunked and whole-recording behavior and verify identical handling at boundaries. A low token rate reduces language-model sequence length but does not by itself establish superior complete-system latency.

Example application

Compare reconstruction and downstream recognition at two supported active-codebook settings, keeping waveform preprocessing, clips, and measurement conditions fixed.

Interpretation / pitfalls

Watch out

Python: official Kyutai code and the published Hugging Face model route support this codec family. R: reticulate to the same model/frontend. The numerical example verifies payload/frame arithmetic only; it does not encode speech, exercise streaming caches, or reproduce adversarial/distillation training.

Python and R code examples (dependencies/validation)

Load the shared audio helper setup. These are deterministic component illustrations, not full-model implementations. Python/NumPy: executed successfully. R/base R: not executed because Rscript was unavailable. No model weights were downloaded.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — These are deterministic component illustrations, not full-model implementations.

Shared setup for this chapter
"""Shared helpers for educational audio objective/architecture components.
This file and all AUD snippets use NumPy only. They do not load trained networks.
"""
import itertools
import numpy as np

def ce(p, y):
    p=np.asarray(p, float); y=np.asarray(y, int)
    return float(-np.log(np.clip(p[np.arange(len(y)),y],1e-12,1)).mean())

def bce(p,y):
    p=np.clip(np.asarray(p,float),1e-12,1-1e-12); y=np.asarray(y,float)
    return float(-(y*np.log(p)+(1-y)*np.log(1-p)).mean())

def mse(a,b): return float(np.mean((np.asarray(a)-np.asarray(b))**2))
def l1(a,b): return float(np.mean(np.abs(np.asarray(a)-np.asarray(b))))
def softmax(a):
    a=np.asarray(a,float); a=a-a.max(axis=-1,keepdims=True)
    z=np.exp(a); return z/z.sum(axis=-1,keepdims=True)
def contrast(a,b,tau=.2):
    a=np.asarray(a,float); b=np.asarray(b,float)
    a=a/np.linalg.norm(a,axis=1,keepdims=True); b=b/np.linalg.norm(b,axis=1,keepdims=True)
    s=a@b.T/tau; y=np.arange(len(a))
    return (ce(softmax(s),y)+ce(softmax(s.T),y))/2

def collapse(path):
    merged=[v for i,v in enumerate(path) if i==0 or v!=path[i-1]]
    return tuple(v for v in merged if v!=0)
def ctc_prob(p,target):
    p=np.asarray(p,float)
    return sum(np.prod([p[t,j] for t,j in enumerate(path)])
               for path in itertools.product(range(p.shape[1]), repeat=len(p))
               if collapse(path)==tuple(target))
def pit_mse(estimate,reference):
    estimate=np.asarray(estimate); reference=np.asarray(reference)
    return min(mse(estimate,reference[list(p)]) for p in itertools.permutations(range(len(reference))))
def cosine(a,b):
    a=np.asarray(a,float); b=np.asarray(b,float)
    return float(a@b/(np.linalg.norm(a)*np.linalg.norm(b)))

# Shared deterministic fixtures; token labels are zero-based in Python.
P=np.array([[.1,.7,.2],[.2,.2,.6],[.6,.2,.2]])
y=np.array([1,2,0])
A=np.array([[1.,0.],[0.,1.],[1.,1.]])
B=np.array([[.9,.1],[.1,.9],[.8,1.]])
s=np.sin(np.arange(32)*.4)
x=s+.1*np.cos(np.arange(32)*.9)
# AUD067: educational component
frame_rate=12.5; active_books=8; codebook_size=2048
result={"nominal_bits_per_second":frame_rate*active_books*np.log2(codebook_size),"frame_ms":1000/frame_rate}
print(result)
R

Component demo, not a trained model — These are deterministic component illustrations, not full-model implementations.

# AUD067: requires shared R setup
frame_rate <- 12.5; active_books <- 8; codebook_size <- 2048
result <- c(nominal_bits_per_second=frame_rate*active_books*log2(codebook_size),frame_ms=1000/frame_rate)
print(result)

Sources

From the CodeSplash reference, entry AUD067.