Freeswitch中mod_unimrcp的ASR匹配及语法加载问题求助
Freeswitch语音识别问题排查与修复
一、问题根源分析
你遇到的Lua脚本语音匹配失败(返回001-no match)、JavaScript语法加载失败并报SyntaxError: missing ) after the argument list,核心原因是play_and_detect_speech的调用代码存在多处格式错误:
session.execute的参数未正确包裹在括号内,原代码将data=...写在括号外,属于基础语法错误- 音频路径
/thilip/welcome.wav后缺少空格,导致detect:被识别为文件名的一部分,无法正确解析识别引擎参数 file://后多了空格,导致语法文件路径无效,无法加载sr.gram- 语句的引号、括号未闭合,直接触发JavaScript语法报错
Lua脚本中虽然能检测到语音,但因语法文件未正确加载,自然无法完成匹配,返回无匹配结果。
二、修复后的代码示例
修正后的Lua代码
session.execute("play_and_detect_speech", "/thilip/welcome.wav detect:unimrcp:uni2 {start-input-timers=false,no-input-timeout=5000,recognition-timeout=5000} file:///usr/local/freeswitch/grammar/sr.gram language=en-US;y=1;n=2")
修正后的JavaScript代码
session.execute("play_and_detect_speech", "/thilip/welcome.wav detect:unimrcp:uni2 {start-input-timers=false,no-input-timeout=5000,recognition-timeout=5000} file:///usr/local/freeswitch/grammar/sr.gram language=en-US;y=1;n=2");
三、额外排查要点
- 确认
sr.gram语法文件格式符合MRCP规范,规则逻辑、语言适配(en-US)是否正确 - 检查mod_unimrcp配置,确保uni2通道的识别引擎连接正常,具备语法文件加载权限
- 查看Freeswitch日志(如
/var/log/freeswitch/freeswitch.log),获取语法加载、识别过程的详细错误信息
内容的提问来源于stack exchange,提问作者thilip an
相关产品推荐
相关产品推荐

