外观
FunASR Offline ASR Server (HTTP)
基于 FunASR C++ ONNX Runtime 构建的高性能 HTTP 离线语音识别服务,支持多 Profile 模型切换(Paraformer 离线大模型 + SenseVoiceSmall 多语种多模态大模型),内置 FSMN-VAD 语音切句、CT-Transformer 标点恢复、SenseVoice 富文本标签解析与逆文本归一化(ITN)。
1. 核心特性
- 多模型 Profile 架构:支持
Paraformer离线大模型(带 VAD + 标点恢复)与SenseVoiceSmall多语种大模型(中/粤/英/日/韩/情绪识别/声音事件检测)灵活切换; - 全格式输入支持:支持
multipart/form-data(上传文件)、application/json(Base64 或本地文件路径)以及 Raw Binary PCM/WAV 音频流; - 双协议兼容:提供统一标准接口(
/asr、/recognize)与 OpenAI/v1/audio/transcriptions兼容接口; - 7×24 高可用架构:内置工作线程池队列(ThreadPool)、过载熔断(HTTP 503)、30 秒读超时保护、每日日志自动轮转与防内存泄漏机制;
- 极速构建:优先直连
onnx-platform/fanasr-onnx预编译 SDK,全工程从零构建仅需 3~4 秒。
2. 默认端口与路由
- 默认监听:
0.0.0.0:10094 GET /health:服务健康检查与运行指标(包含activeModel、modelType、models列表等);POST /asr或POST /recognize:标准文件语音识别接口;POST /v1/audio/transcriptions:OpenAI Whisper 兼容接口。
3. 接口调用说明
3.1 健康检查
bash
curl http://127.0.0.1:10094/health响应示例:
json
{
"code": 0,
"msg": "ok",
"data": {
"status": "ok",
"service": "fanasr-asr-offline-server",
"activeModel": "funasr-paraformer-large-zh-onnx",
"modelType": "paraformer",
"modelDir": "C:/path/to/models/funasr-paraformer-large-zh-onnx",
"sampleRate": 16000,
"uptimeSeconds": 3600,
"totalRequests": 128,
"models": [
"funasr-paraformer-large-zh-onnx",
"funasr-sensevoicesmall-zh-cantonese-en-ja-ko-onnx"
]
}
}3.2 标准识别接口 (POST /asr)
方式 A:multipart/form-data 文件上传(推荐)
bash
curl -X POST http://127.0.0.1:10094/asr \
-F "file=@test.wav" \
-F "language=auto" \
-F "use_itn=true"方式 B:application/json Base64 上传
bash
curl -X POST http://127.0.0.1:10094/asr \
-H "Content-Type: application/json" \
-d '{"audioBase64": "<BASE64_ENCODED_PCM_OR_WAV>", "language": "auto", "useItn": true}'方式 C:application/json 本地绝对路径
bash
curl -X POST http://127.0.0.1:10094/asr \
-H "Content-Type: application/json" \
-d '{"audioPath": "C:/data/audio/sample.wav"}'响应结构(SenseVoiceSmall 模式示例):
json
{
"code": 0,
"msg": "ok",
"data": {
"text": "重点呢想谈三个问题。首先呢就是这一轮全球金融动荡的表现。",
"cleanText": "重点呢想谈三个问题。首先呢就是这一轮全球金融动荡的表现。",
"lang": "zh",
"emotion": "NEUTRAL",
"event": "Speech",
"durationSeconds": 5.15,
"latencyMs": 235.4,
"sentences": [
{
"text": "重点呢想谈三个问题。首先呢就是这一轮全球金融动荡的表现。",
"start": 0,
"end": 5153
}
]
}
}3.3 OpenAI 兼容接口 (POST /v1/audio/transcriptions)
bash
curl -X POST http://127.0.0.1:10094/v1/audio/transcriptions \
-F "file=@test.wav"响应结构:
json
{
"text": "重点呢想谈三个问题。首先呢就是这一轮全球金融动荡的表现。"
}4. 配置文件说明 (config.json)
完整配置项定义、字段类型约束、默认值与高级场景调优请查阅专题文档: 📖 FunASR Offline ASR Server 配置参考
json
{
"server": {
"host": "0.0.0.0",
"port": 10094,
"healthPath": "/health",
"asrPath": "/asr",
"recognizePath": "/recognize",
"transcriptionsPath": "/v1/audio/transcriptions",
"maxPayloadBytes": 67108864
},
"concurrency": {
"workerThreads": 2,
"maxQueueSize": 128,
"numThreads": 1,
"instancePoolSize": 2
},
"asr": {
"activeModel": "funasr-paraformer-large-zh-onnx",
"models": {
"funasr-paraformer-large-zh-onnx": {
"modelDir": "funasr-paraformer-large-zh-onnx",
"vadDir": "funasr-fsmn-vad-zh-onnx",
"puncDir": "funasr-ct-transformer-zh-onnx"
},
"funasr-sensevoicesmall-zh-cantonese-en-ja-ko-onnx": {
"modelDir": "funasr-sensevoicesmall-zh-cantonese-en-ja-ko-onnx",
"language": "auto"
}
},
"quantize": true,
"sampleRate": 16000,
"useItn": true,
"hotwordsFile": "hotword.json",
"defaultHotwordProfile": "default"
},
"ffmpeg": {
"enabled": true,
"ffmpegPath": "ffmpeg",
"timeoutSeconds": 30,
"sampleRate": 16000,
"channels": 1
},
"logging": {
"dir": "logs",
"level": "info"
}
}5. 编译与运行
5.1 Windows (MSVC)
powershell
.\build.ps1编译完成后运行:
powershell
cd target\win_x64
.\fanasr_asr_offline_server.exe5.2 Linux (Ninja / GCC)
bash
./build.sh
cd target/linux_x64
./fanasr_asr_offline_server6. 测试
bash
node request-asr.js
# 或指定音频文件和语种
node request-asr.js path/to/audio.wav http://127.0.0.1:10094 auto