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个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!