当前位置: 首页 > news >正文

FunASR搭建语音识别服务和VAD检测

搭建ASR语音识别服务(含VAD检测)教程

在本文中,我将为大家详细介绍如何搭建一套基于FunASR的ASR(语音识别)服务,并集成VAD(语音活动检测)。该服务使用阿里达摩院的模型,并支持SSL连接、2pass模式以及语音热词处理。我们将一步步讲解如何启动服务、调整VAD参数,以及使用Python客户端请求识别。

1. 环境准备

首先,确保你的服务器已经安装好docker。

你还需要从阿里云上下载相关的语音识别模型、VAD模型、标点符号模型等。这些模型是由达摩院发布的,具体的模型目录稍后会在启动命令中给出。
官方教程:
https://github.chat.carlife.host/modelscope/FunASR/blob/main/runtime/docs/SDK_advanced_guide_online_zh.md

2. 启动ASR服务

镜像启动
通过下述命令拉取并启动FunASR软件包的docker镜像:

sudo docker pull \registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.10
mkdir -p ./funasr-runtime-resources/models
sudo docker run -p 10096:10095 -it --privileged=true \-v $PWD/funasr-runtime-resources/models:/workspace/models \registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.10

首先进入工作目录:

cd /workspace/FunASR/runtime

在启动服务时,我们有两种选择:启用SSL不启用SSL

2.1 不启用SSL

如果你不需要SSL,可以将certfile设置为0,但注意此时客户端只能通过ws协议请求,而不能使用wss。启动命令如下:

nohup bash run_server_2pass.sh \--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 \--lm-dir damo/speech_ngram_lm_zh-cn-ai-wesp-fst \--itn-dir thuduj12/fst_itn_zh \--certfile 0 \--keyfile ../../../ssl_key/server.key \--hotword ../../hotwords.txt > log.txt 2>&1 &
2.2 启用SSL

若希望启用SSL保护通信,可以提供SSL证书和密钥。启动命令如下:

nohup bash run_server_2pass.sh \--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 \--lm-dir damo/speech_ngram_lm_zh-cn-ai-wesp-fst \--itn-dir thuduj12/fst_itn_zh \--certfile ../../../ssl_key/server.crt \--keyfile ../../../ssl_key/server.key \--hotword ../../hotwords.txt > log.txt 2>&1 &

3. Python请求示例

启动服务后,可以通过Python客户端发送请求。以下是使用funasr_wss_client.py的示例代码:

如果开启了https

python funasr_wss_client.py --host "xx.xx.xx.xx" --port 10096 --mode 2pass

如果没开启https

python funasr_wss_client.py --host "xx.xx.xx.xx" --port 10096 --mode 2pass --ssl 0

这里需要确保你的客户端主机和端口设置正确,并且使用的是2pass模式。

4. 调整VAD参数

1. 查找VAD模型的配置文件

FunASR中的VAD模型为FSMN-VAD,参数配置类为VADXOptions,可以在以下路径中找到:

/workspace/FunASR/runtime/python/onnxruntime/funasr_onnx/utils/e2e_vad.py

其中,VADXOptions类定义了多个VAD参数。以下是一些常见参数的定义:

class VADXOptions:sample_rate: int = 16000detect_mode: int = VadDetectMode.kVadMutipleUtteranceDetectMode.valuesnr_mode: int = 0max_end_silence_time: int = 800max_start_silence_time: int = 3000do_start_point_detection: bool = Truedo_end_point_detection: bool = Truewindow_size_ms: int = 200sil_to_speech_time_thres: int = 150speech_to_sil_time_thres: int = 150speech_2_noise_ratio: float = 1.0do_extend: int = 1lookback_time_start_point: int = 200lookahead_time_end_point: int = 100max_single_segment_time: int = 60000

这些参数控制了VAD的静音检测、语音与噪音之间的比率等。具体参数意义如下:

  • max_single_segment_time:单段音频的最大时长,默认60000毫秒(1分钟)。
  • max_end_silence_time:检测到结束静音的最大时长,默认800毫秒。
  • max_start_silence_time:检测到开始静音的最大时长,默认3000毫秒。
  • sil_to_speech_time_thres:从静音到语音的时间阈值,默认150毫秒。
  • speech_to_sil_time_thres:从语音到静音的时间阈值,默认150毫秒。
2. 修改VAD配置

VAD模型的实际配置是从模型目录中的config.yaml文件读取的。可以在以下路径找到config.yaml文件:

/workspace/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/config.yaml

config.yaml文件中的model_conf字段包含了VAD模型的详细配置:

model: FsmnVADStreaming
model_conf:sample_rate: 16000detect_mode: 1snr_mode: 0max_end_silence_time: 800max_start_silence_time: 3000do_start_point_detection: Truedo_end_point_detection: Truewindow_size_ms: 200sil_to_speech_time_thres: 150speech_to_sil_time_thres: 150speech_2_noise_ratio: 1.0do_extend: 1lookback_time_start_point: 200lookahead_time_end_point: 100max_single_segment_time: 60000
3. 修改参数示例

假设你想减少静音端点的检测时间,可以将max_end_silence_time的默认值从800毫秒改为600毫秒。只需编辑config.yaml文件,将以下行:

max_end_silence_time: 800

改为:

max_end_silence_time: 600

这样,你的VAD模型将在600毫秒后检测到结束静音,适用于需要更快速响应的语音识别场景。

结论

通过调整FunASR的VAD参数,你可以根据具体需求定制VAD的检测灵敏度和时长。在本教程中,我们通过修改config.yaml文件,调整了VAD的max_end_silence_time参数。希望本教程对你有所帮助,如果有任何问题,欢迎留言讨论!

http://www.lryc.cn/news/435202.html

相关文章:

  • 设计一个支持多线程写入的并发日志记录系统:C++实战指南
  • 使用LSTM(长短期记忆网络)模型预测股票价格的实例分析
  • 开源的 Windows 12 网页体验版!精美的 UI 设计、丰富流畅的动画
  • chapter14-集合——(List)——day18
  • Frida 脚本抓取 HttpURLConnection 请求和响应
  • Java实现建造者模式和源码中的应用
  • Windows安装docker
  • SprinBoot+Vue校园车辆管理系统的设计与实现
  • 【C语言进阶】C语言动态内存管理:深入理解malloc、calloc与realloc
  • Java+控制台 图书管理系统
  • gi清除无用缓存
  • 云PLM系统对企业影响有哪些?解析云PLM系统的作用
  • 四、查找算法
  • 果蔬识别系统性能优化之路(三)
  • 时序预测|基于小龙虾优化高斯过程GPR数据回归预测Matlab程序COA-GPR 多特征输入单输出 附赠基础GPR
  • C#进阶-快速了解IOC控制反转及相关框架的使用
  • C++内存布局
  • 【Linux 19】线程概念
  • [区间dp]添加括号
  • jenkins流水线+k8s部署springcloud微服务架构项目
  • 安卓开发板_联发科MTK开发评估套件串口调试
  • vue+el-table 可输入表格使用上下键进行input框切换
  • 中国书法——孙溟㠭浅析碑帖《三希堂法帖》
  • 深入探讨生成对抗网络(GANs):颠覆传统的AI创作方式
  • vmware Vnet8虚拟网卡丢失的找回问题
  • Python 从入门到实战13(字符串简介)
  • Redis_RDB持久化
  • SOP流程制定:vioovi ECRS工时分析软件的智慧引领
  • 并发编程-synchronized解决原子性问题
  • CSS之我不会