From d808ce53930736febf9af8906250f2fa55592072 Mon Sep 17 00:00:00 2001 From: sergey-mz Date: Thu, 11 Jan 2018 13:26:39 -0500 Subject: [PATCH] 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 --- .../resources/functions/record_message.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua index 0c1f7e2386..bac165648a 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua @@ -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