SOUND / MMS-TTS
MMS-TTS
reComputer RK3588
在 reComputer RK3576 和 RK3588 上通过 RKNN 加速的 facebook/mms-tts-eng 英语语音合成模型。
选择你正在使用的设备,设置指南和文档将相应更新。
快速开始
Armbian 26.8.7 Gnome 及更新版本(启用 OTA overlayroot): 运行容器前请配置 Docker 存储 以避免 overlay 挂载错误。
sudo docker run --rm --privileged --net=host \
-e PYTHONUNBUFFERED=1 -e RKNN_LOG_LEVEL=0 \
-v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-mms_tts:latestREST API
使用 REST API 进行推理。复制以下命令。
curl http://localhost:8080/v1/chat/completions -d '{
"model": "mms-tts-rknn",
"messages": [{"role": "user", "content": "Hello"}]
}'import requests
resp = requests.post(
"http://localhost:8080/v1/chat/completions",
json={"model": "mms-tts-rknn", "messages": [{"role": "user", "content": "Hello"}]},
)
print(resp.json())模型详情
Armbian 26.8.7 Gnome 及更新版本(启用 OTA overlayroot): 运行容器前请配置 Docker 存储 以避免 overlay 挂载错误。
快速开始
1. 安装 Docker
在开发板上运行以下命令安装 Docker:
# Download installation script
curl -fsSL https://get.docker.com -o get-docker.sh
# Install using Aliyun mirror source
sudo sh get-docker.sh --mirror Aliyun
# Start Docker and enable auto-start on boot
sudo systemctl enable docker
sudo systemctl start docker2. 运行项目(一条命令,Web 预览)
本项目使用 facebook/mms-tts-eng 提供英语语音合成。Web 界面接受文本、控制语速,并提供 WAV 播放和下载。
步骤 A:拉取镜像
sudo docker pull ghcr.io/Seeed-Projects/recomputer-rk-cv/rk3588-mms_tts:latest
sudo docker pull ghcr.io/Seeed-Projects/recomputer-rk-cv/rk3576-mms_tts:latest步骤 B:一键运行
适用于 RK3588:
sudo docker run --rm --privileged --net=host \
-e PYTHONUNBUFFERED=1 \
-e RKNN_LOG_LEVEL=0 \
-v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-mms_tts:latest访问地址: http://<Board_IP>:8000
适用于 RK3576:
sudo docker run --rm --privileged --net=host \
-e PYTHONUNBUFFERED=1 \
-e RKNN_LOG_LEVEL=0 \
-v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
ghcr.io/seeed-projects/recomputer-rk-cv/rk3576-mms_tts:latest访问地址: http://<Board_IP>:8000
3. 命令行推理
python inference.py --platform rk3576 --model_dir model \
--text 'hello from the edge' \
--speaking_rate 0.8 \
--output output.wav在 RK3588 源目录中运行时,请使用 --platform rk3588。
🔌 API 文档
REST API 同步生成英语语音,并保留最新的 20 个生成 WAV 文件供临时下载。
1. 语音合成接口
端点: POST /api/models/mms_tts/predict
请求参数(Multipart/Form-Data):
text:必填英文文本,只能包含受支持的字符,最多 99 个字符。speaking_rate:可选,范围为 0.6 至 1.4,默认值为 1.0;小于 1 时语速更慢。
使用示例:
curl -X POST "http://127.0.0.1:8000/api/models/mms_tts/predict" \
-F 'text=hello from the edge' \
-F 'speaking_rate=0.8'响应格式(JSON):
{
"success": true,
"model": "mms_tts",
"platform": "rk3576",
"inference_time_ms": 224.7,
"result": {
"text": "hello from the edge",
"sample_rate": 16000,
"samples": 35840,
"duration_seconds": 2.24,
"speaking_rate": 0.8,
"duration_clipped": false,
"warnings": [],
"audio_url": "/api/audio/<audio_filename>",
"audio_filename": "<audio_filename>"
}
}语速参数在解码前缩放音素时长,因此不会对 WAV 做后续重采样,并能保持音高。若较慢的语速或较长文本达到解码器时长上限,duration_clipped 会为 true,响应中也会包含警告。
2. 下载生成的音频
端点: GET /api/audio/{audio_filename}
curl -o speech.wav \
"http://127.0.0.1:8000/api/audio/<audio_filename>"使用预测接口返回的准确 audio_filename。
3. 系统配置接口
获取当前配置
- 端点:
GET /api/config - 默认响应:
{"speaking_rate": 1.0}
更新配置
curl -X POST "http://127.0.0.1:8000/api/config" \
-H 'Content-Type: application/json' \
-d '{"speaking_rate": 1.2}'使用 GET /api/health 检查当前平台、已加载的编码器和解码器,以及支持的输入能力。OpenAPI 文档位于 /docs。
🛠️ 开发者指南(生产环境建议)
代码说明
web_service.py:- Web API:处理合成请求、配置、生成音频的存储、播放和下载。
- 输出保留:生成基于 UUID 的 WAV 文件名,并保留最新的 20 个生成文件。
task_runtime.py:- 文本处理:校验支持的英文字符,并转换为固定模型输入。
- 时长控制:使用
speaking_rate缩放音素时长,并报告解码器截断。 - RKNN 推理:运行编码器和解码器,写出单声道 16 kHz WAV 音频。
inference.py:提供单次合成并写入本地 WAV 文件。
模型文件
| 组件 | 文件 |
|---|---|
| MMS-TTS 编码器 | model/encoder.rknn |
| MMS-TTS 解码器 | model/decoder.rknn |
修改模型
- 将兼容的编码器和解码器模型放入
model/,并保留文件名。 - 两者应符合预期词表、时长张量和单声道 16 kHz 输出约定。
- 测试 0.6–1.4 语速范围和解码器时长上限。
编码器和解码器是同一语音合成流水线的两个阶段,不是可选的模型尺寸。上游项目目前为每个平台提供一对模型,没有独立的量化规格选择器。
构建本地镜像
在 reComputer-RK-CV 根目录运行:
docker build -f docker/rk3576/mms_tts.dockerfile \
-t rk3576-mms_tts:local src/rk3576_mms_tts
docker build -f docker/rk3588/mms_tts.dockerfile \
-t rk3588-mms_tts:local src/rk3588_mms_tts输入与输出
输入:英文文本和语速。输出:合成 WAV 音频、时长、采样率和采样数。