# freeswitch_unimrcp_patch
**Repository Path**: yuanxueqing/freeswitch_unimrcp_patchf
## Basic Information
- **Project Name**: freeswitch_unimrcp_patch
- **Description**: freeswitch补丁, mrcpserver安装包/补丁
- **Primary Language**: Unknown
- **License**: LGPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 3
- **Created**: 2023-04-21
- **Last Updated**: 2025-03-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 1. freeswitch patch
## 1.1 介绍
freeswitch补丁
## 1.2 软件架构
补丁在/freeswitch_unimrcp_patchf/freeswitch_patch目录下
## 1.3 安装教程
### 把提供的补丁分别替换freeswitch如下目录的文件
- /usr/local/freeswitch/lib/libfreeswitch.so.1.0.0
- /usr/local/freeswitch/mod/mod_dptools.so
- /usr/local/freeswitch/mod/mod_unimrcp.so
- /usr/local/freeswitch/conf/autoload_configs/unimrcp.conf.xml
- /usr/local/freeswitch/conf/mrcp_profiles/unimrcpserver-mrcp-v2.xml
```
```
## 1.4 功能说明
### 1.4.1 承接句
* 设置通道变量long_short_speech_switch为true则开启承接句/长短停顿功能,系统默认值为false。
* 调用play_and_detect_speech之前把承接句传给通道变量continuation_statement,承接句参数的解析同playback。
* play_and_detect_speech调用结束会自动把long_short_speech_switch设为false,continuation_statement设为空,这两个通道变量设置后只起一次效果,每次调用play_and_detect_speech都要设。
```
```
### 1.4.2 打断
playback不可打断,play_and_detect_speech可打断。
### 1.4.3 MRCP/VAD参数
```
MRCPV2协议RFC6787
https://www.rfc-editor.org/rfc/rfc6787.html#page-120
```
#### 1.4.3.1 start-input-timers
- false表示不统计无声超时。
- true表示开始统计无声超时,如果超过no_input_timeout则mrcpserver会触发一个超时事件发给mrcpclient。
- 调用play_and_detect_speech传start-input-timers=false,表示不统计无声超时,如果play被打断也没必要再统计无声超时, 如果play正常播放结束依然没有检测到打断事件,那么play_and_detect_speech就会发送一个事件把start-input-timers为true告诉mrcpserver让其开始统计无声超时,如果在no_input_timeout时间内依然未检测声音则产生no-input-timeout事件给mrcpclient,这是目前我们项目中的逻辑。
#### 1.4.3.2 sensitivity-level
- 前端点检测时间,一般配置100-300/ms,300ms对检测单字效果差,比如说"喂"检测不到,200ms可以。
- 该参数透传给mrcpserver的vad模块,作为前端点有声检测时长参数,也就是刘博说的min_speak_ms。
- 注:该参数目前服务器是写死的,因为传错了流程调试进行不下去。
#### 1.4.3.3 speech-complete-timeout
短停顿,单位/ms, 说话换气一句话未结束,短停顿时TTS合成已经开始,如果紧接着是长停顿那么可以加快TTS合成速度
#### 1.4.3.4 speech-incomplete-timeout
长停顿,单位/ms, 一句话结束
#### 1.4.3.5 no-input-timeout
无声超时,单位/ms
### 1.4.4 语法参数
```
builtin:grammar/boolean?language=en-US;y=1;n=2
```
该参数没什么意义,如果不传,play_and_detect_speech解析此参数时会导致调用失败。
### 1.4.5 play_and_detect_speech调用示例
```
```
### 1.4.6 lua阻塞语音解决
lua与引擎交互的问题需要设置通道变量get_play_and_detect_speech_param_from_engine,交互前设置true,交互后设置false
```
session:execute("set","get_play_and_detect_speech_param_from_engine=true");
response_body = send2vmdivr_playbackresult(req);
session:execute("set","get_play_and_detect_speech_param_from_engine=false");
```
### 1.4.7 兼容思必驰
- unimrcpserver-mrcp-v2.xml 中的ptime改为20。
- 不开启长短停顿、承接句功能。
- 开启防lua阻塞功能。
# 2. unimrcp server
## 2.1 介绍
mrcpserver安装包,在/freeswitch_unimrcp_patchf/unimrcp目录下
## 2.2 安装教程
### 2.2.1 部署
unimrcp文件夹拷贝到/usr/local/目录下
### 2.2.2 tts.json
```
{
"tts_server": "ws://192.168.26.82:8090/paddlespeech/tts/streaming",
"tts_record_audio": 0
}
```
| name | description |
|---|---|
| tts_server| tts流式识别服务器 |
| tts_record_audio| 1=录音 0=不录音 |
### 2.2.3 asr.json
```
{
"asr_server": "ws://192.168.26.85:8090/paddlespeech/asr/streaming",
"asr_max_connection": 10,
"asr_record_audio": 0,
"sensitivity_level": 200,
"speech_complete_timeout": 500,
"speech_incomplete_timeout": 1200,
"no_input_timeout": 7000,
"onnx_file": "silero_vad.onnx"
}
```
| name | description |
|---|---|
| asr_server | asr流式识别服务器 |
| asr_max_connection | asr plugin最大支持路数 |
| asr_record_audio | 1=录音 0=不录音 |
| sensitivity_level | 前端点检测时长默认值 |
| speech_complete_timeout | 短停顿默认值 |
| speech_incomplete_timeout | 长停顿默认值 |
| no_input_timeout | 无声超时默认值 |
| onnx_file | 模型文件名称 |
sensitivity_level, speech_complete_timeout, speech_incomplete_timeout, no_input_timeout, onnx_file 参数是为了防止用户不传时默认使用的默认值
### 2.2.4 unimrcpserver.xml
```
192.168.4.7
32
```
注意:对接网经ptime是32,思必驰ptime是20,ptime一定要匹配,否则会造成内存拷贝踩踏而容易崩溃。
#### 2.2.5 以服务方式运行
- 把unimrcp.service拷贝到/etc/systemd/system/目录下,执行systemctl daemon-realod加载服务配置脚本。
- systemctl start unimrcp.service 启动服务
- systemctl stop unimrcp.service 暂停服务
- systemctl restart unimrcp.service 重启服务
- systemctl enable unimrcp.service 开机启动服务
- systemctl disable unimrcp.service 取消开机启动
#### 2.2.6 监控服务
- 把unimrcp.timer拷贝到/etc/systemd/system/目录下,执行systemctl daemon-realod加载服务配置脚本。
- 执行systemctl start unimrcp.timer 启动unimrcp.timer服务,这样只要unimrcp服务或者unimrcpserver进程挂掉了就会尝试启动该服务。
- 执行systemctl enable unimrcp.timer设为开机启动,这样就可以永久实现监控服务了。
- 修改unimrcp.timer中的OnUnitActiveSec参数再执行systemctl daemon-reload即可改变监控时间间隔,OnUnitActiveSec=4s代表每隔4秒内如果服务挂掉了立马拉起来,假如配置是4s,服务器已经正常运行4s或者大于4s突然挂掉,服务会被迅速拉起,如果刚拉起又瞬间挂掉,之后才会等4s才尝试拉起。
# 3. mrcpserver稳定性测试脚本
## 3.1 介绍
用于批量测试unimrcpserver的稳定性,在/freeswitch_unimrcp_patchf/test目录下
## 3.2 安装教程
### 3.2.1 添加拨号方案
08_base_diaplan.xml中添加如下拨号方案
```
```
eavesdrop用于监听,因为是监听所有,所以适合监听单路的情况。111是与机器人对话的拨号方案,对话录音是/root/jubao.wav。
注意这2个拨号方案不要被其它的拨号方案拦截了。
### 3.2.2 拷贝录音和脚本
jubao.wav和mrcpserver_test.sh拷贝到/root/目录下
### 3.2.3 执行
```
sh mrcpserver_test.sh -f 10 -t 2
```
每隔1秒发起一次通话,一次发起10 * 2 = 20次
## 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
## 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)