本文档记录 SparkAudio/Spark-TTS-0.5B 在昇腾 NPU(Ascend910B)上的适配与验证结果。
Spark-TTS 是一个基于 Qwen2.5 大语言模型的高效文本转语音模型,支持可控语音生成(性别、音调、语速)和零样本语音克隆。本工程使用 ModelScope 下载模型,并在昇腾 NPU 上完成推理验证。
相关获取地址:
| 组件 | 版本 |
|---|---|
transformers | >=4.36.0 |
torch | >=2.0 |
torch-npu | matching CANN |
modelscope | latest |
librosa | latest |
scipy | latest |
omegaconf | latest |
safetensors | latest |
soundfile | latest |
soxr | latest |
einx | latest |
Ascend910B8.5.1安装依赖:
pip install -r requirements.txt运行 NPU 推理:
python inference.py输入文本(assets/test.txt):
Hello, this is a test of the text to speech system.NPU 推理结果:
Model: SparkAudio/Spark-TTS-0.5B
Input text: Hello, this is a test of the text to speech system.
Output audio: outputs/test.wav
Duration: 3.42s
Sample rate: 16000
Audio max amplitude: 0.737801输出音频有效:
TrueTrueTrue测试条件:连续 10 次推理(含 3 次 warmup),输入文本长度固定。
| 指标 | 数值 |
|---|---|
avg_latency_ms | 5979.1316 |
min_latency_ms | 5275.6922 |
max_latency_ms | 7087.3296 |
p50_latency_ms | 5761.6996 |
p90_latency_ms | 7029.0752 |
p95_latency_ms | 7058.2024 |
audio_duration_sec | 3.0800 |
real_time_factor | 1.9413 |
num_runs | 10 |
Spark-TTS 采用自回归采样生成语义 token,CPU 与 NPU 的最终波形长度和 Mel 谱图存在随机差异,因此以 LLM 隐藏层输出(确定性层) 为权威精度标准,Mel 对比仅作参考。
| 指标 | 数值 | 阈值 | 结果 |
|---|---|---|---|
hidden_states_relative_error | 0.0012% | < 1.0% | PASS |
hidden_states_cosine_sim | 1.000000 | > 0.99 | PASS |
mel_relative_error | 26.3492% | < 5.0% | 参考 |
mel_cosine_sim | 0.945143 | > 0.95 | 参考 |
npu_is_silent | False | must be False | PASS |
npu_has_nan | False | must be False | PASS |
npu_has_inf | False | must be False | PASS |
| Final Result | — | — | PASS |
do_sample=True 导致 CPU 与 NPU 的最终波形长度和内容存在随机差异,因此 Mel 谱图对比仅作参考,不作为失败依据。hidden_states)为准,CPU-NPU 相对误差 0.0012%,余弦相似度 1.000000,完全满足精度要求。snapshot_download 下载,所有加载均使用 local_files_only=True,禁止 HuggingFace 自动下载。controllable_tts 模式(指定性别、音调、语速)进行纯文本到语音合成,无需参考音频。