From 23a079eca933def7b4086799c3ebec5dc4829e06 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 7 Feb 2022 16:08:49 -0500 Subject: [PATCH] Read out TTS Wait for DTMF of 1 if there is somewhere to go afterwards. --- extensions.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extensions.lua b/extensions.lua index 93043e6..b90b423 100644 --- a/extensions.lua +++ b/extensions.lua @@ -9,6 +9,14 @@ function uri_decode(uri) return uri:gsub("%%(%x%x)", hex_to_char) end +function prepare_tts(text) + local sha = channel.SHA1(text):get() + local handle = assert(io.popen("flite -voice /etc/asterisk/voice.flitevox -o /tmp/" .. sha .. ".wav16", "w")) + handle:write(text) + assert(handle:close()) + return "/tmp/" .. sha +end + function call_sgx_jmp(from_jid, to) local req = http_request.new_from_uri( "https://bandwidth-voice.jmp.chat/outbound/calls" @@ -37,6 +45,23 @@ extensions = { local result = call_sgx_jmp(from_jid, extension) channel.CDR("customer_id"):set(result.customer_id) + if result.tts then + local wav = prepare_tts(result.tts) + + if result.from and result.to then + app.read("digits", wav, 1, nil, 3) + else + app.playback(wav) + end + + os.remove(wav .. ".wav16") + + if channel.digits:get() ~= "1" then + app.hangup() + return + end + end + if result.from and result.to then channel.CALLERID("all"):set(result.from .. " <" .. result.from .. ">") app.dial("SIP/bandwidth/" .. result.to) -- 2.45.2