外观
onnx-platform Linux / Docker
这里是 onnx-platform 的统一 Linux 入口。当前支持:
- Ubuntu 22.04 容器内构建用于需要兼容 Ubuntu 22.04 的 ASR / TTS / Emotion 发布产物
- Debian 12 容器内构建用于 Debian 12 x64 上运行的 ASR / TTS / Emotion 发布产物
- Debian 13 容器内构建面向 Debian 13 或满足其新版运行库要求的 ASR / TTS / Emotion 发布产物
- 使用仓库内
sherpa-onnx/linux_x64预编译包 - 产物架构为 Linux x86-64
Docker
Ubuntu 22.04 镜像用于构建需要在 Ubuntu 22.04 x64 上原生运行的 ASR / TTS / Emotion 发布产物。镜像只安装工具链,不复制源码;构建时继续挂载仓库目录:
powershell
docker build `
-f onnx-platform/Dockerfile.ubuntu22 `
-t ai-voice-platform-ubuntu22 `
onnx-platformDebian 12 镜像用于构建需要在 Debian 12 x64 上原生运行的 ASR / TTS / Emotion 发布产物:
powershell
docker build `
-f onnx-platform/Dockerfile.debian12 `
-t ai-voice-platform-debian12 `
onnx-platformDebian 13 镜像继续保留,用于 Debian 13 或具有相应新版 glibc / libstdc++ 运行库的环境:
powershell
docker build `
-f onnx-platform/Dockerfile.debian13 `
-t ai-voice-platform-debian13 `
onnx-platform-f onnx-platform/Dockerfile.<发行版> 指定 Dockerfile 路径。 -t ai-voice-platform-<发行版> 给镜像命名。 最后的 onnx-platform 是构建上下文目录,Docker 会把它作为 COPY 和相对路径解析的根。
以 Debian 12 镜像进入容器:
powershell
docker run --rm -it `
-p 9080:9080 `
-p 10096:10096 `
-v "${PWD}:/workspace/ai-voice-platform" `
-w /workspace/ai-voice-platform/onnx-platform `
ai-voice-platform-debian12 `
bash--rm 表示退出后自动删除容器。 -it 开启交互式终端。 -p 9080:9080 把容器 9080 端口映射到宿主 9080,给 TTS 用。 -p 10096:10096 把容器 10096 端口映射到宿主 10096,给 ASR 用。 -v "${PWD}:/workspace/ai-voice-platform" 把当前仓库挂进容器。 -w /workspace/ai-voice-platform/onnx-platform 设定容器内工作目录。 最后的 bash 是进入容器后执行的命令。
构建
在 Ubuntu 22.04、Debian 12 或 Debian 13 容器内构建前,必须删除其他发行版留下的 CMake 缓存和目标文件,再调用各项目现有的 Linux 构建脚本:
bash
rm -rf build/asr-linux_x64 build/tts-linux_x64 build/emotion-linux_x64
bash sherpa-tts-server/build.sh
bash sherpa-asr-online-server/build.sh
bash emotion-analysis-server/build.sh这三个脚本会自动解析 onnx-platform 根目录,并使用统一目录:
build/tts-linux_x64->sherpa-tts-server/target/linux_x64build/asr-linux_x64->sherpa-asr-online-server/target/linux_x64build/emotion-linux_x64->emotion-analysis-server/target/linux_x64
不要在不同 Linux 发行版之间复用以上 build/*-linux_x64 目录。切换构建镜像时应重新清理, 以免 CMake 缓存或目标文件把较新系统的运行库要求带入发布产物。
其中 TTS / ASR 使用仓库内 sherpa-onnx/linux_x64;情绪分析服务使用 onnxruntime/linux_x64,若该目录下只有 onnxruntime-linux-x64-1.26.0.tgz, emotion-analysis-server/build.sh 会先自动解压出 include/ 与 lib/libonnxruntime.so。
等价的 CMake 参数如下:
bash
cmake -S sherpa-tts-server -B build/tts-linux_x64 -G Ninja -DSHERPA_ONNX_ROOT=/workspace/ai-voice-platform/onnx-platform/sherpa-onnx/linux_x64
cmake -S sherpa-asr-online-server -B build/asr-linux_x64 -G Ninja -DSHERPA_ONNX_ROOT=/workspace/ai-voice-platform/onnx-platform/sherpa-onnx/linux_x64
cmake -S emotion-analysis-server -B build/emotion-linux_x64 -G Ninja -DONNXRUNTIME_ROOT=/workspace/ai-voice-platform/onnx-platform/onnxruntime/linux_x64
cmake -S sherpa-demo -B build/demo-linux_x64 -G Ninja -DSHERPA_ONNX_ROOT=/workspace/ai-voice-platform/onnx-platform/sherpa-onnx/linux_x64-S sherpa-tts-server / -S sherpa-asr-online-server / -S emotion-analysis-server / -S sherpa-demo 分别指定项目源码目录。 -B build/... 指定各自独立的构建目录。 -G Ninja 选择 Ninja 生成器。 -DSHERPA_ONNX_ROOT=.../linux_x64 指向仓库内 Linux 预编译 sherpa-onnx 包。 -DONNXRUNTIME_ROOT=.../linux_x64 指向 ONNX Runtime Linux x64 发行目录。
对应构建:
bash
cmake --build build/tts-linux_x64 -j2
cmake --build build/asr-linux_x64 -j2
cmake --build build/emotion-linux_x64 -j2
cmake --build build/demo-linux_x64 -j2
cmake --install build/tts-linux_x64 --prefix sherpa-tts-server/target/linux_x64
cmake --install build/asr-linux_x64 --prefix sherpa-asr-online-server/target/linux_x64
cmake --install build/emotion-linux_x64 --prefix emotion-analysis-server/target/linux_x64
cmake --install build/demo-linux_x64 --prefix sherpa-demo/target/linux_x64--build <dir> 让 CMake 使用已配置好的构建目录执行编译。 --install <dir> --prefix <dir> 生成干净发布目录。 -j2 表示并行 2 个编译任务。
运行
TTS:
bash
./sherpa-tts-server/target/linux_x64/sherpa_tts_server ./sherpa-tts-server/config.json
curl http://127.0.0.1:9080/health./sherpa-tts-server/target/linux_x64/sherpa_tts_server 是 TTS 可执行文件。 ./sherpa-tts-server/config.json 是服务配置文件。 curl http://127.0.0.1:9080/health 检查服务是否监听成功。
ASR:
bash
./sherpa-asr-online-server/target/linux_x64/sherpa_asr_online_server ./sherpa-asr-online-server/config.json
curl http://127.0.0.1:10096/health./sherpa-asr-online-server/target/linux_x64/sherpa_asr_online_server 是 ASR 可执行文件。 ./sherpa-asr-online-server/config.json 是服务配置文件。 curl http://127.0.0.1:10096/health 检查服务是否监听成功。
Emotion:
bash
./emotion-analysis-server/target/linux_x64/emotion_analysis_server ./emotion-analysis-server/config.json
curl http://127.0.0.1:9090/health./emotion-analysis-server/target/linux_x64/emotion_analysis_server 是情绪分析服务可执行文件。 ./emotion-analysis-server/config.json 是服务配置文件。 curl http://127.0.0.1:9090/health 检查服务是否监听成功。
Demo:
bash
./sherpa-demo/target/linux_x64/demo_offline_asr ./models./sherpa-demo/target/linux_x64/demo_offline_asr 是 demo 程序。 ./models 是模型根目录,demo 会从这里解析各个模型和测试音频。
注意事项
- 本指南覆盖部署所需的
sherpa-tts-server/sherpa-asr-online-server/emotion-analysis-server三个服务;sherpa-demo保留为本地模型验证目标。 - Linux 下要和仓库里的
sherpa-onnx/linux_x64预编译包匹配。 - ASR / TTS 发布时必须整体复制各自
target/linux_x64/中的主程序、libsherpa-onnx-cxx-api.so、libsherpa-onnx-c-api.so、libonnxruntime.so和config.json,并同时部署配置引用的models/模型资源。三个.so通过$ORIGIN从主程序所在目录加载,不能只复制可执行文件。 - 发布包不包含 glibc 或 libstdc++。Ubuntu 22.04、Debian 12、Debian 13 镜像构建的 程序分别依赖对应构建环境的系统运行库;面向某个发行版发布时,应使用对应镜像重新构建, 不要假设在较新发行版中构建的程序能够在较旧发行版上运行。
- 情绪分析服务直接使用
onnx-platform/onnxruntime/下的 ONNX Runtime,不依赖 sherpa-onnx。 - 运行时服务默认以前台常驻方式运行,结束时用
Ctrl+C停止。