Views
No views yet
transformers.models.moss_audio_tokenizer module. Load it with trust_remote_code=True when needed.ch=1 means mono audio, and ch=2 means stereo audio.| Model | Params (M) | Sample rate | Ch. | bps | Nvq | Speech: SIM ↑ (EN/ZH) | Speech: STOI ↑ (EN/ZH) | Speech: PESQ-NB ↑ (EN/ZH) | Speech: PESQ-WB ↑ (EN/ZH) | Audio/Music: Mel-Loss ↓ | Audio/Music: STFT-Dist. ↓ |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Mimi VAE | 28 | 24k | 1 | -- | -- | 0.75 / 0.54 | 0.91 / 0.83 | 2.92 / 2.20 | 2.30 / 1.73 | 1.35 / 1.31 | 2.70 / 2.59 |
| DAC | 77 | 44.1k | 1 | 861 | 1 | 0.30 / 0.20 | 0.76 / 0.68 | 1.55 / 1.36 | 1.24 / 1.15 | 1.25 / 1.18 | 2.71 / 2.54 |
| SpeechTokenizer | 120 | 16k | 1 | 1000 | 2 | 0.36 / 0.25 | 0.77 / 0.68 | 1.59 / 1.38 | 1.25 / 1.17 | -- / -- | -- / -- |
| Mimi | 96 | 24k | 1 | 1100 | 8 | 0.74 / 0.59 | 0.91 / 0.85 | 2.80 / 2.24 | 2.25 / 1.78 | 1.24 / 1.19 | 2.62 / 2.49 |
| MOSS-Audio-Tokenizer-Nano | 22 | 48k | 2 | 750 | 6 | 0.64 / 0.61 | 0.90 / 0.85 | 2.65 / 2.28 | 2.11 / 1.87 | 1.04 / 1.01 | 2.42 / 2.27 |
| MOSS-Audio-Tokenizer-Nano | 22 | 48k | 2 | 1000 | 8 | 0.75 / 0.69 | 0.92 / 0.87 | 2.92 / 2.48 | 2.36 / 2.04 | 1.00 / 0.97 | 2.37 / 2.22 |
| EnCodec | 19 | 48k | 2 | 1500 | 1 | 0.35 / 0.30 | 0.76 / 0.75 | 1.54 / 1.60 | 1.25 / 1.32 | 1.25 / 1.05 | 2.73 / 2.30 |
| SpeechTokenizer | 120 | 16k | 1 | 1500 | 3 | 0.52 / 0.38 | 0.84 / 0.75 | 2.00 / 1.60 | 1.57 / 1.33 | -- / -- | -- / -- |
| Mimi | 96 | 24k | 1 | 1512.5 | 11 | 0.82 / 0.67 | 0.92 / 0.88 | 3.10 / 2.50 | 2.54 / 2.00 | 1.19 / 1.14 | 2.55 / 2.42 |
| DAC | 77 | 44.1k | 1 | 1723 | 2 | 0.57 / 0.47 | 0.86 / 0.80 | 2.21 / 1.85 | 1.74 / 1.49 | 1.03 / 0.99 | 2.43 / 2.26 |
| SpeechTokenizer | 120 | 16k | 1 | 2000 | 4 | 0.66 / 0.50 | 0.88 / 0.80 | 2.38 / 1.79 | 1.92 / 1.49 | -- / -- | -- / -- |
| Mimi | 96 | 24k | 1 | 2062.5 | 15 | 0.87 / 0.73 | 0.94 / 0.90 | 3.36 / 2.76 | 2.81 / 2.22 | 1.14 / 1.09 | 2.49 / 2.36 |
| MOSS-Audio-Tokenizer-Nano | 22 | 48k | 2 | 1500 | 12 | 0.84 / 0.77 | 0.94 / 0.90 | 3.25 / 2.77 | 2.71 / 2.31 | 0.95 / 0.91 | 2.31 / 2.14 |
| MOSS-Audio-Tokenizer-Nano | 22 | 48k | 2 | 2000 | 16 | 0.88 / 0.81 | 0.95 / 0.91 | 3.40 / 2.93 | 2.89 / 2.47 | 0.93 / 0.89 | 2.28 / 2.11 |
1import torchaudio
2from transformers import AutoModel
3
4repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer-Nano"
5model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
6
7wav, sr = torchaudio.load("demo/demo_gt.wav")
8if sr != model.sampling_rate:
9 wav = torchaudio.functional.resample(wav, sr, model.sampling_rate)
10
11# The public waveform interface expects stereo audio.
12if wav.shape[0] == 1:
13 wav = wav.repeat(model.config.number_channels, 1)
14else:
15 wav = wav[: model.config.number_channels]
16
17wav = wav.unsqueeze(0)
18enc = model.encode(wav, return_dict=True)
19print(f"enc.audio_codes.shape: {enc.audio_codes.shape}")
20
21dec = model.decode(enc.audio_codes, return_dict=True)
22print(f"dec.audio.shape: {dec.audio.shape}")
23
24wav = dec.audio.squeeze(0)
25torchaudio.save("demo/demo_rec.wav", wav, sample_rate=model.sampling_rate)
26
27# Decode with the first 8 codebooks, roughly 1 kbps.
28dec_rvq8 = model.decode(enc.audio_codes[:8], return_dict=True)
29wav_rvq8 = dec_rvq8.audio.squeeze(0)
30torchaudio.save("demo/demo_rec_rvq8.wav", wav_rvq8, sample_rate=model.sampling_rate)config.attention_implementation controls whether Transformer layers prefer sdpa or flash_attention_2.
config.compute_dtype controls the non-quantizer autocast dtype and supports fp32, bf16, and fp16.1model.set_attention_implementation("flash_attention_2")
2model.set_compute_dtype("fp16")MossAudioTokenizerModel.encode, decode, batch_encode, and batch_decode all support streaming through a chunk_duration argument.chunk_duration is expressed in seconds.chunk_duration * MossAudioTokenizerConfig.sampling_rate must be divisible by MossAudioTokenizerConfig.downsample_rate.(2, T) or batched stereo inputs shaped (B, 2, T).1import torch
2from transformers import AutoModel
3
4repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer-Nano"
5model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
6audio = torch.randn(2, 48000 * 6) # dummy stereo waveform
7
8# 6.0s @ 48kHz = 288000 samples, divisible by downsample_rate=3840
9enc = model.encode(audio.unsqueeze(0), return_dict=True, chunk_duration=0.08)
10dec = model.decode(enc.audio_codes, return_dict=True, chunk_duration=0.08)
11
12batch_enc = model.batch_encode([audio, audio[:, : 48000 * 3]], chunk_duration=0.08)
13codes_list = [
14 batch_enc.audio_codes[:, i, : batch_enc.audio_codes_lengths[i]]
15 for i in range(batch_enc.audio_codes.shape[1])
16]
17batch_dec = model.batch_decode(codes_list, chunk_duration=0.08)batch_decode(..., streaming=True, ...).max_batch_size=.... If it is omitted, the first batch size reserves the fixed-slot decoder budget for that public stream.finalize_indices means "decode these rows one last time, then evict them". The indices are interpreted against the pre-call logical order.reset_stream=True discards the hidden public streaming state and starts a fresh stream.max_batch_size1import torch
2from transformers import AutoModel
3
4repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer-Nano"
5model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
6num_quantizers = model.config.quantizer_kwargs["num_quantizers"]
7codebook_size = model.config.quantizer_kwargs["codebook_size"]
8
9codes_a0 = torch.randint(0, codebook_size, (num_quantizers, 2))
10codes_b0 = torch.randint(0, codebook_size, (num_quantizers, 3))
11codes_a1 = torch.randint(0, codebook_size, (num_quantizers, 2))
12codes_b1 = torch.randint(0, codebook_size, (num_quantizers, 2))
13codes_c0 = torch.randint(0, codebook_size, (num_quantizers, 1))
14codes_a2 = torch.randint(0, codebook_size, (num_quantizers, 1))
15codes_b2 = torch.randint(0, codebook_size, (num_quantizers, 2))
16codes_c1 = torch.randint(0, codebook_size, (num_quantizers, 2))
17codes_b3 = torch.randint(0, codebook_size, (num_quantizers, 1))
18codes_c2 = torch.randint(0, codebook_size, (num_quantizers, 1))
19
20# First call reserves 3 fixed decoder slots for A and B.
21out_ab0 = model.batch_decode(
22 [codes_a0, codes_b0],
23 streaming=True,
24 max_batch_size=3,
25 reset_stream=True,
26)
27
28# Same logical rows continue in order; C is a tail append.
29out_abc1 = model.batch_decode(
30 [codes_a1, codes_b1, codes_c0],
31 streaming=True,
32)
33
34# Finalize A against the pre-call logical order. A still decodes in this call,
35# then is evicted immediately afterward.
36out_abc2 = model.batch_decode(
37 [codes_a2, codes_b2, codes_c1],
38 streaming=True,
39 finalize_indices=[0],
40)
41
42# The next call can shrink to the surviving logical rows only.
43out_bc3 = model.batch_decode(
44 [codes_b3, codes_c2],
45 streaming=True,
46)configuration_moss_audio_tokenizer.pymodeling_moss_audio_tokenizer.py__init__.pyconfig.json1@misc{gong2026mossttstechnicalreport,
2 title={MOSS-TTS Technical Report},
3 author={Yitian Gong and Botian Jiang and Yiwei Zhao and Yucheng Yuan and Kuangwei Chen and Yaozhou Jiang and Cheng Chang and Dong Hong and Mingshu Chen and Ruixiao Li and Yiyang Zhang and Yang Gao and Hanfu Chen and Ke Chen and Songlin Wang and Xiaogui Yang and Yuqian Zhang and Kexin Huang and ZhengYuan Lin and Kang Yu and Ziqi Chen and Jin Wang and Zhaoye Fei and Qinyuan Cheng and Shimin Li and Xipeng Qiu},
4 year={2026},
5 eprint={2603.18090},
6 archivePrefix={arXiv},
7 primaryClass={cs.SD},
8 url={https://arxiv.org/abs/2603.18090}
9}1@misc{gong2026mossaudiotokenizerscalingaudiotokenizers,
2 title={MOSS-Audio-Tokenizer: Scaling Audio Tokenizers for Future Audio Foundation Models},
3 author={Yitian Gong and Kuangwei Chen and Zhaoye Fei and Xiaogui Yang and Ke Chen and Yang Wang and Kexin Huang and Mingshu Chen and Ruixiao Li and Qingyuan Cheng and Shimin Li and Xipeng Qiu},
4 year={2026},
5 eprint={2602.10934},
6 archivePrefix={arXiv},
7 primaryClass={cs.SD},
8 url={https://arxiv.org/abs/2602.10934}
9}