FreeSWITCH 简单图形化界面46 - 收集打包的一些ASR服务
- 0、一个fs的web配置界面预览
- 1、docker地址
- 2、使用
- 2.1 下载
- 2.2 运行
- 3、例子
- 3.1 下载
- 3.2 启动
- 3.3 编译mod_audio_fork或者mod_audio_stream模块使用
- 3.4 编写呼叫路由和呼叫脚本
- 呼叫路由
- 呼叫脚本
- 3.5 esl捕获识别结果
- 3.6 其他处理
- 3.7 测试视频参考
0、一个fs的web配置界面预览
http://myfs.f3322.net:8020/
用户名:admin,密码:admin
FreeSWITCH界面安装参考:https://blog.csdn.net/jia198810/article/details/137820796
1、docker地址
registry.cn-hangzhou.aliyuncs.com/pbx/asr-47m latest 616 MB
registry.cn-hangzhou.aliyuncs.com/pbx/asr-14m latest 588 MB
registry.cn-hangzhou.aliyuncs.com/pbx/asr-124m latest 653 MB
registry.cn-hangzhou.aliyuncs.com/pbx/my-funasr latest 6.5G
2、使用
2.1 下载
# 下载对应的asr地址
podman pull registry.cn-hangzhou.aliyuncs.com/pbx/asr-124m
2.2 运行
# asr-124m 中英文 124M
# sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13
# 启动 -v为热词,可选,-e为变量,NUM_THREADS为最大线程,可选,下面的都一样
podman run -itd -p 8000:8000/tcp -v /root/hotwords.txt:/root/hotwords.txt -e NUM_THREADS=4 --name asr-124m asr-124m
# 查看日志
podman exec -it asr-124m tail -f /var/log/asr.log # asr-14m 中文 14M
# sherpa-ncnn-streaming-zipformer-zh-14m-2023-02-23-chinese
podman run -itd -p 8000:8000/tcp -v /root/hotwords.txt:/root/hotwords.txt -e NUM_THREADS=4 --name asr-14m asr-14m# asr-47m 中英文 47M
# sherpa-ncnn-streaming-zipformer-small-bilingual-zh-en-2023-02-16-bilingual-chinese-english
podman run -itd -p 8000:8000/tcp -v /root/hotwords.txt:/root/hotwords.txt -e NUM_THREADS=4 --name asr-47m asr-47m# Funasr 启动较慢
# 可以进入容器netstat -tnlp是否启动8000和10095 ,
#`offline`表示推理模式为一句话识别;
#`online`表示推理模式为实时语音识别;
#`2pass`表示为实时语音识别,并且说话句尾采用离线模型进行纠错;
# 用online吧,online效果还是可以的
podman run -itd -p 8000:8000 -p 10095:10095 -e MODE='online' -v /root/hotwords.txt:/workspace/models/hotwords.txt --name my-funasr my-funasr
3、例子
3.1 下载
root@xiaojia-ts /h/xiaojia# podman pull registry.cn-hangzhou.aliyuncs.com/pbx/asr-124m (base)
Trying to pull registry.cn-hangzhou.aliyuncs.com/pbx/asr-124m:latest...
Getting image source signatures
Copying blob fcbb30fb83d0 done |
Copying blob 5b4de9788e44 skipped: already exists
Copying blob f686e60318db done |
Copying blob 095f960760ee skipped: already exists
Copying blob 6721db44a395 done |
Copying config 8e4c94354d done |
Writing manifest to image destination
8e4c94354db2df8a0dea58c552e616afcc660acad95bd940f280c193129ab908
3.2 启动
root@xiaojia-ts /h/xiaojia# podman run -itd -p 8000:8000/tcp -e NUM_THREADS=4 --name asr-124m asr-124m (base)
96878427c8d4e1b0b2bf4fe96386c253d10f95eac12fa32af4066747b4d2d231
3.3 编译mod_audio_fork或者mod_audio_stream模块使用
参考下面的地址,编译该模块,如果安装了图形化界面,自动mod_audio_fork模块。
https://gitee.com/rasonyang/drachtio-freeswitch-modules/blob/main/modules/mod_audio_fork/README.md
https://github.com/amigniter/mod_audio_stream
编译完成后,加载模块
freeswitch@MyFs> load mod_audio_fork
+OK Reloading XML
+OK
mod_audio_fork对应的api为
uuid_audio_fork <uuid> start <wss-url> <mix-type> <sampling-rate> <metadata>
3.4 编写呼叫路由和呼叫脚本
呼叫路由
<extension name="11120-自定义ASR"><condition expression="^(11120)$" field="destination_number"><action application="python" data="handle-asr"/><action application="hangup"/></condition>
</extension>
呼叫脚本
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*-
"""
处理语音识别结果
"""from freeswitch import *
import refsapi = API()def handler(session, args):# 接通session.answer()# 获取uuiduuid = session.getVariable("uuid")# 执行api,把该uuid的audio发送到asr地址的8000(上面的容器映射的端口),单声道mono,采样率16kcmd = "uuid_audio_fork {} start ws://192.168.1.70:8000/ mono 16k".format(uuid)fsapi.executeString(cmd)# 超时时间session.sleep(30000)
3.5 esl捕获识别结果
连接esl,获取"Event-Subclass": "mod_audio_fork::json"
事件,_body
为识别内容。
{"Event-Subclass": "mod_audio_fork::json","Event-Name": "CUSTOM","Core-UUID": "5788c155-5b0e-48c9-8ec8-accd46623a0b","FreeSWITCH-Hostname": "localhost.localdomain","FreeSWITCH-Switchname": "MyFs","FreeSWITCH-IPv4": "192.168.1.20","FreeSWITCH-IPv6": "::1","中间很多内容,略过......""variable_playback_seconds": "1","variable_playback_ms": "1000","variable_playback_samples": "8000","Content-Length": "144","Content-Length": "144","_body": "{\"text\":\"今天是205年8月2号然后我在测试一个语音识别程序我主要想看一下原始月的准确度\",\"timestamp\":1754120626173}"
}
3.6 其他处理
识别结果拿到后,解析body内容,可以在esl里编写程序,进行其他处理。
3.7 测试视频参考
下面为这个registry.cn-hangzhou.aliyuncs.com/pbx/asr-124m
的测试结果
FreeSWITCH asr测试
祝君成功,好运连连