Skip to content

feat: integrate M5-TTS (ASLP-lab) as a native GGUF TTS architecture - #5

Merged
lovemefan merged 4 commits into
RapidAI:mainfrom
yoletPig:feat/m5-tts
Dec 3, 2026
Merged

lovemefan merged 4 commits into
RapidAI:mainfrom
yoletPig:feat/m5-tts

Conversation

@yoletPig

Copy link
Copy Markdown
Contributor

M5-TTS Integration for RapidSpeech.cpp

Integrate ASLP-lab/M5-TTS (50M-param multilingual TTS with multi-token prediction + Qwen3-TTS 12Hz codec) as a native GGUF-based TTS architecture.

What's included

File Description
scripts/convert_m5tts_to_gguf.py Converts M5-TTS checkpoint + Qwen 12Hz codec to a single GGUF (LM + codec encoder + decoder + tokenizer + RoPE tables)
rapidspeech/src/arch/m5tts.h Architecture header: HParams, LlamaBlock, MimiBlock, Conv1D, CodecDecoder/EncoderWeights, BPETokenizer, State, Model
rapidspeech/src/arch/m5tts.cpp Loading, llama3 byte-level BPE, TN integration, orchestration (Encode/Decode), arch registration
rapidspeech/src/arch/m5tts_lm.cpp LM graphs: backbone prefill/step (llama-30M), MTP depth decoder (llama-20M), next-frame embedding
rapidspeech/src/arch/m5tts_codec.cpp Codec graphs: encoder (SEANet + Mimi transformer + RVQ argmin) and streaming decoder (RVQ → causal conv → 8L sliding-window transformer → conv upsampler)
rapidspeech/src/arch/m5tts_graph.h Shared graph-building helpers (rmsnorm, rope_neox, llama_block, conv1d_full/streaming, snake_beta, flash-attn with KV cache)

Pipeline

text (+ref audio) → wetext TN → llama3 BPE
  → backbone (8L llama-30M) prefill [text ‖ codec-encoded prompt]
  → frame loop: backbone step → MTP depth decoder (5L llama-20M) × 16 codebooks
  → Qwen3-TTS 12Hz codec decoder → 24 kHz PCM

Usage

# Convert (requires M5-TTS checkpoint + Audio-Tokenizer from HuggingFace)
python scripts/convert_m5tts_to_gguf.py \
  --m5-dir ~/models/M5-TTS \
  --codec-dir ~/models/M5-TTS-Audio-Tokenizer \
  --output m5tts-f16.gguf --out-type f16

# TTS with voice cloning
./build/rs-tts-offline -m m5tts-f16.gguf \
  --ref reference.wav --ref-text "参考转写" \
  -t "目标文本" --lang Chinese --gpu false -o output.wav

Verification

  1. Build: cmake -B build && cmake --build build --parallel $(nproc)
  2. Convert the model (see above)
  3. Run TTS: ./build/rs-tts-offline -m m5tts-f16.gguf --ref ref.wav --ref-text "..." -t "你好" -o out.wav
  4. Verify with x-asr: ./build/rs-asr-offline -m xasr-q8_0.gguf -w out.wav

Benchmark (CPU 8-thread, RTX 4060 Ti WSL2)

Model Size RTF ↓ ASR round-trip
m5tts-f16 1.07 GB 1.46 你好,欢迎使用我们的语音合成模型。 ✓
m5tts-q8_0 732 MB 1.02 Mixed quality
m5tts-q4_k_m 638 MB 1.44 Degraded

Known limitations

  • The codec encoder uses F16 im2col (ggml limitation); this introduces ~0.1% quantization noise in the reference audio encoding, causing the RVQ codes to occasionally flip and degrading voice-cloning prompt quality.
  • The LM backbone sampling uses the same top-k/temperature parameters as the ONNX reference (topk=10, temperature=0.9).
  • English/Chinese voice cloning verified; other M5-TTS languages untested.

Implement M5-TTS architecture in rapidspeech, including model loading,
llama3 byte-level BPE tokenization, state management, LM frame generation
orchestration, and codec graph implementations. Register the new sources
in CMakeLists.txt.
Stray stderr debug logging left over from development was removed from the m5tts encoder, codec decoder, and llama_block graph code.
@lovemefan
lovemefan merged commit 0c15853 into RapidAI:main Dec 3, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants