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

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

逻辑比较简单

相关推荐
AI_567814 小时前
Postman接口测试提速技巧:批量请求+智能断言实践
测试工具·lua·postman
小王不爱笑1324 天前
Postman 使用教程
测试工具·lua·postman
TracyCoder1235 天前
Redis 进阶之路:探秘事务、Lua 与特殊数据结构
数据结构·redis·lua
星空露珠5 天前
速算24点所有题库公式
开发语言·数据库·算法·游戏·lua
星空露珠6 天前
速算24点检测生成核心lua
开发语言·数据库·算法·游戏·lua
想做后端的前端8 天前
Lua的热更新
开发语言·lua
澄风9 天前
Redis ZSet+Lua脚本+SpringBoot实战:滑动窗口限流方案从原理到落地
spring boot·redis·lua
Geoking.9 天前
【Redis】Redis 中的 Pipeline 与 Lua 脚本:高性能与原子性的两种武器
redis·lua
剑之所向10 天前
嵌入式之lua脚本
开发语言·junit·lua
plmm烟酒僧10 天前
使用 Lua 进行汽车 UDS 诊断:轻量级脚本化诊断新思路
嵌入式·lua·汽车电子·uds诊断·汽车诊断·can通信·诊断协议