diff --git a/app/voicemails/app_config.php b/app/voicemails/app_config.php index 14195f3f92..b3c7ed3f07 100644 --- a/app/voicemails/app_config.php +++ b/app/voicemails/app_config.php @@ -66,6 +66,10 @@ $y++; $apps[$x]['permissions'][$y]['name'] = "voicemail_sms_edit"; $y++; + $apps[$x]['permissions'][$y]['name'] = "voicemail_transcription_edit"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $apps[$x]['permissions'][$y]['groups'][] = "admin"; + $y++; //default settings $y = 0; @@ -167,6 +171,10 @@ $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."; $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]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Choose whether to attach the file to the email."; diff --git a/app/voicemails/app_languages.php b/app/voicemails/app_languages.php index af6a8557d6..b2db1b64b8 100644 --- a/app/voicemails/app_languages.php +++ b/app/voicemails/app_languages.php @@ -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']['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']['es-cl'] = "Correo a"; $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']['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']['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."; diff --git a/app/voicemails/voicemail_edit.php b/app/voicemails/voicemail_edit.php index b8204b5e53..21cc10f4ac 100644 --- a/app/voicemails/voicemail_edit.php +++ b/app/voicemails/voicemail_edit.php @@ -59,6 +59,7 @@ else { $voicemail_alternate_greet_id = check_str($_POST["voicemail_alternate_greet_id"]); $voicemail_mail_to = check_str($_POST["voicemail_mail_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_local_after_email = check_str($_POST["voicemail_local_after_email"]); $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_mail_to, "; $sql .= "voicemail_sms_to, "; + $sql .= "voicemail_transcription_enabled, "; $sql .= "voicemail_file, "; $sql .= "voicemail_local_after_email, "; $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_mail_to."', "; $sql .= "'".$voicemail_sms_to."', "; + $sql .= "'".$voicemail_transcription_enabled."', "; $sql .= "'".$voicemail_file."', "; $sql .= "'".$voicemail_local_after_email."', "; $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_mail_to = '".$voicemail_mail_to."', "; $sql .= "voicemail_sms_to = '".$voicemail_sms_to."', "; + $sql .= "voicemail_transcription_enabled = '".$voicemail_transcription_enabled."', "; $sql .= "voicemail_file = '".$voicemail_file."', "; $sql .= "voicemail_local_after_email = '".$voicemail_local_after_email."', "; $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_mail_to = $row["voicemail_mail_to"]; $voicemail_sms_to = $row["voicemail_sms_to"]; + $voicemail_transcription_enabled = $row["voicemail_transcription_enabled"]; $voicemail_file = $row["voicemail_file"]; $voicemail_local_after_email = $row["voicemail_local_after_email"]; $voicemail_enabled = $row["voicemail_enabled"]; @@ -490,6 +495,21 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; } + if(permission_exists('voicemail_transcription_edit') && $_SESSION['voicemail']['transcribe_enabled']['boolean'] == "true") { + echo "\n"; + echo "\n"; + echo " ".$text['label-voicemail_transcription_enabled']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-voicemail_transcription_enabled']."\n"; + echo "\n"; + echo "\n"; + } echo "\n"; echo "\n"; diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index f6edfe2233..3340b00b5d 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -199,6 +199,7 @@ voicemail_mail_to = row["voicemail_mail_to"]; voicemail_attach_file = row["voicemail_attach_file"]; voicemail_local_after_email = row["voicemail_local_after_email"]; + voicemail_transcription_enabled = row["voicemail_transcription_enabled"]; end); --set default values if (voicemail_local_after_email == nil) then 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 85c1f0101e..a62196d05e 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua @@ -38,46 +38,52 @@ end) end - local function transcribe(file_path,settings) + local function transcribe(file_path,settings,start_epoch) --transcription variables - local transcribe_provider = settings:get('voicemail', 'transcribe_provider', 'text') or ''; - transcribe_language = settings:get('voicemail', 'transcribe_language', 'text') or 'en-US'; + if (os.time() - start_epoch > 2) then + 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 - freeswitch.consoleLog("notice", "[voicemail] transcribe_provider: " .. transcribe_provider .. "\n"); - freeswitch.consoleLog("notice", "[voicemail] transcribe_language: " .. transcribe_language .. "\n"); + if (debug["info"]) then + 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 ''; - local api_key2 = settings:get('voicemail', 'microsoft_key2', 'text') or ''; - 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.."\"" - local handle = io.popen(access_token_cmd); - local access_token_result = handle:read("*a"); - handle:close(); - if (debug["info"]) then - freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n"); - freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n"); - 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 - 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"); - freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_json["results"][1]["name"] .. "\n"); - freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n"); - end + if (transcribe_provider == "microsoft") then + local api_key1 = settings:get('voicemail', 'microsoft_key1', 'text') or ''; + local api_key2 = settings:get('voicemail', 'microsoft_key2', 'text') or ''; + 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.."\"" + local handle = io.popen(access_token_cmd); + local access_token_result = handle:read("*a"); + handle:close(); + if (debug["info"]) then + freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n"); + freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n"); + 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 + 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"); + freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_json["results"][1]["name"] .. "\n"); + freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n"); + end - transcription = transcribe_json["results"][1]["name"]; - transcription = transcription:gsub(".*<%/profanity>","..."); - confidence = transcribe_json["results"][1]["confidence"]; + transcription = transcribe_json["results"][1]["name"]; + transcription = transcription:gsub(".*<%/profanity>","..."); + confidence = transcribe_json["results"][1]["confidence"]; + end + return transcription; end - return transcription; + else + if (debug["info"]) then + freeswitch.consoleLog("notice", "[voicemail] message too short for transcription.\n"); + end end return ''; @@ -93,6 +99,7 @@ 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 @@ -226,8 +233,8 @@ else --create initial wav recording result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds); - if (transcribe_enabled == "true") then - transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav",settings); + if (transcribe_enabled == "true" and voicemail_transcription_enabled == "true") then + transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav",settings,start_epoch); end --use lame to encode, if available if (file_exists("/usr/bin/lame")) then @@ -248,8 +255,8 @@ end else 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 - transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext,settings); + if (transcribe_enabled == "true" and voicemail_transcription_enabled == "true") then + transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext,settings,start_epoch); end end end