Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

Update SDK_advanced_guide_online_zh.md

Yabin Lidc0684f9e954
diff --git a/funasr/runtime/docs/SDK_advanced_guide_online_zh.md b/funasr/runtime/docs/SDK_advanced_guide_online_zh.md
index cc475102b..c7603c8b6 100644
--- a/funasr/runtime/docs/SDK_advanced_guide_online_zh.md
+++ b/funasr/runtime/docs/SDK_advanced_guide_online_zh.md
@@ -1,9 +1,9 @@
# FunASR实时语音转写服务开发指南
FunASR提供可便捷本地或者云端服务器部署的实时语音转写服务,内核为FunASR已开源runtime-SDK。
-集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large非流式语音识别(ASR)、Paraformer-large流式语音识别(ASR)、标点恢复(PUNC) 等相关能力。软件包既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求
+集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large非流式语音识别(ASR)、Paraformer-large流式语音识别(ASR)、标点(PUNC) 等相关能力。软件包既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求
-本文档为FunASR离线文件转写服务开发指南。如果您想快速体验实时语音转写服务,可参考[快速上手](#快速上手)。
+本文档为FunASR实时转写服务开发指南。如果您想快速体验实时语音转写服务,可参考[快速上手](#快速上手)。
## 快速上手
### 镜像启动
@@ -19,21 +19,22 @@ sudo docker run -p 10095:10095 -it --privileged=true -v /root:/workspace/models
### 服务端启动
-docker启动之后,启动 funasr-wss-server服务程序:
+docker启动之后,启动 funasr-wss-server-2pass服务程序:
```shell
cd FunASR/funasr/runtime
-./run_server.sh \
+./run_server_2pass.sh \
--download-model-dir /workspace/models \
--vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \
--model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx \
- --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
+ --online-model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx \
+ --punc-dir damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx
```
服务端详细参数介绍可参考[服务端参数介绍](#服务端参数介绍)
### 客户端测试与使用
下载客户端测试工具目录samples
```shell
-wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_samples.tar.gz
+wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_online_samples.tar.gz
```
我们以Python语言客户端为例,进行说明,支持多种音频格式输入(.wav, .pcm, .mp3等),也支持视频输入(.mp4等),以及多文件列表wav.scp输入,其他版本客户端请参考文档([点击此处](#客户端用法详解)),定制服务部署请参考[如何定制服务部署](#如何定制服务部署)
```shell
@@ -97,7 +98,7 @@ python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode offline --audio
### cpp-client
进入samples/cpp目录后,可以用cpp进行测试,指令如下:
```shell
-./funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav
+./funasr-wss-client-2pass --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav
```
命令参数说明:
@@ -131,8 +132,9 @@ cd /workspace/FunASR/funasr/runtime/websocket/build/bin
./funasr-wss-server \
--download-model-dir /workspace/models \
--model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx \
+ --online-model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx \
--vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \
- --punc-dir damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \
+ --punc-dir damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx \
--decoder-thread-num 32 \
--io-thread-num 8 \
--port 10095 \
@@ -143,6 +145,7 @@ cd /workspace/FunASR/funasr/runtime/websocket/build/bin
```text
--download-model-dir 模型下载地址,通过设置model ID从Modelscope下载模型
--model-dir modelscope model ID
+--online-model-dir modelscope model ID
--quantize True为量化ASR模型,False为非量化ASR模型,默认是True
--vad-dir modelscope model ID
--vad-quant True为量化VAD模型,False为非量化VAD模型,默认是True
@@ -155,34 +158,6 @@ cd /workspace/FunASR/funasr/runtime/websocket/build/bin
--keyfile ssl的密钥文件,默认为:../../../ssl_key/server.key
```
-funasr-wss-server同时也支持从本地路径加载模型(本地模型资源准备详见[模型资源准备](#模型资源准备))示例如下:
-```shell
-cd /workspace/FunASR/funasr/runtime/websocket/build/bin
-./funasr-wss-server \
- --model-dir /workspace/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx \
- --vad-dir /workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx \
- --punc-dir /workspace/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx \
- --decoder-thread-num 32 \
- --io-thread-num 8 \
- --port 10095 \
- --certfile ../../../ssl_key/server.crt \
- --keyfile ../../../ssl_key/server.key
- ```
-命令参数介绍:
-```text
---model-dir ASR模型路径,默认为:/workspace/models/asr
---quantize True为量化ASR模型,False为非量化ASR模型,默认是True
---vad-dir VAD模型路径,默认为:/workspace/models/vad
---vad-quant True为量化VAD模型,False为非量化VAD模型,默认是True
---punc-dir PUNC模型路径,默认为:/workspace/models/punc
---punc-quant True为量化PUNC模型,False为非量化PUNC模型,默认是True
---port 服务端监听的端口号,默认为 10095
---decoder-thread-num 服务端启动的推理线程数,默认为 8
---io-thread-num 服务端启动的IO线程数,默认为 1
---certfile ssl的证书文件,默认为:../../../ssl_key/server.crt
---keyfile ssl的密钥文件,默认为:../../../ssl_key/server.key
-```
-
## 模型资源准备
如果您选择通过funasr-wss-server从Modelscope下载模型,可以跳过本步骤。
@@ -191,11 +166,12 @@ FunASR离线文件转写服务中的vad、asr和punc模型资源均来自Modelsc
| 模型 | Modelscope链接 |
|------|---------------------------------------------------------------------------------------------------------------|
-| VAD | https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx/summary |
-| ASR | https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary |
-| PUNC | https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx/summary |
+| VAD | https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary |
+| ASR | https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx/summary |
+| ASR | https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx/summary |
+| PUNC | https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx/summary |
-离线文件转写服务中部署的是量化后的ONNX模型,下面介绍下如何导出ONNX模型及其量化:您可以选择从Modelscope导出ONNX模型、从finetune后的资源导出模型:
+实时转写服务中部署的是量化后的ONNX模型,下面介绍下如何导出ONNX模型及其量化:您可以选择从Modelscope导出ONNX模型、从finetune后的资源导出模型:
### 从Modelscope导出ONNX模型
@@ -227,63 +203,3 @@ python -m funasr.export.export_model \
```shell
python -m funasr.export.export_model --model-name /path/to/finetune/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch --export-dir ./export --type onnx --quantize True
```
-
-
-
-## 如何定制服务部署
-
-FunASR-runtime的代码已开源,如果服务端和客户端不能很好的满足您的需求,您可以根据自己的需求进行进一步的开发:
-### c++ 客户端:
-
-https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/websocket
-
-### python 客户端:
-
-https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket
-
-### 自定义客户端:
-
-如果您想定义自己的client,websocket通信协议为:
-
-```text
-# 首次通信
-{"mode": "offline", "wav_name": wav_name, "is_speaking": True}
-# 发送wav数据
-bytes数据
-# 发送结束标志
-{"is_speaking": False}
-```
-
-### c++ 服务端:
-
-#### VAD
-```c++
-// VAD模型的使用分为FsmnVadInit和FsmnVadInfer两个步骤:
-FUNASR_HANDLE vad_hanlde=FsmnVadInit(model_path, thread_num);
-// 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数;
-FUNASR_RESULT result=FsmnVadInfer(vad_hanlde, wav_file.c_str(), NULL, 16000);
-// 其中:vad_hanlde为FunOfflineInit返回值,wav_file为音频路径,sampling_rate为采样率(默认16k)
-```
-
-使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-online-vad.cpp
-
-#### ASR
-```text
-// ASR模型的使用分为FunOfflineInit和FunOfflineInfer两个步骤:
-FUNASR_HANDLE asr_hanlde=FunOfflineInit(model_path, thread_num);
-// 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数;
-FUNASR_RESULT result=FunOfflineInfer(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL, 16000);
-// 其中:asr_hanlde为FunOfflineInit返回值,wav_file为音频路径,sampling_rate为采样率(默认16k)
-```
-
-使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-offline.cpp
-
-#### PUNC
-```text
-// PUNC模型的使用分为CTTransformerInit和CTTransformerInfer两个步骤:
-FUNASR_HANDLE punc_hanlde=CTTransformerInit(model_path, thread_num);
-// 其中:model_path 包含"model-dir"、"quantize",thread_num为onnx线程数;
-FUNASR_RESULT result=CTTransformerInfer(punc_hanlde, txt_str.c_str(), RASR_NONE, NULL);
-// 其中:punc_hanlde为CTTransformerInit返回值,txt_str为文本
-```
-使用示例详见:https://github.com/alibaba-damo-academy/FunASR/blob/main/funasr/runtime/onnxruntime/bin/funasr-onnx-online-punc.cpp
\ No newline at end of file