This commit is contained in:
游雁 2023-08-08 14:50:09 +08:00
parent 2d7e966b03
commit bffee31cf3
3 changed files with 28 additions and 180 deletions

View File

@ -31,7 +31,7 @@ FunASR希望在语音识别的学术研究和工业应用之间架起一座桥
<a name="最新动态"></a>
## 最新动态
- 2023.08.07: 中文实时语音写服务一键部署的CPU版本发布详细信息参阅([一键部署文档](funasr/runtime/docs/SDK_tutorial_online_zh.md))
- 2023.08.07: 中文实时语音写服务一键部署的CPU版本发布详细信息参阅([一键部署文档](funasr/runtime/docs/SDK_tutorial_online_zh.md))
- 2023.07.17: BAT一种低延迟低内存消耗的RNN-T模型发布详细信息参阅[BAT](egs/aishell/bat)
- 2023.07.03: 中文离线文件转写服务一键部署的CPU版本发布详细信息参阅([一键部署文档](funasr/runtime/docs/SDK_tutorial_zh.md))
- 2023.06.26: ASRU2023 多通道多方会议转录挑战赛2.0完成竞赛结果公布,详细信息参阅([M2MeT2.0](https://alibaba-damo-academy.github.io/FunASR/m2met2_cn/index.html)

View File

@ -1,21 +1,21 @@
# FunASR实时语音写服务开发指南
# FunASR实时语音写服务开发指南
FunASR提供可便捷本地或者云端服务器部署的实时语音写服务内核为FunASR已开源runtime-SDK。
FunASR提供可便捷本地或者云端服务器部署的实时语音写服务内核为FunASR已开源runtime-SDK。
集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large非流式语音识别(ASR)、Paraformer-large流式语音识别(ASR)、标点(PUNC) 等相关能力。软件包既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求
本文档为FunASR实时转写服务开发指南。如果您想快速体验实时语音写服务,可参考[快速上手](#快速上手)。
本文档为FunASR实时转写服务开发指南。如果您想快速体验实时语音写服务,可参考[快速上手](#快速上手)。
## 快速上手
### 镜像启动
通过下述命令拉取并启动FunASR runtime-SDK的docker镜像
通过下述命令拉取并启动FunASR软件包的docker镜像
```shell
sudo docker pull registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.0
sudo docker run -p 10095:10095 -it --privileged=true -v /root:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.0
mkdir -p ./funasr-runtime-resources/models
sudo docker run -p 10095:10095 -it --privileged=true -v ./funasr-runtime-resources/models:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.0
```
如果您没有安装docker可参考[Docker安装](#Docker安装)
如果您没有安装docker可参考[Docker安装](https://alibaba-damo-academy.github.io/FunASR/en/installation/docker_zh.html)
### 服务端启动
@ -42,111 +42,31 @@ python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode 2pass
```
------------------
## Docker安装
下述步骤为手动安装docker环境的步骤
### docker环境安装
```shell
# Ubuntu
curl -fsSL https://test.docker.com -o test-docker.sh
sudo sh test-docker.sh
# Debian
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# CentOS
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# MacOS
brew install --cask --appdir=/Applications docker
```
安装详见https://alibaba-damo-academy.github.io/FunASR/en/installation/docker.html
### docker启动
```shell
sudo systemctl start docker
```
## 客户端用法详解
在服务器上完成FunASR服务部署以后可以通过如下的步骤来测试和使用离线文件转写服务。
目前分别支持以下几种编程语言客户端
- [Python](#python-client)
- [CPP](#cpp-client)
- [html网页版本](#Html网页版)
- [Java](#Java-client)
### python-client
若想直接运行client进行测试可参考如下简易说明以python版本为例
```shell
python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode 2pass --audio_in "../audio/asr_example.wav" --output_dir "./results"
```
命令参数说明:
```text
--host 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip
--port 10095 部署端口号
--mode`offline`表示推理模式为一句话识别;`online`表示推理模式为实时语音识别;`2pass`表示为实时语音识别,并且说话句尾采用离线模型进行纠错。
--chunk_size表示流式模型latency配置`[5,10,5]`表示当前音频解码片段为600ms并且回看300ms右看300ms。
--audio_in 需要进行转写的音频文件支持文件路径文件列表wav.scp
--thread_num 设置并发发送线程数默认为1
--ssl 设置是否开启ssl证书校验默认1开启设置为0关闭
```
### cpp-client
进入samples/cpp目录后可以用cpp进行测试指令如下
```shell
./funasr-wss-client-2pass --server-ip 127.0.0.1 --port 10095 --wav-path ../audio/asr_example.wav
```
命令参数说明:
```text
--server-ip 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip
--port 10095 部署端口号
--mode`offline`表示推理模式为一句话识别;`online`表示推理模式为实时语音识别;`2pass`表示为实时语音识别,并且说话句尾采用离线模型进行纠错。
--chunk-size表示流式模型latency配置`[5,10,5]`表示当前音频解码片段为600ms并且回看300ms右看300ms。
--wav-path 需要进行转写的音频文件,支持文件路径
--thread-num 设置并发发送线程数默认为1
--is-ssl 设置是否开启ssl证书校验默认1开启设置为0关闭
```
### Html网页版
在浏览器中打开 html/static/index.html即可出现如下页面支持麦克风输入与文件上传直接进行体验
<img src="images/html.png" width="900"/>
### Java-client
```shell
FunasrWsClient --host localhost --port 10095 --audio_in ./asr_example.wav --mode offline
```
详细可以参考文档([点击此处](../java/readme.md)
- [Python](./SDK_tutorial_online_zh.md#python-client)
- [CPP](./SDK_tutorial_online_zh.md#cpp-client)
- [html网页版本](./SDK_tutorial_online_zh.md#html-client)
- [Java](./SDK_tutorial_online_zh.md#java-client)
- [c\#](./SDK_tutorial_online_zh.md#c\#)
详细用法可以点击进入查看。更多版本客户端支持请参考[websocket/grpc协议](./websocket_protocol_zh.md)
## 服务端参数介绍:
funasr-wss-server支持从Modelscope下载模型设置模型下载地址--download-model-dir默认为/workspace/models及model ID--model-dir、--vad-dir、--punc-dir,示例如下:
funasr-wss-server-2pass支持从Modelscope下载模型或者从本地目录路径启动示例如下
```shell
cd /workspace/FunASR/funasr/runtime/websocket/build/bin
./funasr-wss-server-2pass \
--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-vad_realtime-vocab272727-onnx \
--decoder-thread-num 32 \
--io-thread-num 8 \
--port 10095 \
--certfile ../../../ssl_key/server.crt \
--keyfile ../../../ssl_key/server.key
--port 10095
```
命令参数介绍:
```text
--download-model-dir 模型下载地址通过设置model ID从Modelscope下载模型
@ -160,87 +80,15 @@ cd /workspace/FunASR/funasr/runtime/websocket/build/bin
--port 服务端监听的端口号,默认为 10095
--decoder-thread-num 服务端启动的推理线程数,默认为 8
--io-thread-num 服务端启动的IO线程数默认为 1
--certfile ssl的证书文件默认为../../../ssl_key/server.crt
--keyfile ssl的密钥文件默认为../../../ssl_key/server.key
--certfile ssl的证书文件默认为../../../ssl_key/server.crt,如需关闭,设置为""
--keyfile ssl的密钥文件默认为../../../ssl_key/server.key,如需关闭,设置为""
```
## 模型资源准备
执行上述指令后启动实时语音听写服务。如果模型指定为ModelScope中model id会自动从MoldeScope中下载如下模型
[FSMN-VAD模型](https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary)
[Paraformer-lagre实时模型](https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx/summary )
[Paraformer-lagre非实时模型](https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx/summary)
[CT-Transformer标点预测模型](https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx/summary)
如果您选择通过funasr-wss-server-2pass 从Modelscope下载模型可以跳过本步骤。
如果您希望部署您finetune后的模型例如10epoch.pb需要手动将模型重命名为model.pb并将原modelscope中模型model.pb替换掉将路径指定为`model_dir`即可
FunASR离线文件转写服务中的vad、asr和punc模型资源均来自Modelscope模型地址详见下表
| 模型 | Modelscope链接 |
|------|---------------------------------------------------------------------------------------------------------------|
| 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后的资源导出模型
### 从Modelscope导出ONNX模型
从Modelscope网站下载对应model name的模型然后导出量化后的ONNX模型
```shell
python -m funasr.export.export_model \
--export-dir ./export \
--type onnx \
--quantize True \
--model-name damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch \
--model-name damo/speech_fsmn_vad_zh-cn-16k-common-pytorch \
--model-name damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch
```
命令参数介绍:
```text
--model-name Modelscope上的模型名称例如damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
--export-dir ONNX模型导出地址
--type 模型类型,目前支持 ONNX、torch
--quantize int8模型量化
```
### 从finetune后的资源导出模型
假如您想部署finetune后的模型可以参考如下步骤
将您finetune后需要部署的模型例如10epoch.pb重命名为model.pb并将原modelscope中模型model.pb替换掉假如替换后的模型路径为/path/to/finetune/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch通过下述命令把finetune后的模型转成onnx模型
```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
### 自定义客户端:
如果您想定义自己的clientwebsocket通信协议为
```text
首次通信
message为需要用json序列化
{"mode": "offline", "wav_name": "wav_name", "is_speaking": True, "wav_format":"pcm", "chunk_size":[5,10,5]}
参数介绍:
`mode``offline`,表示推理模式为一句话识别;`online`,表示推理模式为实时语音识别;`2pass`:表示为实时语音识别,并且说话句尾采用离线模型进行纠错。
`wav_name`:表示需要推理音频文件名
`wav_format`表示音视频文件后缀名可选pcm、mp3、mp4等备注1.0版本只支持pcm音频流
`is_speaking`表示断句尾点例如vad切割点或者一条wav结束
`chunk_size`表示流式模型latency配置`[5,10,5]`表示当前音频为600ms并且回看300ms右看300ms。
`audio_fs`当输入音频为pcm数据时需要加上音频采样率参数
发送音频数据
直接将音频数据移除头部信息后的bytes数据发送支持音频采样率为8000016000
发送结束标志
音频数据发送结束后需要发送结束标志需要用json序列化
{"is_speaking": False}
```

View File

@ -11,9 +11,9 @@ SDK 支持以下几种服务部署:
- 英文离线转写服务,进行中
- 更多支持中
## 中文实时语音写服务CPU版本
## 中文实时语音写服务CPU版本
FunASR实时语音写服务软件包,既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求。
FunASR实时语音写服务软件包,既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求。
为了支持不同用户的需求,针对不同场景,准备了不同的图文教程:
### 便捷部署教程
@ -27,7 +27,7 @@ FunASR实时语音转写服务软件包既可以实时地进行语音转文
### 技术原理揭秘
文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高实时、高精度、高效率、长音频链路,详细文档参考([点击此处](https://mp.weixin.qq.com/s/8He081-FM-9IEI4D-lxZ9w)
文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高精度、高效率、长音频链路,详细文档参考([点击此处]()