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

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

逻辑比较简单

相关推荐
钟智强3 小时前
CVE-2025-49844高危预警:Redis Lua脚本引擎UAF漏洞深度剖析与POC实战
数据库·redis·web安全·junit·lua
闲人编程4 小时前
聚合管道与复杂查询
开发语言·oracle·lua·match·查询·聚合·lookup
会周易的程序员2 天前
cNetgate物联网网关内存数据表和数据视图模块架构
c语言·c++·物联网·架构·lua·iot
会周易的程序员3 天前
cNetgate插件架构设计详解 动态库 脚本二开lua, python, javascript
javascript·c++·python·物联网·lua·iot
白太岁6 天前
Redis:(3) Lua 与 Redis、基于连接池的 Facade 模式封装
数据库·c++·redis·lua·外观模式
Maguyusi11 天前
go 批量生成c++和lua proto文件
c++·golang·lua·protobuf
foxsen_xia11 天前
Kamailio通过Lua写路由
开发语言·lua·信息与通信
码农周14 天前
nginx + Lua 实现域名访问日志统计
nginx·lua
難釋懷15 天前
Lua脚本解决多条命令原子性问题
开发语言·lua
AI_567818 天前
Postman接口测试提速技巧:批量请求+智能断言实践
测试工具·lua·postman