Indic Parler-TTS 是 AI4Bharat 在 Parler-TTS 基础上扩展的印度语言文本转语音模型,支持 21 种印度语言与 metaphone(音素文字),可让单一检查点说出未显式训练过的语言。模型为 encoder-decoder 结构(937.8M 参数):T5 风格文本编码器接收说话人描述(如"A female speaker delivers... in Hindi..."),解码器自回归生成音频 codec token(9 个 codebook,词表 1088)。
原始模型:ai4bharat/indic-parler-tts(Apache-2.0;⚠️ HF 上为 gated,权重需从 ModelScope 获取) 官方代码:ai4bharat/indic-parler-tts
加载方式:pip install parler-tts → ParlerTTSForConditionalGeneration.from_pretrained(models/) + AutoTokenizer。
适配方案(确定性对比路径):完整生成链路含随机采样,跨端不可复现。本仓库采用 teacher-forcing 前向:固定英文描述编码为 (1, 21) token,固定种子(42)合成的 9×128 音频 token(codebook 堆叠,符合 decoder 的 (bsz*codebooks, L) → (bsz, codebooks, L) 约定)驱动一次前向,对比解码器 logits 的 cos_sim 与 argmax 一致率——完整验证加载路径与计算图,双端输入完全一致。
# 1. 克隆仓库
git clone https://gitcode.com/weasonlee/indic-parler-tts.git
cd indic-parler-tts
# 2. 安装依赖
pip install -r requirements.txt
# 3. 准备权重到 models/(已 .gitignore 排除;model.safetensors 单文件 ~3.7GB)
# HF 为 gated,从 ModelScope 下载:
pip install modelscope
python -c "
from modelscope import snapshot_download
snapshot_download('ai4bharat/Indic-Parler-TTS', local_dir='models')"
# 4. 推理(NPU,teacher-forcing 对比路径)
python inference.py --device npu
# 或 CPU
python inference.py --device cpu$ python inference.py --device npu
torch.npu.is_available() = True
torch.npu.device_count() = 2
[info] device = npu:0, torch = 2.9.0+cpu
[load] ParlerTTS: 937.8M params, decoder vocab=1088, enc=t5
[info] desc_tokens = (1, 21), audio_tokens = (9, 128) (9 codebooks x 128, seed=42)
[time] run 0: 40 ms
[time] avg: 40 ms (teacher-forcing pass)
[out ] logits: shape=(9, 128, 1088) mean=15.9366 std=20.2456
[out ] argmax sample: [166, 775, 28, 815, 690, 1024, 928, 1024]
===== CPU vs NPU comparison (decoder logits (9, 128, 1088)) =====
cos_sim = 0.99999628
max_abs_err = 1.523e+00
mean_abs_err = 6.061e-02
argmax agreement = 93.40%输入:固定说话人描述("A female speaker delivers a slightly expressive and animated speech in Hindi at a normal pace.",21 token)+ 固定种子(42)合成音频 token(9 codebook × 128 步);CPU 与 NPU 输入完全一致。
| 指标 | 值 |
|---|---|
| cos_sim(9×128×1088 解码器 logits) | 0.99999628 |
| max_abs_err / mean_abs_err | 1.523e+00 / 6.061e-02 |
| argmax 一致率 | 93.40% |
| 单次前向耗时(含同步,3 次均值) | NPU ~40 ms vs CPU ~2311 ms(~58× 加速) |
说明:logits 量级较大(std≈20),fp32 下 NPU 与 CPU 的注意力累加顺序差异被放大,最大绝对误差 1.5 出现在 20 量级的取值上(相对误差 ~7%),但整体方向一致性 cos_sim 仍达 0.999996,argmax 一致率 93.4%(多数不一致 token 的 top-1/top-2 logits 差距在噪声量级),属 fp32 正常差异范围,适配可用。对精度敏感场景建议在 NPU 上以 float32 严格模式或参考实现复核关键 token。
├── inference.py # 推理脚本(teacher-forcing + NPU/CPU 对比)
├── readme.md
├── requirements.txt
├── models/ # 权重目录(需自行下载,已 gitignore)
├── assets/ # 运行截图
│ ├── agent_workflow.png
│ ├── npu_device_call.png
│ └── model_result.png
└── results/ # 每次运行的 logits/耗时产物(gitignore)Nair V. et al. "Indic Parler-TTS: a multilingual TTS model for 21 indic languages." arXiv 2025.