深圳安嘉建设有限公司网站,舞阳专业做网站,用模版做网站的好处和坏处,做旅游攻略的网站好文章目录 1. 写在前面2. MRCP Server 配置与测试2.1 MRCP Server 配置2.2 MRCP Server 测试 3. FreeSwitch 配置3.1. 配置 mrcp profile3.2. 配置 mrcp conf3.3. 配置拨号任务 4. 效果测试 1. 写在前面 上一篇文章中#xff0c;对MRCP Server的开发进行了介绍#xff0c;下面… 文章目录 1. 写在前面2. MRCP Server 配置与测试2.1 MRCP Server 配置2.2 MRCP Server 测试 3. FreeSwitch 配置3.1. 配置 mrcp profile3.2. 配置 mrcp conf3.3. 配置拨号任务 4. 效果测试 1. 写在前面 上一篇文章中对MRCP Server的开发进行了介绍下面讲解如何通过配置让FreeSWITCH能够与MRCP Server进行对接获得电话呼叫的语音识别结果。
2. MRCP Server 配置与测试
2.1 MRCP Server 配置
cd /usr/local/unimrcp/conf
vim unimrcpserver.xml以下xml只展示了需要进行调整的部分将*.so的名称添加到配置文件中enabletrue
!-- Factory of plugins (MRCP engines) --
plugin-factoryengine idDemo-Synth-1 namedemosynth enablefalse/engine idXFyun-Synth-1 namexfyunsynth enabletrue/engine idDemo-Recog-1 namedemorecog enablefalse/!--engine idXFyun-Recog-1 namexfyunrecog enabletrue/--engine idXxx-Recog-1 nameXxxRecog enabletrue/engine idDemo-Verifier-1 namedemoverifier enabletrue/engine idRecorder-1 namemrcprecorder enabletrue/
/plugin-factory2.2 MRCP Server 测试 完成配置后启动UniMRCP Server
cd /usr/local/unimrcp/bin
./unimrcpserver -o 3运行结果如下图 启动UniMRCP Client输入run recog进行测试。
cd /usr/local/unimrcp/bin
./unimrcpclient
help
usage:- run [app_name] [profile_name] (run demo application)app_name is one of synth, recog, bypass, discoverprofile_name is one of uni2, uni1, ...examples: run synthrun recogrun synth uni1run recog uni1- loglevel [level] (set loglevel, one of 0,1...7)- quit, exit3. FreeSwitch 配置
3.1. 配置 mrcp profile 创建新的 mrcp服务连接的 配置文件 xiaoi-mrcp-v2.xml
cd /usr/local/freeswitch/conf/mrcp_profiles
vim xiaoi-mrcp-v2.xmlinclude!-- UniMRCP Server MRCPv2 --!-- 后面我们使用该配置文件均使用 name 作为唯一标识而不是文件名 --profile namexiaoi-mrcp-v2 version2!-- MRCP 服务器地址 --param nameserver-ip value192.168.160.2/!-- MRCP SIP 端口号 --param nameserver-port value8060/param nameresource-location value/!-- FreeSWITCH IP、端口以及 SIP 传输方式 --param nameclient-ip value192.168.160.58/!-- 注意当配置多个mrcp server的时候该端口不能冲突否则可能不可用 --param nameclient-port value5089/param namesip-transport valueudp/param namespeechsynth valuespeechsynthesizer/param namespeechrecog valuespeechrecognizer/!--param namertp-ext-ip valueauto/--param namertp-ip value192.168.160.58/param namertp-port-min value4000/param namertp-port-max value5000/param namecodecs valuePCMU PCMA L16/96/8000/!-- Add any default MRCP params for SPEAK requests here --synthparams/synthparams!-- Add any default MRCP params for RECOGNIZE requests here --recogparams!--param namestart-input-timers valuefalse/--/recogparams/profile
/include3.2. 配置 mrcp conf 配置/usr/local/freeswitch/conf/autoload_configs/unimrcp.conf.xml文件
cd /usr/local/freeswitch/conf/autoload_configs
vim unimrcp.conf.xml配置文件如下al-unimrcpv2为默认的进行注释下面配置中只配置了xiaoi-mrcp-v2注意该名字与1配置的xiaoi-mrcp-v2.xml中profile name名称一致。
configuration nameunimrcp.conf descriptionUniMRCP Clientsettings!--al-unimrcpv2 UniMRCP profile to use for TTS --param namedefault-tts-profile valueal-unimrcpv2/!-- param namedefault-tts-profile valuexiaoi-mrcp-v2/ --!-- UniMRCP profile to use for ASR --!-- param namedefault-asr-profile valueal-unimrcpv2/ --param namedefault-asr-profile valuexiaoi-mrcp-v2/!-- UniMRCP logging level to appear in freeswitch.log. Options are:EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG --param namelog-level valueDEBUG/!-- Enable events for profile creation, open, and close --param nameenable-profile-events valuefalse/param namemax-connection-count value100/param nameoffer-new-connection value1/param namerequest-timeout value3000//settingsprofilesX-PRE-PROCESS cmdinclude data../mrcp_profiles/*.xml//profiles/configuration注意完成配置后不能直接 F6 reloadxml 需要重启FreeSWITCH才生效
systemctl restart freeswitch3.3. 配置拨号任务 在/usr/local/freeswitch/conf/dialplan/default.xml里新增如下配置
extension nameunimrcpcondition fielddestination_number expression^5001$action applicationanswer/action applicationlua dataasr.lua//condition
/extensionlua脚本存放地址及内容可根据需要调整
cd /usr/local/freeswitch/scripts
vim asr.luasession:answer()--freeswitch.consoleLog(INFO, Called extension is .. argv[1]\n)
welcome ivr/ivr-welcome_to_freeswitch.wav
menu ivr/ivr-this_ivr_will_let_you_test_features.wav
--
grammar hello
no_input_timeout 80000
recognition_timeout 80000
confidence_threshold 0.2
--
session:streamFile(welcome)
--freeswitch.consoleLog(INFO, Prompt file is \n)
tryagain 1while (tryagain 1) do
--session:execute(play_and_detect_speech,menu .. detect:unimrcp {start-input-timersfalse,no-input-timeout .. no_input_timeout .. ,recognition-timeout .. recognition_timeout .. } .. grammar)xml session:getVariable(detect_speech_result)
--if (xml nil) thenfreeswitch.consoleLog(CRIT,Result is nil\n)tryagain 0elsefreeswitch.consoleLog(CRIT,Result is .. xml .. \n)tryagain 0end
end
session:hangup()从上面的lua脚本能看出会加载grammar语法文件在/usr/local/freeswitch/grammar目录新增hello.gram语法文件可以为空语法文件须满足语音识别语法规范1.0标准简称 SRGS1.0该语法文件 ASR 引擎在进行识别时可以使用。
!-- grammar hello.gram --
?xml version1.0 encodingutf-8 ?
grammar version1.0 xml:langzh-cn rootdigit tag- formatsemantics/1.0 modecontinuous xmlnshttp://www.w3.org/2001/06/grammar!-- 这些都是必不可少的,做一个假配置--rule iddigitone-ofitemone/itemitemtwo/item/one-of/rule
/grammar4. 效果测试 完成以上配置后使用sip软电话拨打配置的号码5001在fs端fs_cli查看log
2021-05-19 14:43:37.981898 [DEBUG] apt_task.c:265 () Signal Message to [MRCP Client] [0x7f6500023ec0;2;3]
2021-05-19 14:43:37.981898 [DEBUG] apt_poller_task.c:251 () Wait for Messages [MRCPv2ConnectionAgent]
2021-05-19 14:43:37.981898 [DEBUG] apt_task.c:337 () Process Message [MRCP Client] [0x7f6500023ec0;2;3]
2021-05-19 14:43:37.981898 [INFO] mrcp_client_session.c:516 (ASR-13) Raise App MRCP Event ASR-13 ea2c920254a0462d
2021-05-19 14:43:37.981898 [DEBUG] mod_unimrcp.c:3675 (ASR-13) RECOGNITION COMPLETE, Completion-Cause: 000
2021-05-19 14:43:37.981898 [DEBUG] mod_unimrcp.c:3684 (ASR-13) Recognition result is not null-terminated. Appending null terminator.
2021-05-19 14:43:37.981898 [DEBUG] mod_unimrcp.c:2733 (ASR-13) ASR adding result headers
2021-05-19 14:43:37.981898 [DEBUG] mod_unimrcp.c:2628 (ASR-13) result:?xml version1.0?
resultinterpretation confidence99instanceengineNameXxx/engineNameengineStartTime/engineStartTimeresult喂喂喂讲话./resultbeginTime/beginTimeendTime/endTime/instanceinput modespeech喂喂喂讲话./input/interpretation
/result后续开发中使用mod_event_socket的内连模式对fs事件进行监听在play_and_detect_speech 应用执行完成的事件CHANNEL_EXECUTE_COMPLETE中就能获取到语音识别结果。 socket 连接命令与监听命令如下
nc 127.0.0.1 8021
auth ClueCon
event plain CHANNEL_EXECUTE_COMPLETE监听事件的结果如下便于查看进行了URL解码省略了该事件的部分细节内容
Content-Length: 9403
Content-Type: text/event-plainEvent-Name: CHANNEL_EXECUTE_COMPLETE
Core-UUID: 6f535b68-8025-4727-a210-70c2278501f9
FreeSWITCH-Hostname: freeswitch-seat
FreeSWITCH-Switchname: freeswitch-seat
FreeSWITCH-IPv4: 192.168.160.58
FreeSWITCH-IPv6: ::1
......
variable_current_application: play_and_detect_speech
variable_playback_last_offset_pos: 29760
variable_playback_seconds: 3
variable_playback_ms: 3970
variable_playback_samples: 31765
variable_detect_speech_result: ?xml version1.0?
resultinterpretation confidence99instanceengineNameXxx/engineNameengineStartTime/engineStartTimeresult喂喂喂讲话./resultbeginTime/beginTimeendTime/endTime/instanceinput modespeech喂喂喂讲话./input/interpretation
/result
variable_current_application_response: DONE
Application: play_and_detect_speech
Application-Data: ivr/ivr-this_ivr_will_let_you_test_features.wavdetect:unimrcp {start-input-timersfalse,no-input-timeout80000,recognition-timeout80000}hello
Application-Response: DONE
Application-UUID: 7f56ddc1-2d8f-4a2c-aae1-a236749f8133技术参考资料 https://github.com/wangkaisine/mrcp-plugin-with-freeswitch