Qwen3-TTS (12Hz, voice clone) inference on pure CPU via MNN — no PyTorch required at runtime
Project description
qwen3-tts-mnn
Qwen3-TTS-12Hz-0.6B-Base 的纯 CPU 推理包 — 基于 MNN,支持零样本声音克隆。
- 运行时只需
numpy + MNN(pymnn),无需 PyTorch / CUDA - 内置纯 Python Qwen2 BPE 分词器(与 HuggingFace 输出逐 token 一致)
- 与原生 PyTorch 推理 codec 匹配率 ≥99%(fp16 权重,实测 g0 99.0% / 全 16 组 99.9%)
- 输出 24kHz 单声道波形
安装
pip install qwen3-tts-mnn
模型资产
PyPI 包不含模型权重(~1.9GB),需自行准备 MNN 资产目录:
model_dir/
talker_step.mnn # Talker LM 单步 (带 KV cache)
cp_step.mnn # CodePredictor 单步
vocoder.mnn # 12Hz codec -> 24kHz 波形
weights/*.bin # 嵌入表/头 fp16 + meta.json
tokenizer/{vocab.json, merges.txt}
声线目录(克隆资产,纯 numpy,运行时无 torch 依赖):
voice_dir/
ref_code.i32.bin # [T,16] int32, 参考音频的 12Hz codec
spk_emb.f32.bin # [1024] float32, 说话人嵌入
meta.json # {ref_text, ref_ids, ref_frames}
快速开始
Python API
from qwen3_tts_mnn import Qwen3TtsMnn
tts = Qwen3TtsMnn('model_dir', num_threads=8)
tts.load_voice('voice_dir')
pcm = tts.synthesize('你好呀,我是小柒!') # float32 [-1,1], 24kHz
tts.synthesize_to_file('你好呀', 'out.wav') # 直接写 wav (标准库)
可调参数:temperature / top_k / top_p / repetition_penalty / seed / max_steps / min_new_tokens,
以及 synthesize_codes()(取 codec 帧)与 codes_to_wav()(离线解码)、on_frame 流式回调。
命令行
qwen3-tts-mnn --model-dir model_dir --voice voice_dir \
--text '你好呀,我是小柒!' -o out.wav --threads 8 --seed 42
克隆新声音
用官方 PyTorch 模型离线一次性提取声线资产(之后推理不再需要 torch):
pip install qwen3-tts-mnn[extract]
qwen3-tts-mnn-extract --hf-model /path/to/Qwen3-TTS-12Hz-0.6B-Base \
--ref-audio ref.wav --ref-text '参考音频的逐字文本' -o my_voice/
参考音频建议 3~15s 清晰人声,--ref-text 必须与音频内容逐字一致。
from qwen3_tts_mnn.voice import extract_voice
profile = extract_voice(hf_model_path, 'ref.wav', '逐字文本', out_dir='my_voice/')
架构
文本 ──> Qwen2 BPE ──> text_proj ──┐
├─> Talker LM (28层, KV cache) ──> g0 logits ──> CP (15步) ──> codes [T,16]
ref_code+spk_emb ──> ICL 装配 ─────┘ │
vocoder.mnn <──────────┘
│
24kHz wav
- Talker/CodePredictor 以
*_step.mnn(prefill/decode 共用单步 + KV cache 输入输出)运行 - 嵌入表/头等小权重为 fp16 bin,由 numpy 查表/矩阵乘完成
- 采样对齐原生实现:temperature + top_k + top_p + repetition_penalty(unique 历史)
性能参考
Apple Silicon(8 线程, fp16):RTF ≈ 46(即 1s 音频需 46s 合成)。生产环境建议
预合成固定台词缓存,或流式分段合成。
License
Apache-2.0(代码)。模型权重遵循 Qwen 模型许可证。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qwen3_tts_mnn-0.1.0.tar.gz.
File metadata
- Download URL: qwen3_tts_mnn-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28b724edc2befbe41506829410ac692f84f05b6281d2e1398c955e7b0c79ac9f
|
|
| MD5 |
41127d3083f2d77f410dab97b5c18c56
|
|
| BLAKE2b-256 |
93fecb76ee958f8debde3ad172a2f2ff7f6970d69e4faaf929e4bff4d7d5e624
|
File details
Details for the file qwen3_tts_mnn-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qwen3_tts_mnn-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3288f9e75a5cadaa7e42367775e07f6c60df3a46e6eda46851c4dbcbef7da91
|
|
| MD5 |
1c1c5b6545703aba9319908164c49251
|
|
| BLAKE2b-256 |
70b7a9765e56029590434d5753b0df424711c6e9d36cba2ae4fd090c9e32e0fb
|