Lua
session:answer()
session:setVariable("tts_engine", "ali")
session:setVariable("tts_voice", "default")
session:setVariable("playback_delimiter", "!")
local json = freeswitch.JSON()
local prompt = "您好,请说"
while session:ready() do
session:execute("play_and_detect_speech", "say:" .. "." .. prompt .. "'" .. "!tone_stream://%(100,1000,800)" .. " detect:ali default") -- asr模块是ali, 语法是default
local res = session:getVariable("detect_speech_result")
session:consoleLog("ERR", res)
local j = json:decode(res)
local text = j and j.text or ""
session:consoleLog("ERR", text)
if text ~= "" then
if string.find(text, "再见") or string.find(text, "拜拜") then break end
prompt = "您说的是 " .. text .. "..........谢谢!我们再玩一次......您好,请说"
else
prompt = "抱歉,我听不清您说什么..........您好请说"
end
end
session:streamFile("say:'谢谢您的使用,再见!'")
session:setVariable("playback_delimiter", "!")
say:tts!tone_stream://%(100,1000,800)
这样播放tts,再播放一个beep
如果asr识别到了,就把识别到的内容再播放一遍
如果是"再见"或者"拜拜",那么say good bye,最后挂机
如果识别不到,那么 "抱歉,我听不清您说什么"
逻辑比较简单