Add per-voicemail transcription enabled. (#2370)

This commit is contained in:
Chris Black 2017-02-13 12:12:43 -08:00 committed by FusionPBX
parent e0e1bc6950
commit 7dca005cdf
5 changed files with 96 additions and 38 deletions

View File

@ -66,6 +66,10 @@
$y++; $y++;
$apps[$x]['permissions'][$y]['name'] = "voicemail_sms_edit"; $apps[$x]['permissions'][$y]['name'] = "voicemail_sms_edit";
$y++; $y++;
$apps[$x]['permissions'][$y]['name'] = "voicemail_transcription_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
//default settings //default settings
$y = 0; $y = 0;
@ -167,6 +171,10 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the sms did to send voicemail to."; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the sms did to send voicemail to.";
$z++; $z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_transcription_enabled";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "If voicemail transcription is enabled for this user";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_attach_file"; $apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_attach_file";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Choose whether to attach the file to the email."; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Choose whether to attach the file to the email.";

View File

@ -157,6 +157,17 @@ $text['label-voicemail_sms_to']['uk'] = "SMS-повідомлення на";
$text['label-voicemail_sms_to']['de-at'] = "SMS an"; $text['label-voicemail_sms_to']['de-at'] = "SMS an";
$text['label-voicemail_sms_to']['he'] = ""; $text['label-voicemail_sms_to']['he'] = "";
$text['label-voicemail_transcription_enabled']['en-us'] = "Transcription Enabled";
$text['label-voicemail_transcription_enabled']['es-cl'] = "";
$text['label-voicemail_transcription_enabled']['pt-pt'] = "";
$text['label-voicemail_transcription_enabled']['fr-fr'] = "";
$text['label-voicemail_transcription_enabled']['pt-br'] = "";
$text['label-voicemail_transcription_enabled']['pl'] = "";
$text['label-voicemail_transcription_enabled']['sv-se'] = "";
$text['label-voicemail_transcription_enabled']['uk'] = "";
$text['label-voicemail_transcription_enabled']['de-at'] = "";
$text['label-voicemail_transcription_enabled']['he'] = "";
$text['label-voicemail_mail_to']['en-us'] = "Mail To"; $text['label-voicemail_mail_to']['en-us'] = "Mail To";
$text['label-voicemail_mail_to']['es-cl'] = "Correo a"; $text['label-voicemail_mail_to']['es-cl'] = "Correo a";
$text['label-voicemail_mail_to']['pt-pt'] = "Email Para"; $text['label-voicemail_mail_to']['pt-pt'] = "Email Para";
@ -522,6 +533,17 @@ $text['description-voicemail_sms_to']['uk'] = "Введіть номер SMS в
$text['description-voicemail_sms_to']['de-at'] = "Geben Sie die SMS-Nummer um Voicemail Benachrichtigung zu senden."; $text['description-voicemail_sms_to']['de-at'] = "Geben Sie die SMS-Nummer um Voicemail Benachrichtigung zu senden.";
$text['description-voicemail_sms_to']['he'] = "הזן את מספר ה-SMS לשלוח הודעת תא קולי."; $text['description-voicemail_sms_to']['he'] = "הזן את מספר ה-SMS לשלוח הודעת תא קולי.";
$text['description-voicemail_transcription_enabled']['en-us'] = "Choose if voicemail transcription is enabled for this extension ";
$text['description-voicemail_transcription_enabled']['es-cl'] = "";
$text['description-voicemail_transcription_enabled']['pt-pt'] = "";
$text['description-voicemail_transcription_enabled']['fr-fr'] = "";
$text['description-voicemail_transcription_enabled']['pt-br'] = "";
$text['description-voicemail_transcription_enabled']['pl'] = "";
$text['description-voicemail_transcription_enabled']['sv-se'] = "";
$text['description-voicemail_transcription_enabled']['uk'] = "";
$text['description-voicemail_transcription_enabled']['de-at'] = "";
$text['description-voicemail_transcription_enabled']['he'] = "";
$text['description-voicemail_message']['en-us'] = "A list of recorded voice messages which shows when the message was created, caller ID information, length, file size and download or delete the message."; $text['description-voicemail_message']['en-us'] = "A list of recorded voice messages which shows when the message was created, caller ID information, length, file size and download or delete the message.";
$text['description-voicemail_message']['es-cl'] = "Un listado de grabaciones de mensajes de voz que muestran la fecha de creación, información del Caller ID, duración, tamaño del archivo y permite descargar o eliminar el archivo"; $text['description-voicemail_message']['es-cl'] = "Un listado de grabaciones de mensajes de voz que muestran la fecha de creación, información del Caller ID, duración, tamaño del archivo y permite descargar o eliminar el archivo";
$text['description-voicemail_message']['pt-pt'] = "Uma lista de mensagens gravadas que mostra quando uma mensagem foi criada, o ID do chamador, a duração, o tamanho do ficheiro e opção de descarregar ou remover a mensagem."; $text['description-voicemail_message']['pt-pt'] = "Uma lista de mensagens gravadas que mostra quando uma mensagem foi criada, o ID do chamador, a duração, o tamanho do ficheiro e opção de descarregar ou remover a mensagem.";

View File

@ -59,6 +59,7 @@ else {
$voicemail_alternate_greet_id = check_str($_POST["voicemail_alternate_greet_id"]); $voicemail_alternate_greet_id = check_str($_POST["voicemail_alternate_greet_id"]);
$voicemail_mail_to = check_str($_POST["voicemail_mail_to"]); $voicemail_mail_to = check_str($_POST["voicemail_mail_to"]);
$voicemail_sms_to = check_str($_POST["voicemail_sms_to"]); $voicemail_sms_to = check_str($_POST["voicemail_sms_to"]);
$voicemail_transcription_enabled = check_str($_POST["voicemail_transcription_enabled"]);
$voicemail_file = check_str($_POST["voicemail_file"]); $voicemail_file = check_str($_POST["voicemail_file"]);
$voicemail_local_after_email = check_str($_POST["voicemail_local_after_email"]); $voicemail_local_after_email = check_str($_POST["voicemail_local_after_email"]);
$voicemail_enabled = check_str($_POST["voicemail_enabled"]); $voicemail_enabled = check_str($_POST["voicemail_enabled"]);
@ -147,6 +148,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= "voicemail_alternate_greet_id, "; $sql .= "voicemail_alternate_greet_id, ";
$sql .= "voicemail_mail_to, "; $sql .= "voicemail_mail_to, ";
$sql .= "voicemail_sms_to, "; $sql .= "voicemail_sms_to, ";
$sql .= "voicemail_transcription_enabled, ";
$sql .= "voicemail_file, "; $sql .= "voicemail_file, ";
$sql .= "voicemail_local_after_email, "; $sql .= "voicemail_local_after_email, ";
$sql .= "voicemail_enabled, "; $sql .= "voicemail_enabled, ";
@ -162,6 +164,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= (($voicemail_alternate_greet_id != '') ? "'".$voicemail_alternate_greet_id."'" : 'null').", "; $sql .= (($voicemail_alternate_greet_id != '') ? "'".$voicemail_alternate_greet_id."'" : 'null').", ";
$sql .= "'".$voicemail_mail_to."', "; $sql .= "'".$voicemail_mail_to."', ";
$sql .= "'".$voicemail_sms_to."', "; $sql .= "'".$voicemail_sms_to."', ";
$sql .= "'".$voicemail_transcription_enabled."', ";
$sql .= "'".$voicemail_file."', "; $sql .= "'".$voicemail_file."', ";
$sql .= "'".$voicemail_local_after_email."', "; $sql .= "'".$voicemail_local_after_email."', ";
$sql .= "'".$voicemail_enabled."', "; $sql .= "'".$voicemail_enabled."', ";
@ -181,6 +184,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= "voicemail_alternate_greet_id = ".(($voicemail_alternate_greet_id != '') ? "'".$voicemail_alternate_greet_id."'" : 'null').", "; $sql .= "voicemail_alternate_greet_id = ".(($voicemail_alternate_greet_id != '') ? "'".$voicemail_alternate_greet_id."'" : 'null').", ";
$sql .= "voicemail_mail_to = '".$voicemail_mail_to."', "; $sql .= "voicemail_mail_to = '".$voicemail_mail_to."', ";
$sql .= "voicemail_sms_to = '".$voicemail_sms_to."', "; $sql .= "voicemail_sms_to = '".$voicemail_sms_to."', ";
$sql .= "voicemail_transcription_enabled = '".$voicemail_transcription_enabled."', ";
$sql .= "voicemail_file = '".$voicemail_file."', "; $sql .= "voicemail_file = '".$voicemail_file."', ";
$sql .= "voicemail_local_after_email = '".$voicemail_local_after_email."', "; $sql .= "voicemail_local_after_email = '".$voicemail_local_after_email."', ";
$sql .= "voicemail_enabled = '".$voicemail_enabled."', "; $sql .= "voicemail_enabled = '".$voicemail_enabled."', ";
@ -267,6 +271,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$voicemail_alternate_greet_id = $row["voicemail_alternate_greet_id"]; $voicemail_alternate_greet_id = $row["voicemail_alternate_greet_id"];
$voicemail_mail_to = $row["voicemail_mail_to"]; $voicemail_mail_to = $row["voicemail_mail_to"];
$voicemail_sms_to = $row["voicemail_sms_to"]; $voicemail_sms_to = $row["voicemail_sms_to"];
$voicemail_transcription_enabled = $row["voicemail_transcription_enabled"];
$voicemail_file = $row["voicemail_file"]; $voicemail_file = $row["voicemail_file"];
$voicemail_local_after_email = $row["voicemail_local_after_email"]; $voicemail_local_after_email = $row["voicemail_local_after_email"];
$voicemail_enabled = $row["voicemail_enabled"]; $voicemail_enabled = $row["voicemail_enabled"];
@ -490,6 +495,21 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
} }
if(permission_exists('voicemail_transcription_edit') && $_SESSION['voicemail']['transcribe_enabled']['boolean'] == "true") {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-voicemail_transcription_enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='voicemail_transcription_enabled' id='voicemail_transcription_enabled'>\n";
echo " <option value='true' ".(($voicemail_transcription_enabled == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
echo " <option value='false' ".(($voicemail_transcription_enabled == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-voicemail_transcription_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n"; echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n"; echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";

View File

@ -199,6 +199,7 @@
voicemail_mail_to = row["voicemail_mail_to"]; voicemail_mail_to = row["voicemail_mail_to"];
voicemail_attach_file = row["voicemail_attach_file"]; voicemail_attach_file = row["voicemail_attach_file"];
voicemail_local_after_email = row["voicemail_local_after_email"]; voicemail_local_after_email = row["voicemail_local_after_email"];
voicemail_transcription_enabled = row["voicemail_transcription_enabled"];
end); end);
--set default values --set default values
if (voicemail_local_after_email == nil) then if (voicemail_local_after_email == nil) then

View File

@ -38,46 +38,52 @@
end) end)
end end
local function transcribe(file_path,settings) local function transcribe(file_path,settings,start_epoch)
--transcription variables --transcription variables
local transcribe_provider = settings:get('voicemail', 'transcribe_provider', 'text') or ''; if (os.time() - start_epoch > 2) then
transcribe_language = settings:get('voicemail', 'transcribe_language', 'text') or 'en-US'; local transcribe_provider = settings:get('voicemail', 'transcribe_provider', 'text') or '';
transcribe_language = settings:get('voicemail', 'transcribe_language', 'text') or 'en-US';
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] transcribe_provider: " .. transcribe_provider .. "\n"); freeswitch.consoleLog("notice", "[voicemail] transcribe_provider: " .. transcribe_provider .. "\n");
freeswitch.consoleLog("notice", "[voicemail] transcribe_language: " .. transcribe_language .. "\n"); freeswitch.consoleLog("notice", "[voicemail] transcribe_language: " .. transcribe_language .. "\n");
end end
if (transcribe_provider == "microsoft") then if (transcribe_provider == "microsoft") then
local api_key1 = settings:get('voicemail', 'microsoft_key1', 'text') or ''; local api_key1 = settings:get('voicemail', 'microsoft_key1', 'text') or '';
local api_key2 = settings:get('voicemail', 'microsoft_key2', 'text') or ''; local api_key2 = settings:get('voicemail', 'microsoft_key2', 'text') or '';
if (api_key1 ~= '' and api_key2 ~= '') then if (api_key1 ~= '' and api_key2 ~= '') then
access_token_cmd = "curl -X POST \"https://api.cognitive.microsoft.com/sts/v1.0/issueToken\" -H \"Content-type: application/x-www-form-urlencoded\" -H \"Content-Length: 0\" -H \"Ocp-Apim-Subscription-Key: "..api_key1.."\"" access_token_cmd = "curl -X POST \"https://api.cognitive.microsoft.com/sts/v1.0/issueToken\" -H \"Content-type: application/x-www-form-urlencoded\" -H \"Content-Length: 0\" -H \"Ocp-Apim-Subscription-Key: "..api_key1.."\""
local handle = io.popen(access_token_cmd); local handle = io.popen(access_token_cmd);
local access_token_result = handle:read("*a"); local access_token_result = handle:read("*a");
handle:close(); handle:close();
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n"); freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n"); freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n");
end end
transcribe_cmd = "curl -X POST \"https://speech.platform.bing.com/recognize?scenarios=smd&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=en-US&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 transcribe_cmd = "curl -X POST \"https://speech.platform.bing.com/recognize?scenarios=smd&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=en-US&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 handle = io.popen(transcribe_cmd);
local transcribe_result = handle:read("*a"); local transcribe_result = handle:read("*a");
handle:close(); handle:close();
local transcribe_json = JSON.decode(transcribe_result); local transcribe_json = JSON.decode(transcribe_result);
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n"); freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n"); freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n");
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_json["results"][1]["name"] .. "\n"); freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_json["results"][1]["name"] .. "\n");
freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n"); freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n");
end end
transcription = transcribe_json["results"][1]["name"]; transcription = transcribe_json["results"][1]["name"];
transcription = transcription:gsub("<profanity>.*<%/profanity>","..."); transcription = transcription:gsub("<profanity>.*<%/profanity>","...");
confidence = transcribe_json["results"][1]["confidence"]; confidence = transcribe_json["results"][1]["confidence"];
end
return transcription;
end end
return transcription; else
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message too short for transcription.\n");
end
end end
return ''; return '';
@ -93,6 +99,7 @@
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] transcribe_enabled: " .. transcribe_enabled .. "\n"); freeswitch.consoleLog("notice", "[voicemail] transcribe_enabled: " .. transcribe_enabled .. "\n");
freeswitch.consoleLog("notice", "[voicemail] voicemail_transcription_enabled: " .. voicemail_transcription_enabled .. "\n");
end end
--record your message at the tone press any key or stop talking to end the recording --record your message at the tone press any key or stop talking to end the recording
@ -226,8 +233,8 @@
else else
--create initial wav recording --create initial wav recording
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds); result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds);
if (transcribe_enabled == "true") then if (transcribe_enabled == "true" and voicemail_transcription_enabled == "true") then
transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav",settings); transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav",settings,start_epoch);
end end
--use lame to encode, if available --use lame to encode, if available
if (file_exists("/usr/bin/lame")) then if (file_exists("/usr/bin/lame")) then
@ -248,8 +255,8 @@
end end
else else
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds); result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds);
if (transcribe_enabled == "true") then if (transcribe_enabled == "true" and voicemail_transcription_enabled == "true") then
transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext,settings); transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext,settings,start_epoch);
end end
end end
end end