Check for request errors and return empty string (#2957)

* ODBC DSN detection

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* Spelling errors

* Requests to speech platform can fail
This commit is contained in:
sergey-mz
2018-01-11 13:26:39 -05:00
committed by FusionPBX
parent 203c8bcd35
commit 929b79d5d0

View File

@@ -62,14 +62,26 @@
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n");
end
--Access token request can fail
if (access_token_result == '') then
freeswitch.consoleLog("notice", "[voicemail] ACCESS TOKEN: (null) \n");
return ''
end
transcribe_cmd = "curl -X POST \"https://speech.platform.bing.com/recognize?scenarios=smd&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=" .. transcribe_language .. "&device.os=Freeswitch&version=3.0&format=json&instanceid=" .. gen_uuid() .. "&requestid=" .. gen_uuid() .. "\" -H 'Authorization: Bearer " .. access_token_result .. "' -H 'Content-type: audio/wav; codec=\"audio/pcm\"; samplerate=8000; trustsourcerate=false' --data-binary @"..file_path
local handle = io.popen(transcribe_cmd);
local transcribe_result = handle:read("*a");
handle:close();
local transcribe_json = JSON.decode(transcribe_result);
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n");
end
--Trancribe request can fail
if (transcribe_result == '') then
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: (null) \n");
return ''
end
local transcribe_json = JSON.decode(transcribe_result);
if (debug["info"]) then
if (transcribe_json["results"][1]["name"] == nil) then
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: (null) \n");
else