image.png

安装

官网参考文档:mod_unimrcp

mod_unimrcp 安装

加载非默认模块的方法:

  • 编辑freeswitch/modules.conf文件,找到要安装的模块,去掉前面的注释符号#。
  • 在命令行执行make mod_xxx-install命令,这样就编译相应模块,并把编译后的动态库安装的/usr/local/freeswitch/mod目录下了。
  • 如果想启动freeswitch的时候就自动加载,修改/usr/local/freeswitch/conf/autoload_configs/modules.conf.xml,去掉注释符号就可以了。

按照上面步骤安装 mod_unimrcp 即可。
mrcp_profiles/unimrcpserver-mrcp-v2.xml

配置外网ip、修改端口号

conf/unimrcpserver.xml配置中配置外网ip方法,配置并打开以下参数注释

  1. <sip-uas id="SIP-Agent-1" type="SofiaSIP">
  2. <sip-ip>本机内网地址</sip-ip>
  3. <sip-ext-ip>本机外网地址</sip-ext-ip>
  4. </sip-uas>

sip端口修改:

  1. <sip-port>8060</sip-port>替换成设置参数
  2. rtp ip&端口范围修改:
  3. <rtp-factory id="RTP-Factory-1">
  4. <rtp-ip>10.10.0.1</rtp-ip> 本机内网ip
  5. <rtp-ext-ip>a.b.c.d</rtp-ext-ip> 本机外网ip
  6. <rtp-port-min>5000</rtp-port-min> rtp端口下限
  7. <rtp-port-max>6000</rtp-port-max> rtp端口上限
  8. </rtp-factory>

在mrcp_profiles目录新建unimrcpserver-mrcp-v2.xml配置文件:

  1. <!-- FreeSWITCH IP、端口以及 SIP 传输方式 -->
  2. <param name="client-ip" value="192.168.1.153" />
  3. <param name="client-port" value="5069"/>
  4. <param name="sip-transport" value="udp"/>
  5. <param name="speechsynth" value="speechsynthesizer"/>
  6. <param name="speechrecog" value="speechrecognizer"/>
  7. <!--param name="rtp-ext-ip" value="auto"/-->
  8. <param name="rtp-ip" value="192.168.1.153"/>
  9. <param name="rtp-port-min" value="4000"/>
  10. <param name="rtp-port-max" value="5000"/>
  11. <param name="codecs" value="PCMU PCMA L16/96/8000"/>
  12. <!-- Add any default MRCP params for SPEAK requests here -->
  13. <synthparams>
  14. </synthparams>
  15. <!-- Add any default MRCP params for RECOGNIZE requests here -->
  16. <recogparams>
  17. <!--param name="start-input-timers" value="false"/-->
  18. </recogparams>

修改unimrcp.conf.xml,将”default-tts-profile”、”default-asr-profile”修改为我们上面配置的”unimrcpserver-mrcp2”(注意是 name 值而不是文件名),这样我们后面使用的时候可以不指定配置名直接使用默认配置:

  1. <param name="max-connection-count" value="100"/>
  2. <param name="offer-new-connection" value="1"/>
  3. <param name="request-timeout" value="3000"/>

智能 IVR 脚本
在scripts目录下新增names.lua脚本:

  1. session:answer()
  2. --freeswitch.consoleLog("INFO", "Called extension is '".. argv[1]"'\n")
  3. welcome = "ivr/ivr-welcome_to_freeswitch.wav"
  4. menu = "ivr/ivr-this_ivr_will_let_you_test_features.wav"
  5. --
  6. grammar = "hello"
  7. no_input_timeout = 80000
  8. recognition_timeout = 80000
  9. confidence_threshold = 0.2
  10. --
  11. session:streamFile(welcome)
  12. --freeswitch.consoleLog("INFO", "Prompt file is \n")
  13. tryagain = 1
  14. while (tryagain == 1) do
  15. --
  16. session:execute("play_and_detect_speech",menu .. "detect:unimrcp {start-input-timers=false,no-input-timeout=" .. no_input_timeout .. ",recognition-timeout=" .. recognition_timeout .. "}" .. grammar)
  17. xml = session:getVariable('detect_speech_result')
  18. --
  19. if (xml == nil) then
  20. freeswitch.consoleLog("CRIT","Result is 'nil'\n")
  21. tryagain = 0
  22. else
  23. freeswitch.consoleLog("CRIT","Result is '" .. xml .. "'\n")
  24. tryagain = 0
  25. end
  26. end
  27. --
  28. -- put logic to forward call here
  29. --
  30. session:sleep(250)
  31. session:set_tts_parms("unimrcp", "xiaofang");
  32. session:speak("今天天气不错啊");
  33. session:hangup()

同时我们需要在grammar目录新增hello.gram语法文件,可以为空语法文件须满足语音识别语法规范1.0标准(简称SRGS1.0),该语法文件 ASR 引擎在进行识别时可以使用。如:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <grammar version="1.0" xml:lang="zh-cn" root="Menu" tag-format="semantics/1.0"
  3.     xmlns=http://www.w3.org/2001/06/grammar
  4.     xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"><!- 这些都是必不可少的-->
  5. <rule id="city" scope="public">
  6. <one-of> <!-- 匹配其中一个短语-->
  7. <item>北京</item>
  8. <item>上海</item>
  9. </one-of>
  10. </rule>
  11. <rule id="cross" scope="public">
  12. <one-of>
  13. <item></item>
  14. <item></item>
  15. <item>飞往</item>
  16. </one-of>
  17. </rule>
  18. <rule id="Menu" scope="public">
  19. <item>
  20. <ruleref uri="#date"/> <!--指定关联的其他规则的节点-->
  21. <tag>out.date = reles.latest();</tag>
  22. </item>
  23. <item repeat="0-1"></item> <!--显示1次或0次-->
  24. <item>
  25. <ruleref uri="#city"/>
  26. <tag>out.city = rulels.latest();</tag>
  27. </item>
  28. <item>
  29. <ruleref uri="#cross"/>
  30. <tag>out.cross = rulels.latest();</tag>
  31. </item>
  32. <item>
  33. <ruleref uri="#city"/>
  34. <tag>out.city = rulels.latest();</tag>
  35. </item>
  36. </rule>
  37. </grammar>

脚本中,我们使用 unimrcp 默认配置,”play_and_detect_speech” 调用了 ASR 服务,”speak” 调用了 TTS 服务。你可以在循环中,尝试分析解析到的语句,根据内容进行导航、反馈。

最终测试
SIP 客户端登陆后拨打 5001 分机,就可以听到我们配置的导航内容了。

freesWitch安装mod_unimrcp.pptx

参考

https://github.com/wangkaisine/mrcp-plugin-with-freeswitch
https://freeswitch.org/confluence/display/FREESWITCH/mod_unimrcp
https://github.com/sunguangyong/freeswitch_unimrcp_xfyun
https://cotin.tech/AI/UniMRCPASR/
https://mp.weixin.qq.com/s/FSyoNXShmKz3bAAAeVyUBg
https://blog.csdn.net/zjzfb/article/details/94393487
https://blog.csdn.net/initiallht/category_10759863.html