【语音识别】在Win11使用Docker部署FunASR服务器

在 Win11 使用 Docker 部署 FunASR 服务器

该文章因官网文档不详细故写的经验论
官网文章:https://github.com/alibaba-damo-academy/FunASR/blob/main/runtime/docs/SDK_advanced_guide_online_zh.md
且官网只针对 Linux/Max 系统出的教程,故利用Win11记录

镜像启动

docker pull registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.9
mkdir D://FunASR//model
docker run -p 10095:10095 -it --privileged=true -v D:/FunASR/model:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.9

docker pull 拉取镜像
docker run 启动镜像
-p 10095:10095 将容器内部的端口 10095 映射到宿主机的端口 10095
-it 分配一个伪终端并保持标准输入打开
--privileged=true 赋予容器特权,允许它执行特权操作,如访问宿主机的硬件设备等
-v D:/FunASR/model:/workspace/models 将本地文件系统中的 D:/FunASR/model 目录挂载到容器内的 /workspace/models 目录,实现本地文件与容器内部的文件共享
registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.9 拉取下来的镜像

服务端启动

docker启动之后,启动 funasr-wss-server-2pass服务程序:

cd FunASR/runtime
nohup bash run_server_2pass.sh \
  --certfile 0  \
  --download-model-dir /workspace/models \
  --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx \
  --model-dir damo/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-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 \
  --itn-dir thuduj12/fst_itn_zh > log.txt 2>&1 &
# 如果您想关闭ssl,增加参数:--certfile 0
# 如果您想使用时间戳或者nn热词模型进行部署,请设置--model-dir为对应模型:
#   damo/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-onnx(时间戳)
#   damo/speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404-onnx(nn热词)
# 如果您想在服务端加载热词,请在宿主机文件./funasr-runtime-resources/models/hotwords.txt配置热词(docker映射地址为/workspace/models/hotwords.txt):
#   每行一个热词,格式(热词 权重):阿里巴巴 20(注:热词理论上无限制,但为了兼顾性能和效果,建议热词长度不超过10,个数不超过1k,权重1~100)

run_server_2pass.sh命令参数介绍

--download-model-dir 模型下载地址,通过设置model ID从Modelscope下载模型
--model-dir  modelscope model ID 或者 本地模型路径
--online-model-dir  modelscope model ID 或者 本地模型路径
--vad-dir  modelscope model ID 或者 本地模型路径
--punc-dir  modelscope model ID 或者 本地模型路径
--lm-dir modelscope model ID 或者 本地模型路径
--itn-dir modelscope model ID 或者 本地模型路径
--port  服务端监听的端口号,默认为 10095
--decoder-thread-num  服务端线程池个数(支持的最大并发路数),
                      脚本会根据服务器线程数自动配置decoder-thread-num、io-thread-num
--io-thread-num  服务端启动的IO线程数
--model-thread-num  每路识别的内部线程数(控制ONNX模型的并行),默认为 1,
                    其中建议 decoder-thread-num*model-thread-num 等于总线程数
--certfile  ssl的证书文件,默认为:../../../ssl_key/server.crt,如果需要关闭ssl,参数设置为0
--keyfile   ssl的密钥文件,默认为:../../../ssl_key/server.key
--hotword   热词文件路径,每行一个热词,格式:热词 权重(例如:阿里巴巴 20),
            如果客户端提供热词,则与客户端提供的热词合并一起使用,服务端热词全局生效,客户端热词只针对对应客户端生效。

监控服务端日志

tail -f /workspace/FunASR/runtime/log.txt

在这里插入图片描述

下载测试案例

开启服务的终端不关闭,另开一个终端用于下载示例

# 查看运行的容器
docker ps 
CONTAINER ID   IMAGE                                                                                      COMMAND       CREATED          STATUS          PORTS                      NAMES
0c81b11d2791   registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.9   "/bin/bash"   19 minutes ago   Up 19 minutes   0.0.0.0:10095->10095/tcp   inspiring_banzai
# 另开终端
docker exec -it 0c81b11d2791 /bin/bash
# 下载示例
 wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/sample/funasr_samples.tar.gz

使用测试案例

打开基于 HTML 的案例

# 在 /workspace/models 目录下创建一个目录 funasr_samples
mkdir /workspace/models/funasr_samples
# 解压文件到 /workspace/models/funasr_samples 目录下
tar -xzf funasr_samples.tar.gz -C /workspace/models/funasr_samples

前面镜像启动时,我们将容器的目录 /workspace/models 挂载到了宿主机的 D:/FunASR/model 下面,因此下载到 /workspace/models/funasr_samples 目录里面的内容,可以在 D:/FunASR/model 上面看到
在这里插入图片描述

连接ASR服务端

修改asr服务器地址为 ws://127.0.0.1:10095/,因为没有开启 SSL,所以不是 wss 而是 ws,使用本地地址 127.0.0.1,端口号为镜像启动时配置的,与宿主机映射的端口号对应
在这里插入图片描述

关闭FunASR服务

# 查看 funasr-wss-server-2pass 对应的PID
ps -x | grep funasr-wss-server-2pass
 133 pts/0    Sl     0:18 /workspace/FunASR/runtime/websocket/build/bin/funasr-wss-server-2pass --download-model-dir /workspace/models --model-dir damo/speech_paraformer-large-vad-punc_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 --itn-dir thuduj12/fst_itn_zh --lm-dir damo/speech_ngram_lm_zh-cn-ai-wesp-fst --decoder-thread-num 8 --model-thread-num 1 --io-thread-num 1 --port 10095 --certfile  --keyfile  --hotword /workspace/FunASR/runtime/websocket/hotwords.txt
 2106 pts/1    S+     0:00 grep --color=auto funasr-wss-server-2pass
# 关闭进程
kill -9 133

在这里插入图片描述

注意事项

Tip:当你关闭了服务端,再次启动时,报 asio listen error: asio.system:98 (Address already in use) 错误,并不影响客户端访问服务端。

  • 15
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hjhcos

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值