XSwitch asr.lua

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,最后挂机

如果识别不到,那么 "抱歉,我听不清您说什么"

逻辑比较简单

相关推荐
_GR11 小时前
一篇博客学习Lua_安装使用+语法详解
开发语言·junit·lua
叫我六胖子2 天前
LUA(初学)
开发语言·lua
好奇的菜鸟4 天前
在 Postman 中高效生成随机环境变量的完整指南
测试工具·lua·postman
旷世奇才李先生11 天前
Lua 安装使用教程
开发语言·lua
Accpdaiyekun11 天前
C# 操作mongodb 多次查询快还是使用管道查询速度快
mongodb·c#·lua
快下雨了L12 天前
Lua现学现卖
开发语言·lua
WIN赢21 天前
PostMan使用
测试工具·lua·postman
多多*22 天前
计算机网络期末 网络基础概述
运维·服务器·网络·数据库·计算机网络·oracle·lua
22 天前
Lua复习之何为闭包
开发语言·unity·游戏引擎·lua·交互
码上库利南22 天前
详解Redis的LUA脚本、管道 (Pipelining)、事务事务 (Transactions)
数据库·redis·lua