F5-TTS(A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching)是一款基于流匹配(Flow Matching)的零样本(Zero-Shot)文本转语音(Text-to-Speech)模型。该模型采用 Diffusion Transformer(DiT)架构,支持语音克隆、情感控制、语速调节等功能,能够通过少量参考音频生成自然流畅的语音。
本仓库完成了 SWivid/F5-TTS 模型在华为昇腾 Ascend NPU 上的适配工作,支持在昇腾910平台进行端到端的文本到语音合成推理。
| 组件 | 版本 |
|---|---|
| 操作系统 | Ubuntu 22.04.5 LTS (aarch64) |
| NPU | Ascend910 (2Chip) |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.9.0 (CPU) |
| torch_npu | 2.9.0.post1 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| F5-TTS | 1.1.22 |
| Vocos | 0.1.0 |
| Transformers | 5.15.1 |
# 安装基础依赖
pip install f5-tts
pip install torch-npu soundfile librosa
# 设置环境变量
export ASCEND_VISIBLE_DEVICES=10
export HF_ENDPOINT=https://hf-mirror.com# 从 HuggingFace 镜像下载模型
mkdir -p /path/to/models/F5-TTS/F5TTS_Base
curl -L "https://hf-mirror.com/SWivid/F5-TTS/resolve/main/F5TTS_Base/model_1200000.safetensors" \
-o /path/to/models/F5-TTS/F5TTS_Base/model_1200000.safetensors
curl -L "https://hf-mirror.com/SWivid/F5-TTS/resolve/main/F5TTS_Base/vocab.txt" \
-o /path/to/models/F5-TTS/F5TTS_Base/vocab.txtpython3 inference.py \
--ref_audio /path/to/ref_audio.wav \
--ref_text "Reference audio transcript" \
--gen_text "Text to synthesize" \
--output output.wavpython3 inference.py --server --port 8000服务启动后,可通过 API 进行调用:
# 检查服务状态
curl http://localhost:8000/v1/models
# TTS 推理(生成语音)
curl -X POST http://localhost:8000/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{"gen_text": "Hello, this is a test of F5-TTS on Ascend NPU."}'python3 -c "
from f5_tts.api import F5TTS
f5tts = F5TTS(model='F5TTS_Base',
ckpt_file='/path/to/models/F5-TTS/F5TTS_Base/model_1200000.safetensors',
vocab_file='/path/to/models/F5-TTS/F5TTS_Base/vocab.txt',
device='npu:0')
print('Model loaded successfully on NPU')
"预期输出:模型加载成功,无报错。
python3 inference.py \
--ref_audio /path/to/ref_audio.wav \
--ref_text "Reference transcript" \
--gen_text "Hello, welcome to the F5-TTS model on Ascend NPU." \
--output test_output.wav预期输出:生成 WAV 文件,可在播放器中播放。
以下为在 Ascend910 NPU 上 F5TTS_Base 模型(F5TTS_Base,335M 参数)的测试数据:
| 指标 | 值 |
|---|---|
| 模型加载时间 | 7.23s |
| 推理时间(生成 13.3s 音频,32步采样) | 2.61s |
| 实时率(RTF) | 0.196 |
| 生成音频采样率 | 24kHz |
| NPU 显存占用 | ~678 MB |
| 参考音频时长 | 5.33s |
| 生成文本长度 | 25 个词 |
F5-TTS 的原始精度指标请参考官方论文 F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching。
在昇腾 NPU 上的适配测试中,通过设置随机种子(seed=42),验证了推理结果的可复现性。生成的音频与 CUDA 版本相比,波形 RMS 和峰值在合理误差范围内,验证了 NPU 推理的正确性。
HF_ENDPOINT=https://hf-mirror.com 加速模型下载