奥利奥泡泡 2019-04-01 00:19 采纳率: 0%
浏览 3380

freeswitch对接mrcp,想用lua脚本把结果取出来然后判断结果

也是从网上找的例子,但是我想解析这个xml,判断如果是yes,播放1.mp3,no播放2.MP3,该怎么做呢,有大神知道吗,我不会lua

代码如下:

tryagain = 1
while (tryagain == 1) do

    session:execute("play_and_detect_speech",welcome .. "detect:unimrcp {start-input-timers=false,no-input-timeout=" .. no_input_timeout .. ",recognition-timeout=" .. recognition_timeout .. "}" .. grammar)
    xl = session:getVariable('detect_speech_result')

    if (xl == nil) then
        freeswitch.consoleLog("CRIT","电话挂断\n")
        tryagain = 0
    else
        freeswitch.consoleLog("CRIT","Result is '" .. xl .. "'\n")
        这里取结果,判断
        session:execute("playback", huifu2)
        tryagain = 0
    end
end

得到的xml如下

<result>
     <interpretation grammar="" confidence="1.0">
         <instance>
             <callId>hostname-4418_35629.1554048033766857898-841227</callId>
             <logId>EDC18579-98CC-4649-9E60-6D5A1C71FEE0_-1</logId>
             <rolecategory>CLIENT</rolecategory>
             <extJson>
                <snStartTime>00:06.559</snStartTime>
                <snStopTime>00:07.519</snStopTime>
                <speed>1.04</speed></extJson>
             <categotyId>TXT</categotyId>
         </instance>
         <input mode="speech">yes,</input>
     </interpretation>
</result>
  • 写回答

1条回答 默认 最新

  • 瘦羊博士 2019-06-05 16:44
    关注

    将XML文件转Table,然后取Table的对应key, value,就可以获取yes or no 的值,识别不到的时候,也可能获取到空值

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了