This commit is contained in:
游雁 2023-06-30 22:55:31 +08:00
parent e387e4d4bf
commit 9799a7ba3b
3 changed files with 177 additions and 338 deletions

View File

@ -1,331 +0,0 @@
# FunASR离线文件转写服务便捷部署教程
FunASR提供可便捷本地或者云端服务器部署的离线文件转写服务内核为FunASR已开源runtime-SDK。集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large语音识别(ASR)、标点恢复(PUNC) 等相关能力,可以准确、高效的对音频进行高并发转写。
## 环境安装与启动服务
服务器配置与申请免费试用13个月[点击此处](./aliyun_server_tutorial.md)
### 获得脚本工具并一键部署
通过以下命令运行一键部署服务按照提示逐步完成FunASR runtime-SDK服务的部署和运行。目前暂时仅支持Linux环境其他环境参考文档[高阶开发指南](./SDK_advanced_guide_cn.md)
[//]: # (受限于网络funasr-runtime-deploy.sh一键部署工具的下载可能不顺利遇到数秒还未下载进入一键部署工具的情况请Ctrl + C 终止后再次运行以下命令。)
```shell
curl -O https://raw.githubusercontent.com/alibaba-damo-academy/FunASR/main/funasr/runtime/funasr-runtime-deploy.sh; sudo bash funasr-runtime-deploy.sh install
# 如遇到网络问题,中国大陆用户,可以用个下面的命令:
# curl -O https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/shell/funasr-runtime-deploy.sh; sudo bash funasr-runtime-deploy.sh install
```
#### 启动过程配置详解
##### 选择FunASR Docker镜像
推荐选择latest使用我们的最新镜像也可选择历史版本。
```text
[1/9]
Please choose the Docker image.
1) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest
2) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.1.0
Enter your choice: 1
You have chosen the Docker image: registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest
```
##### 选择ASR/VAD/PUNC模型
你可以选择ModelScope中的模型也可以选<model_name>自行填入ModelScope中的模型名将会在Docker运行时自动下载。同时也可以选择<model_path>填入宿主机中的本地模型路径。
```text
[2/9]
Please input [Y/n] to confirm whether to automatically download model_id in ModelScope or use a local model.
[y] With the model in ModelScope, the model will be automatically downloaded to Docker(/workspace/models).
If you select both the local model and the model in ModelScope, select [y].
[n] Use the models on the localhost, the directory where the model is located will be mapped to Docker.
Setting confirmation[Y/n]:
You have chosen to use the model in ModelScope, please set the model ID in the next steps, and the model will be automatically downloaded in (/workspace/models) during the run.
Please enter the local path to download models, the corresponding path in Docker is /workspace/models.
Setting the local path to download models, default(/root/models):
The local path(/root/models) set will store models during the run.
[2.1/9]
Please select ASR model_id in ModelScope from the list below.
1) damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
2) model_name
3) model_path
Enter your choice: 1
The model ID is damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
The model dir in Docker is /workspace/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
[2.2/9]
Please select VAD model_id in ModelScope from the list below.
1) damo/speech_fsmn_vad_zh-cn-16k-common-onnx
2) model_name
3) model_path
Enter your choice: 1
The model ID is damo/speech_fsmn_vad_zh-cn-16k-common-onnx
The model dir in Docker is /workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx
[2.3/9]
Please select PUNC model_id in ModelScope from the list below.
1) damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
2) model_name
3) model_path
Enter your choice: 1
The model ID is damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
The model dir in Docker is /workspace/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
```
##### 输入宿主机中FunASR服务可执行程序路径
输入FunASR服务可执行程序的宿主机路径Docker运行时将自动挂载到Docker中运行。默认不输入的情况下将指定Docker中默认的/workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server。
```text
[3/9]
Please enter the path to the excutor of the FunASR service on the localhost.
If not set, the default /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server in Docker is used.
Setting the path to the excutor of the FunASR service on the localhost:
Corresponding, the path of FunASR in Docker is /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server
```
##### 设置宿主机提供给FunASR的端口
设置提供给Docker的宿主机端口默认为10095。请保证此端口可用。
```text
[4/9]
Please input the opened port in the host used for FunASR server.
Default: 10095
Setting the opened host port [1-65535]:
The port of the host is 10095
The port in Docker for FunASR server is 10095
```
##### 设置FunASR服务的推理线程数
设置FunASR服务的推理线程数默认为宿主机核数同时自动设置服务的IO线程数为推理线程数的四分之一。
```text
[5/9]
Please input thread number for FunASR decoder.
Default: 1
Setting the number of decoder thread:
The number of decoder threads is 1
The number of IO threads is 1
```
##### 所有设置参数展示及确认
展示前面6步设置的参数确认则将所有参数存储到/var/funasr/config并开始启动Docker否则提示用户进行重新设置。
```text
[6/9]
Show parameters of FunASR server setting and confirm to run ...
The current Docker image is : registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest
The model is downloaded or stored to this directory in local : /root/models
The model will be automatically downloaded to the directory : /workspace/models
The ASR model_id used : damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
The ASR model directory corresponds to the directory in Docker : /workspace/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
The VAD model_id used : damo/speech_fsmn_vad_zh-cn-16k-common-onnx
The VAD model directory corresponds to the directory in Docker : /workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx
The PUNC model_id used : damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
The PUNC model directory corresponds to the directory in Docker: /workspace/models/damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx
The path in the docker of the FunASR service executor : /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server
Set the host port used for use by the FunASR service : 10095
Set the docker port used by the FunASR service : 10095
Set the number of threads used for decoding the FunASR service : 1
Set the number of threads used for IO the FunASR service : 1
Please input [Y/n] to confirm the parameters.
[y] Verify that these parameters are correct and that the service will run.
[n] The parameters set are incorrect, it will be rolled out, please rerun.
read confirmation[Y/n]:
Will run FunASR server later ...
Parameters are stored in the file /var/funasr/config
```
##### 检查Docker服务
检查当前宿主机是否安装了Docker服务若未安装则安装Docker并启动。
```text
[7/9]
Start install docker for ubuntu
Get docker installer: curl -fsSL https://test.docker.com -o test-docker.sh
Get docker run: sudo sh test-docker.sh
# Executing docker install script, commit: c2de0811708b6d9015ed1a2c80f02c9b70c8ce7b
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c install -m 0755 -d /etc/apt/keyrings
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
+ sh -c chmod a+r /etc/apt/keyrings/docker.gpg
+ sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal test" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
Version: 24.0.2
...
...
Docker install success, start docker server.
```
##### 下载FunASR Docker镜像
下载并更新step1.1中选择的FunASR Docker镜像。
```text
[8/9]
Pull docker image(registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest)...
funasr-runtime-cpu-0.0.1: Pulling from funasr_repo/funasr
7608715873ec: Pull complete
3e1014c56f38: Pull complete
...
...
```
##### 启动FunASR Docker
启动FunASR Docker等待step1.2选择的模型下载完成并启动FunASR服务。
```text
[9/9]
Construct command and run docker ...
943d8f02b4e5011b71953a0f6c1c1b9bc5aff63e5a96e7406c83e80943b23474
Loading models:
[ASR ][Done ][==================================================][100%][1.10MB/s][v1.2.1]
[VAD ][Done ][==================================================][100%][7.26MB/s][v1.2.0]
[PUNC][Done ][==================================================][100%][ 474kB/s][v1.1.7]
The service has been started.
If you want to see an example of how to use the client, you can run sudo bash funasr-runtime-deploy.sh -c .
```
#### 启动已经部署过的FunASR服务
一键部署后若出现重启电脑等关闭Docker的动作可通过如下命令直接启动FunASR服务启动配置为上次一键部署的设置。
```shell
sudo bash funasr-runtime-deploy.sh start
```
#### 关闭FunASR服务
```shell
sudo bash funasr-runtime-deploy.sh stop
```
#### 重启FunASR服务
根据上次一键部署的设置重启启动FunASR服务。
```shell
sudo bash funasr-runtime-deploy.sh restart
```
#### 替换模型并重启FunASR服务
替换正在使用的模型并重新启动FunASR服务。模型需为ModelScope中的ASR/VAD/PUNC模型或者从ModelScope中模型finetune后的模型。
```shell
sudo bash funasr-runtime-deploy.sh update model <model ID>
e.g
sudo bash funasr-runtime-deploy.sh update model damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
```
### 测试与使用离线文件转写服务
在服务器上完成FunASR服务部署以后可以通过如下的步骤来测试和使用离线文件转写服务。目前分别支持Python、C++、Java版本client的的命令行运行以及可在浏览器可直接体验的html网页版本更多语言client支持参考文档【FunASR高阶开发指南】。
funasr-runtime-deploy.sh运行结束后可通过命令以交互的形式自动下载测试样例samples到当前目录的funasr_samples中并设置参数运行
```shell
sudo bash funasr-runtime-deploy.sh client
```
可选择提供的Python和Linux C++范例程序以Python范例为例
```text
Will download sample tools for the client to show how speech recognition works.
Please select the client you want to run.
1) Python
2) Linux_Cpp
Enter your choice: 1
Please enter the IP of server, default(127.0.0.1):
Please enter the port of server, default(10095):
Please enter the audio path, default(/root/funasr_samples/audio/asr_example.wav):
Run pip3 install click>=8.0.4
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Requirement already satisfied: click>=8.0.4 in /usr/local/lib/python3.8/dist-packages (8.1.3)
Run pip3 install -r /root/funasr_samples/python/requirements_client.txt
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Requirement already satisfied: websockets in /usr/local/lib/python3.8/dist-packages (from -r /root/funasr_samples/python/requirements_client.txt (line 1)) (11.0.3)
Run python3 /root/funasr_samples/python/wss_client_asr.py --host 127.0.0.1 --port 10095 --mode offline --audio_in /root/funasr_samples/audio/asr_example.wav --send_without_sleep --output_dir ./funasr_samples/python
...
...
pid0_0: 欢迎大家来体验达摩院推出的语音识别模型。
Exception: sent 1000 (OK); then received 1000 (OK)
end
If failed, you can try (python3 /root/funasr_samples/python/wss_client_asr.py --host 127.0.0.1 --port 10095 --mode offline --audio_in /root/funasr_samples/audio/asr_example.wav --send_without_sleep --output_dir ./funasr_samples/python) in your Shell.
```
#### python-client
若想直接运行client进行测试可参考如下简易说明以python版本为例
```shell
python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" --send_without_sleep --output_dir "./results"
```
命令参数说明:
```text
--host 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip
--port 10095 部署端口号
--mode offline表示离线文件转写
--audio_in 需要进行转写的音频文件支持文件路径文件列表wav.scp
--output_dir 识别结果保存路径
```
#### cpp-client
```shell
export LD_LIBRARY_PATH=/root/funasr_samples/cpp/libs:$LD_LIBRARY_PATH
/root/funasr_samples/cpp/funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path /root/funasr_samples/audio/asr_example.wav
```
命令参数说明:
```text
--server-ip 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip
--port 10095 部署端口号
--wav-path 需要进行转写的音频文件,支持文件路径
```
### 视频demo
[点击此处]()

View File

@ -0,0 +1,170 @@
# FunASR离线文件转写服务便捷部署教程
FunASR提供可便捷本地或者云端服务器部署的离线文件转写服务内核为FunASR已开源runtime-SDK。
集成了达摩院语音实验室在Modelscope社区开源的语音端点检测(VAD)、Paraformer-large语音识别(ASR)、标点恢复(PUNC) 等相关能力,拥有完整的语音识别链路,可以将几十个小时的音频识别成带标点的文字,而且支持上百路并发同时进行识别。
## 服务器配置
用户可以根据自己的业务需求,选择合适的服务器配置,推荐配置为:
- 配置1: X86计算型4核vCPU内存8G单机可以支持大约32路的请求
- 配置2: X86计算型16核vCPU内存32G单机可以支持大约64路的请求
- 配置3: X86计算型64核vCPU内存128G单机可以支持大约200路的请求
详细性能测试报告:[点此链接](./benchmark_onnx_cpp.md)
云服务厂商针对新用户有3个月免费试用活动申请教程[点击此处](./aliyun_server_tutorial.md)
## 快速上手
通过以下命令运行一键部署服务按照提示逐步完成FunASR runtime-SDK服务的部署和运行。目前暂时仅支持Linux环境其他环境参考文档[高阶开发指南](./SDK_advanced_guide_cn.md)
```shell
curl -O https://raw.githubusercontent.com/alibaba-damo-academy/FunASR/main/funasr/runtime/funasr-runtime-deploy.sh; sudo bash funasr-runtime-deploy.sh install
# 如遇到网络问题,中国大陆用户,可以用个下面的命令:
# curl -O https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/shell/funasr-runtime-deploy.sh; sudo bash funasr-runtime-deploy.sh install
```
## 测试与使用
在服务器上完成FunASR服务部署以后可以通过如下的步骤来测试和使用离线文件转写服务。
目前分别支持以下几种编程语言客户端
- Python
- C++
- Java
- html网页版本
我们以Python语言客户端为例进行说明其他版本客户端请参考[开发指南]()
#### python-client
若想直接运行client进行测试可参考如下简易说明以python版本为例
```shell
python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" --send_without_sleep --output_dir "./results"
```
命令参数说明:
```text
--host 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip
--port 10095 部署端口号
--mode offline表示离线文件转写
--audio_in 需要进行转写的音频文件支持文件路径文件列表wav.scp
--output_dir 识别结果保存路径
```
[//]: # (#### cpp-client)
[//]: # ()
[//]: # (```shell)
[//]: # (export LD_LIBRARY_PATH=/root/funasr_samples/cpp/libs:$LD_LIBRARY_PATH)
[//]: # (/root/funasr_samples/cpp/funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path /root/funasr_samples/audio/asr_example.wav)
[//]: # (```)
[//]: # ()
[//]: # (命令参数说明:)
[//]: # ()
[//]: # (```text)
[//]: # (--server-ip 为FunASR runtime-SDK服务部署机器ip默认为本机ip127.0.0.1如果client与服务不在同一台服务器需要改为部署机器ip)
[//]: # (--port 10095 部署端口号)
[//]: # (--wav-path 需要进行转写的音频文件,支持文件路径)
[//]: # (```)
## 服务端常见操作介绍
### 启动已经部署过的FunASR服务
一键部署后若出现重启电脑等关闭Docker的动作可通过如下命令直接启动FunASR服务启动配置为上次一键部署的设置。
```shell
sudo bash funasr-runtime-deploy.sh start
```
### 关闭FunASR服务
```shell
sudo bash funasr-runtime-deploy.sh stop
```
### 重启FunASR服务
根据上次一键部署的设置重启启动FunASR服务。
```shell
sudo bash funasr-runtime-deploy.sh restart
```
### 替换模型并重启FunASR服务
替换正在使用的模型并重新启动FunASR服务。模型需为ModelScope中的ASR/VAD/PUNC模型或者从ModelScope中模型finetune后的模型。
```shell
sudo bash funasr-runtime-deploy.sh update model <model ID>
e.g
sudo bash funasr-runtime-deploy.sh update model damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
```
### 服务端启动过程配置详解
##### 选择FunASR Docker镜像
推荐选择latest使用我们的最新镜像也可选择历史版本。
```text
[1/9]
Please choose the Docker image.
1) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest
2) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.1.0
Enter your choice: 1
You have chosen the Docker image: registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest
```
##### 设置宿主机提供给FunASR的端口
设置提供给Docker的宿主机端口默认为10095。请保证此端口可用。
```text
[4/9]
Please input the opened port in the host used for FunASR server.
Default: 10095
Setting the opened host port [1-65535]:
The port of the host is 10095
The port in Docker for FunASR server is 10095
```
##### 设置FunASR服务的推理线程数
设置FunASR服务的推理线程数默认为宿主机核数同时自动设置服务的IO线程数为推理线程数的四分之一。
```text
[5/9]
Please input thread number for FunASR decoder.
Default: 1
Setting the number of decoder thread:
The number of decoder threads is 1
The number of IO threads is 1
```
## 视频demo
[点击此处]()

View File

@ -14,18 +14,18 @@ SDK 支持以下几种服务部署:
## 中文离线文件转写服务部署CPU版本
目前FunASR runtime-SDK-0.0.1版本已支持中文语音离线文件服务部署CPU版本拥有完整的语音识别链路可以将几十个小时的音频识别成带标点的文字而且支持上百路并发同时进行识别。
中文语音离线文件服务部署CPU版本拥有完整的语音识别链路可以将几十个小时的音频识别成带标点的文字而且支持上百路并发同时进行识别。
为了支持不同用户的需求,针对不同场景,准备了不同的图文教程:
为了支持不同用户的需求,我们分别针对小白与高阶开发者,准备了不同的图文教程:
### 便捷部署教程
适用场景为对服务部署SDK无修改需求部署模型来自于ModelScope或者用户finetune详细教程参考[点击此处](./docs/SDK_tutorial_cn.md)
### 技术原理揭秘
文档介绍了背后技术原理,识别准确率,计算效率等,以及核心优势介绍:便捷、高精度、高效率、长音频链路,详细文档参考([点击此处](https://mp.weixin.qq.com/s?__biz=MzA3MTQ0NTUyMw==&tempkey=MTIyNF84d05USjMxSEpPdk5GZXBJUFNJNzY0bU1DTkxhV19mcWY4MTNWQTJSYXhUaFgxOWFHZTZKR0JzWC1JRmRCdUxCX2NoQXg0TzFpNmVJX2R1WjdrcC02N2FEcUc3MDhzVVhpNWQ5clU4QUdqNFdkdjFYb18xRjlZMmc5c3RDOTl0U0NiRkJLb05ZZ0RmRlVkVjFCZnpXNWFBVlRhbXVtdWs4bUMwSHZnfn4%3D&chksm=1f2c3254285bbb42bc8f76a82e9c5211518a0bb1ff8c357d085c1b78f675ef2311f3be6e282c#rd)
### 便捷部署教程
### 开发指南
文档主要针对小白用户与初级开发者没有修改、定制需求支持从modelscope中下载模型部署也支持用户finetune后的模型部署详细教程参考[点击此处](./docs/SDK_tutorial_cn.md)
适用场景为对服务部署SDK有修改需求部署模型来自于ModelScope或者用户finetune详细文档参考[点击此处](./docs/SDK_advanced_guide_offline_cn.md)
### 高阶开发指南
文档主要针对高阶开发者需要对服务进行修改与定制支持从modelscope中下载模型部署也支持用户finetune后的模型部署详细文档参考[点击此处](./docs/SDK_advanced_guide_offline_cn.md)