跳到正文

onnx-platform

onnx-platform 是 AI Voice Platform 的本地 C++ 语音与 AI 推理服务集合,包含基于 sherpa-onnxFunASR 两个体系构建的高性能离线/流式 ASR、TTS 与情绪分析服务。

模块总览

模块目录服务 / 组件名称协议与端口底层框架 / 模型主要功能
fanasr-asr-online-server/FunASR 流式实时 ASRWebSocket 10099 (/audio)FunASR + SenseVoice / ParaformerSenseVoice 伪流式 / Paraformer 2-pass 毫秒级 partial + 句尾高精度带标点 final 修正
fanasr-asr-offline-server/FunASR 离线 ASRHTTP 10094 (/asr)FunASR + Paraformer + CT-Punc音频文件整段转写、时间戳与标点恢复
sherpa-asr-online-server/Sherpa 流式 ASRWebSocket 10096 (/audio)sherpa-onnx + Zipformer实时流式识别,对接 FreeSWITCH mod_audio_fork
sherpa-asr-offline-server/Sherpa 离线 ASRHTTP 10095 (/asr)sherpa-onnx + SenseVoice多语种(中英粤日韩)语音转写、ITN、语种/情绪检测
sherpa-tts-server/本地 TTS 语音合成HTTP 9080 (/tts, /tts-stream)sherpa-onnx + VITS/Matcha/Kokoro离线 WAV 合成与实时 MP3 流式播放 (shout://)
emotion-analysis-server/情绪分析服务HTTP 9090 (/analyze)ONNX Runtime + BERT/wav2vec2文本与音频多模态情绪打分(0~100 极性融合)
fanasr-onnx/FunASR 预编译 SDK静态/动态库资产C++ 头文件与 Win/Linux 预编 .lib/.dll/.so支持服务端 1~3 秒极速构建,免编 OpenFST/Kaldi
fanasr-runtime/FunASR 运行时源码C++ 源码工程Kaldi Fbank / OpenFST / OnnxRuntime跨平台底层推理运行时,支持 CMake 自动降级编译
sherpa-onnx/sherpa-onnx 预编译 SDK跨平台二进制包Win_x64, Linux_x64, macOS arm64sherpa-onnx 官方预编译资产
sherpa-demo/C++ 验证程序集本地 CLI 工具sherpa-onnx离线/流式 ASR/TTS/VAD 最小测试程序

Linux / Docker 构建说明

当前 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_x64fanasr-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-platform

Debian 12 镜像用于构建需要在 Debian 12 x64 上原生运行的 ASR / TTS / Emotion 发布产物:

powershell
docker build `
  -f onnx-platform/Dockerfile.debian12 `
  -t ai-voice-platform-debian12 `
  onnx-platform

Debian 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 build/fanasr-online-linux_x64 build/fanasr-offline-linux_x64
bash sherpa-tts-server/build.sh
bash sherpa-asr-online-server/build.sh
bash emotion-analysis-server/build.sh
bash fanasr-asr-online-server/build.sh
bash fanasr-asr-offline-server/build.sh

这些脚本会自动解析 onnx-platform 根目录,并使用统一目录:

  • build/tts-linux_x64 -> sherpa-tts-server/target/linux_x64
  • build/asr-linux_x64 -> sherpa-asr-online-server/target/linux_x64
  • build/emotion-linux_x64 -> emotion-analysis-server/target/linux_x64
  • build/fanasr-online-linux_x64 -> fanasr-asr-online-server/target/linux_x64
  • build/fanasr-offline-linux_x64 -> fanasr-asr-offline-server/target/linux_x64

不要在不同 Linux 发行版之间复用以上 build/*-linux_x64 目录。切换构建镜像时应重新清理, 以免 CMake 缓存或目标文件把较新系统的运行库要求带入发布产物。

其中 TTS / ASR 使用仓库内 sherpa-onnx/linux_x64;情绪分析服务使用 onnxruntime/linux_x64,若该目录下只有 onnxruntime-linux-x64-1.26.0.tgzemotion-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.solibsherpa-onnx-c-api.solibonnxruntime.soconfig.json,并同时部署配置引用的 models/ 模型资源。三个 .so 通过 $ORIGIN 从主程序所在目录加载,不能只复制可执行文件。
  • 发布包不包含 glibc 或 libstdc++。Ubuntu 22.04、Debian 12、Debian 13 镜像构建的 程序分别依赖对应构建环境的系统运行库;面向某个发行版发布时,应使用对应镜像重新构建, 不要假设在较新发行版中构建的程序能够在较旧发行版上运行。
  • 情绪分析服务直接使用 onnx-platform/onnxruntime/ 下的 ONNX Runtime,不依赖 sherpa-onnx。
  • 运行时服务默认以前台常驻方式运行,结束时用 Ctrl+C 停止。

文档与代码在同一仓库维护,现有 Markdown 是唯一内容源。