Added a simple selfhosted voicemail transcription API client

This commit is contained in:
Dan
2018-10-24 21:17:52 -07:00
parent 6bdda8fbee
commit 2056a71f13

View File

@@ -48,7 +48,7 @@
freeswitch.consoleLog("notice", "[voicemail] transcribe_provider: " .. transcribe_provider .. "\n");
freeswitch.consoleLog("notice", "[voicemail] transcribe_language: " .. transcribe_language .. "\n");
end
end
if (transcribe_provider == "microsoft") then
local api_key1 = settings:get('voicemail', 'microsoft_key1', 'text') or '';
@@ -93,19 +93,40 @@
freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n");
end
end
transcription = transcribe_json["results"][1]["name"];
transcription = transcription:gsub("<profanity>.*<%/profanity>","...");
confidence = transcribe_json["results"][1]["confidence"];
return transcription;
end
end
--start of my section
if (transcribe_provider == "selfhosted") then
local transcription_server = settings:get('voicemail', 'transcription_server', 'text') or '';
freeswitch.consoleLog("notice", "[voicemail] transcription provider: " .. transcription_server .. "\n");
local api_key2 = settings:get('voicemail', 'api_key', 'text') or '';
if (transcription_server ~= '') then
transcribe_cmd = "curl -L " .. transcription_server .. " -F file=@"..file_path
local handle = io.popen(transcribe_cmd);
local transcribe_result = handle:read("*a");
handle:close();
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n");
--Trancribe request can fail
if (transcribe_result == '') then
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: (null) \n");
return ''
end
return transcribe_result;
end
end
--end of my function
else
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message too short for transcription.\n");
end
end
end
return '';
end
@@ -116,12 +137,12 @@
local max_len_seconds = settings:get('voicemail', 'message_max_length', 'numeric') or 300;
transcribe_enabled = settings:get('voicemail', 'transcribe_enabled', 'boolean') or "false";
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] transcribe_enabled: " .. transcribe_enabled .. "\n");
freeswitch.consoleLog("notice", "[voicemail] voicemail_transcription_enabled: " .. voicemail_transcription_enabled .. "\n");
end
--record your message at the tone press any key or stop talking to end the recording
if (skip_instructions == "true") then
--skip the instructions