欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > FunASR搭建语音识别服务和VAD检测

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

2024/10/25 2:29:52 来源:https://blog.csdn.net/u012960155/article/details/142108347  浏览:    关键词: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参数。希望本教程对你有所帮助,如果有任何问题,欢迎留言讨论!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com