mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Update record_message.lua (#5488)
This commit is contained in:
@@ -277,6 +277,73 @@
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (transcribe_provider == "google") then
|
||||
local api_key = settings:get('voicemail', 'google_key', 'text') or '';
|
||||
local transcription_server = settings:get('voicemail', 'google_url', 'text') or '';
|
||||
if (api_key ~= '') then
|
||||
transcribe_cmd = [[sox ]]..file_path..[[ ]]..file_path..[[.flac && echo "{ 'config': { 'languageCode': 'en-US', 'enableWordTimeOffsets': false }, 'audio': { 'content': '`base64 -w 0 ]]..file_path..[[.flac`' } }" | curl -X POST -H "Content-Type: application/json" -d @- "]]..transcription_server..[[:recognize?key=]]..api_key..[[" && rm -f ]]..file_path..[[.flac]]
|
||||
|
||||
end
|
||||
|
||||
local handle = io.popen(transcribe_cmd);
|
||||
local transcribe_result = handle:read("*a");
|
||||
transcribe_result = transcribe_result:gsub('%%HESITATION ', '');
|
||||
handle:close();
|
||||
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 ''
|
||||
else
|
||||
status, transcribe_json = pcall(JSON.decode, transcribe_result);
|
||||
if not status then
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] error decoding google json\n");
|
||||
end
|
||||
return '';
|
||||
end
|
||||
end
|
||||
|
||||
if (transcribe_json["results"] ~= nil) then
|
||||
--Transcription
|
||||
if (transcribe_json["results"][1]["alternatives"][1]["transcript"] ~= nil) then
|
||||
transcription = '';
|
||||
for key, row in pairs(transcribe_json["results"]) do
|
||||
transcription = transcription .. row["alternatives"][1]["transcript"];
|
||||
end
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcription .. "\n");
|
||||
end
|
||||
else
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: (null) \n");
|
||||
end
|
||||
return '';
|
||||
end
|
||||
--Confidence
|
||||
if (transcribe_json["results"][1]["alternatives"][1]["confidence"]) then
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["alternatives"][1]["confidence"] .. "\n");
|
||||
end
|
||||
confidence = transcribe_json["results"][1]["alternatives"][1]["confidence"];
|
||||
else
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: (null) \n");
|
||||
end
|
||||
end
|
||||
return transcription;
|
||||
else
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: json error \n");
|
||||
end
|
||||
return '';
|
||||
end
|
||||
end
|
||||
|
||||
if (transcribe_provider == "custom") then
|
||||
local transcription_server = settings:get('voicemail', 'transcription_server', 'text') or '';
|
||||
|
||||
Reference in New Issue
Block a user