diff --git a/README_zh.md b/README_zh.md index 282b2f161..c86d3dc23 100644 --- a/README_zh.md +++ b/README_zh.md @@ -31,7 +31,7 @@ FunASR希望在语音识别的学术研究和工业应用之间架起一座桥 ## 最新动态 -- 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)) diff --git a/funasr/runtime/docs/SDK_advanced_guide_online_zh.md b/funasr/runtime/docs/SDK_advanced_guide_online_zh.md index 8b5d35ca8..a56d334a0 100644 --- a/funasr/runtime/docs/SDK_advanced_guide_online_zh.md +++ b/funasr/runtime/docs/SDK_advanced_guide_online_zh.md @@ -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,默认为本机ip(127.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,默认为本机ip(127.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,即可出现如下页面,支持麦克风输入与文件上传,直接进行体验 - - - -### 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 - -### 自定义客户端: - -如果您想定义自己的client,websocket通信协议为: - -```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数据发送,支持音频采样率为80000,16000 -发送结束标志 -音频数据发送结束后,需要发送结束标志(需要用json序列化): -{"is_speaking": False} -``` diff --git a/funasr/runtime/readme_cn.md b/funasr/runtime/readme_cn.md index f0717b494..dd6cd817c 100644 --- a/funasr/runtime/readme_cn.md +++ b/funasr/runtime/readme_cn.md @@ -11,9 +11,9 @@ SDK 支持以下几种服务部署: - 英文离线转写服务,进行中 - 更多支持中 -## 中文实时语音转写服务(CPU版本) +## 中文实时语音听写服务(CPU版本) -FunASR实时语音转写服务软件包,既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求。 +FunASR实时语音听写服务软件包,既可以实时地进行语音转文字,而且能够在说话句尾用高精度的转写文字修正输出,输出文字带有标点,支持高并发多路请求。 为了支持不同用户的需求,针对不同场景,准备了不同的图文教程: ### 便捷部署教程 @@ -27,7 +27,7 @@ FunASR实时语音转写服务软件包,既可以实时地进行语音转文 ### 技术原理揭秘 -文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高实时、高精度、高效率、长音频链路,详细文档参考([点击此处](https://mp.weixin.qq.com/s/8He081-FM-9IEI4D-lxZ9w)) +文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高精度、高效率、长音频链路,详细文档参考([点击此处]())