Voicemail Greetings: Integrate AI greeting generation, fix waveform image generation for OpenAI audio files.

This commit is contained in:
fusionate
2024-05-31 15:00:15 -06:00
parent 642c0acb79
commit 7d105c79e6
5 changed files with 475 additions and 41 deletions

View File

@@ -101,6 +101,11 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "greeting_message";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['search'] = 'true';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "greeting_filename";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";

View File

@@ -182,6 +182,32 @@ $text['message-greeting_selected']['zh-cn'] = "已选择问候语";
$text['message-greeting_selected']['ja-jp'] = "選択された挨拶";
$text['message-greeting_selected']['ko-kr'] = "인사말 선택됨";
$text['message-greeting_created']['en-us'] = "Greeting Created";
$text['message-greeting_created']['en-gb'] = "Greeting Created";
$text['message-greeting_created']['ar-eg'] = "";
$text['message-greeting_created']['de-at'] = "";
$text['message-greeting_created']['de-ch'] = "";
$text['message-greeting_created']['de-de'] = "";
$text['message-greeting_created']['el-gr'] = "";
$text['message-greeting_created']['es-cl'] = "";
$text['message-greeting_created']['es-mx'] = "";
$text['message-greeting_created']['fr-ca'] = "";
$text['message-greeting_created']['fr-fr'] = "";
$text['message-greeting_created']['he-il'] = "";
$text['message-greeting_created']['it-it'] = "";
$text['message-greeting_created']['nl-nl'] = "";
$text['message-greeting_created']['pl-pl'] = "";
$text['message-greeting_created']['pt-br'] = "";
$text['message-greeting_created']['pt-pt'] = "";
$text['message-greeting_created']['ro-ro'] = "";
$text['message-greeting_created']['ru-ru'] = "";
$text['message-greeting_created']['sv-se'] = "";
$text['message-greeting_created']['uk-ua'] = "";
$text['message-greeting_created']['tr-tr'] = "";
$text['message-greeting_created']['zh-cn'] = "";
$text['message-greeting_created']['ja-jp'] = "";
$text['message-greeting_created']['ko-kr'] = "";
$text['label-tools']['en-us'] = "Tools";
$text['label-tools']['en-gb'] = "Tools";
$text['label-tools']['ar-eg'] = "أدوات";
@@ -572,4 +598,160 @@ $text['confirm-filename']['zh-cn'] = "请提供:问候文件名";
$text['confirm-filename']['ja-jp'] = "入力してください: 挨拶ファイル名";
$text['confirm-filename']['ko-kr'] = "제공하십시오: 인사말 파일 이름";
?>
$text['label-model']['en-us'] = "Model";
$text['label-model']['en-gb'] = "Model";
$text['label-model']['ar-eg'] = "نموذج";
$text['label-model']['de-at'] = "Modell";
$text['label-model']['de-ch'] = "Modell";
$text['label-model']['de-de'] = "Modell";
$text['label-model']['el-gr'] = "Μοντέλο";
$text['label-model']['es-cl'] = "Modelo";
$text['label-model']['es-mx'] = "Modelo";
$text['label-model']['fr-ca'] = "Modèle";
$text['label-model']['fr-fr'] = "Modèle";
$text['label-model']['he-il'] = "דֶגֶם";
$text['label-model']['it-it'] = "Modello";
$text['label-model']['nl-nl'] = "Model";
$text['label-model']['pl-pl'] = "Model";
$text['label-model']['pt-br'] = "Modelo";
$text['label-model']['pt-pt'] = "Modelo";
$text['label-model']['ro-ro'] = "Model";
$text['label-model']['ru-ru'] = "Модель";
$text['label-model']['sv-se'] = "Modell";
$text['label-model']['uk-ua'] = "Модель";
$text['label-model']['tr-tr'] = "Modeli";
$text['label-model']['zh-cn'] = "模型";
$text['label-model']['ja-jp'] = "モデル";
$text['label-model']['ko-kr'] = "모델";
$text['description-model']['en-us'] = "Select the model that is used to make the recording.";
$text['description-model']['en-gb'] = "Select the model that is used to make the recording.";
$text['description-model']['ar-eg'] = "حدد النموذج المستخدم لإجراء التسجيل.";
$text['description-model']['de-at'] = "Wählen Sie das Modell aus, das für die Aufnahme verwendet wird.";
$text['description-model']['de-ch'] = "Wählen Sie das Modell aus, das für die Aufnahme verwendet wird.";
$text['description-model']['de-de'] = "Wählen Sie das Modell aus, das für die Aufnahme verwendet wird.";
$text['description-model']['el-gr'] = "Επιλέξτε το μοντέλο που χρησιμοποιείται για την εγγραφή.";
$text['description-model']['es-cl'] = "Seleccione el modelo que se utiliza para realizar la grabación.";
$text['description-model']['es-mx'] = "Seleccione el modelo que se utiliza para realizar la grabación.";
$text['description-model']['fr-ca'] = "Sélectionnez le modèle utilisé pour effectuer l'enregistrement.";
$text['description-model']['fr-fr'] = "Sélectionnez le modèle utilisé pour effectuer l'enregistrement.";
$text['description-model']['he-il'] = "בחר את הדגם המשמש לביצוע ההקלטה.";
$text['description-model']['it-it'] = "Seleziona il modello utilizzato per effettuare la registrazione.";
$text['description-model']['nl-nl'] = "Selecteer het model dat wordt gebruikt om de opname te maken.";
$text['description-model']['pl-pl'] = "Wybierz model, który będzie używany do nagrywania.";
$text['description-model']['pt-br'] = "Selecione o modelo que será utilizado para fazer a gravação.";
$text['description-model']['pt-pt'] = "Selecione o modelo que será utilizado para fazer a gravação.";
$text['description-model']['ro-ro'] = "Selectați modelul care este utilizat pentru a face înregistrarea.";
$text['description-model']['ru-ru'] = "Выберите модель, которая использовалась для записи.";
$text['description-model']['sv-se'] = "Välj den modell som används för att göra inspelningen.";
$text['description-model']['uk-ua'] = "Виберіть модель, яка використовується для запису.";
$text['description-model']['tr-tr'] = "Kaydı yapmak için kullanılan modeli seçin.";
$text['description-model']['zh-cn'] = "选择用于进行录制的型号。";
$text['description-model']['ja-jp'] = "録音に使用したモデルを選択します。";
$text['description-model']['ko-kr'] = "녹음에 사용되는 모델을 선택합니다.";
$text['label-voice']['en-us'] = "Voice";
$text['label-voice']['en-gb'] = "Voice";
$text['label-voice']['ar-eg'] = "صوت";
$text['label-voice']['de-at'] = "Stimme";
$text['label-voice']['de-ch'] = "Stimme";
$text['label-voice']['de-de'] = "Stimme";
$text['label-voice']['el-gr'] = "Φωνή";
$text['label-voice']['es-cl'] = "Voz";
$text['label-voice']['es-mx'] = "Voz";
$text['label-voice']['fr-ca'] = "Voix";
$text['label-voice']['fr-fr'] = "Voix";
$text['label-voice']['he-il'] = "קוֹל";
$text['label-voice']['it-it'] = "Voce";
$text['label-voice']['nl-nl'] = "Stem";
$text['label-voice']['pl-pl'] = "Głos";
$text['label-voice']['pt-br'] = "Voz";
$text['label-voice']['pt-pt'] = "Voz";
$text['label-voice']['ro-ro'] = "Voce";
$text['label-voice']['ru-ru'] = "Голос";
$text['label-voice']['sv-se'] = "Röst";
$text['label-voice']['uk-ua'] = "Голос";
$text['label-voice']['tr-tr'] = "Ses";
$text['label-voice']['zh-cn'] = "嗓音";
$text['label-voice']['ja-jp'] = "";
$text['label-voice']['ko-kr'] = "목소리";
$text['description-voice']['en-us'] = "Select the voice that is used to make the recording.";
$text['description-voice']['en-gb'] = "Select the voice that is used to make the recording.";
$text['description-voice']['ar-eg'] = "حدد الصوت المستخدم في التسجيل.";
$text['description-voice']['de-at'] = "Wählen Sie die Stimme aus, die für die Aufnahme verwendet wird.";
$text['description-voice']['de-ch'] = "Wählen Sie die Stimme aus, die für die Aufnahme verwendet wird.";
$text['description-voice']['de-de'] = "Wählen Sie die Stimme aus, die für die Aufnahme verwendet wird.";
$text['description-voice']['el-gr'] = "Επιλέξτε τη φωνή που χρησιμοποιείται για την εγγραφή.";
$text['description-voice']['es-cl'] = "Seleccione la voz que se utiliza para realizar la grabación.";
$text['description-voice']['es-mx'] = "Seleccione la voz que se utiliza para realizar la grabación.";
$text['description-voice']['fr-ca'] = "Sélectionnez la voix utilisée pour effectuer l'enregistrement.";
$text['description-voice']['fr-fr'] = "Sélectionnez la voix utilisée pour effectuer l'enregistrement.";
$text['description-voice']['he-il'] = "בחר את הקול המשמש לביצוע ההקלטה.";
$text['description-voice']['it-it'] = "Seleziona la voce utilizzata per effettuare la registrazione.";
$text['description-voice']['nl-nl'] = "Selecteer de stem die wordt gebruikt om de opname te maken.";
$text['description-voice']['pl-pl'] = "Wybierz głos, który zostanie użyty do nagrania.";
$text['description-voice']['pt-br'] = "Selecione a voz usada para fazer a gravação.";
$text['description-voice']['pt-pt'] = "Selecione a voz usada para fazer a gravação.";
$text['description-voice']['ro-ro'] = "Selectați vocea care este folosită pentru a face înregistrarea.";
$text['description-voice']['ru-ru'] = "Выберите голос, который используется для записи.";
$text['description-voice']['sv-se'] = "Välj rösten som används för att göra inspelningen.";
$text['description-voice']['uk-ua'] = "Виберіть голос, який використовується для запису.";
$text['description-voice']['tr-tr'] = "Kaydı yapmak için kullanılan sesi seçin.";
$text['description-voice']['zh-cn'] = "选择用于录音的声音。";
$text['description-voice']['ja-jp'] = "録音に使用する音声を選択します。";
$text['description-voice']['ko-kr'] = "녹음에 사용되는 음성을 선택합니다.";
$text['label-message']['en-us'] = "Message";
$text['label-message']['en-gb'] = "Message";
$text['label-message']['ar-eg'] = "رسالة";
$text['label-message']['de-at'] = "Nachricht";
$text['label-message']['de-ch'] = "Nachricht";
$text['label-message']['de-de'] = "Nachricht";
$text['label-message']['el-gr'] = "Μήνυμα";
$text['label-message']['es-cl'] = "Mensaje";
$text['label-message']['es-mx'] = "Mensaje";
$text['label-message']['fr-ca'] = "Message";
$text['label-message']['fr-fr'] = "Message";
$text['label-message']['he-il'] = "הוֹדָעָה";
$text['label-message']['it-it'] = "Messaggio";
$text['label-message']['nl-nl'] = "Bericht";
$text['label-message']['pl-pl'] = "Wiadomość";
$text['label-message']['pt-br'] = "Mensagem";
$text['label-message']['pt-pt'] = "Mensagem";
$text['label-message']['ro-ro'] = "Mesaj";
$text['label-message']['ru-ru'] = "Сообщение";
$text['label-message']['sv-se'] = "Meddelande";
$text['label-message']['uk-ua'] = "повідомлення";
$text['label-message']['tr-tr'] = "İleti";
$text['label-message']['zh-cn'] = "信息";
$text['label-message']['ja-jp'] = "メッセージ";
$text['label-message']['ko-kr'] = "메시지";
$text['description-message']['en-us'] = "The recording message.";
$text['description-message']['en-gb'] = "The recording message.";
$text['description-message']['ar-eg'] = "رسالة التسجيل.";
$text['description-message']['de-at'] = "Die Aufnahmenachricht.";
$text['description-message']['de-ch'] = "Die Aufnahmenachricht.";
$text['description-message']['de-de'] = "Die Aufnahmenachricht.";
$text['description-message']['el-gr'] = "Το μήνυμα ηχογράφησης.";
$text['description-message']['es-cl'] = "El mensaje de grabación.";
$text['description-message']['es-mx'] = "El mensaje de grabación.";
$text['description-message']['fr-ca'] = "Le message d'enregistrement.";
$text['description-message']['fr-fr'] = "Le message d'enregistrement.";
$text['description-message']['he-il'] = "הודעת ההקלטה.";
$text['description-message']['it-it'] = "Il messaggio registrato.";
$text['description-message']['nl-nl'] = "Het opnamebericht.";
$text['description-message']['pl-pl'] = "Nagrana wiadomość.";
$text['description-message']['pt-br'] = "A mensagem de gravação.";
$text['description-message']['pt-pt'] = "A mensagem de gravação.";
$text['description-message']['ro-ro'] = "Mesajul de înregistrare.";
$text['description-message']['ru-ru'] = "Сообщение о записи.";
$text['description-message']['sv-se'] = "Inspelningsmeddelandet.";
$text['description-message']['uk-ua'] = "Запис повідомлення.";
$text['description-message']['tr-tr'] = "Kayıt mesajı.";
$text['description-message']['zh-cn'] = "录音消息。";
$text['description-message']['ja-jp'] = "録音メッセージ。";
$text['description-message']['ko-kr'] = "녹음 메시지입니다.";
?>

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2023
Portions created by the Initial Developer are Copyright (C) 2008-2024
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -41,24 +41,65 @@
$language = new text;
$text = $language->get();
//validate the uuids
if (is_uuid($_REQUEST["id"])) {
//add the settings object
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
$speech_enabled = $settings->get('speech', 'enabled', 'false');
$speech_engine = $settings->get('speech', 'engine', '');
$transcribe_enabled = $settings->get('transcribe', 'enabled', 'false');
$transcribe_engine = $settings->get('transcribe', 'engine', '');
//set defaults
$translate_enabled = false;
$language_enabled = false;
//add the speech object and get the voices and languages arrays
if ($speech_enabled == 'true' && !empty($speech_engine)) {
$speech = new speech($settings);
$voices = $speech->get_voices();
//$speech_models = $speech->get_models();
//$translate_enabled = $speech->get_translate_enabled();
//$language_enabled = $speech->get_language_enabled();
//$languages = $speech->get_languages();
}
//add the transcribe object and get the languages arrays
if ($transcribe_enabled == 'true' && !empty($transcribe_engine)) {
$transcribe = new transcribe($settings);
//$transcribe_models = $transcribe->get_models();
//$translate_enabled = $transcribe->get_translate_enabled();
//$language_enabled = $transcribe->get_language_enabled();
//$languages = $transcribe->get_languages();
}
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$voicemail_greeting_uuid = $_REQUEST["id"];
}
if (is_numeric($_REQUEST["voicemail_id"])) {
else {
$action = "add";
$voicemail_greeting_uuid = uuid();
}
if (!empty($_REQUEST["voicemail_id"]) && is_numeric($_REQUEST["voicemail_id"])) {
$voicemail_id = $_REQUEST["voicemail_id"];
}
//get the form value and set to php variables
if (count($_POST) > 0) {
if (!empty($_POST) && is_array($_POST)) {
$greeting_id = $_POST["greeting_id"];
$greeting_name = $_POST["greeting_name"];
$greeting_voice = $_POST["greeting_voice"];
//$greeting_model = $_POST["greeting_model"];
$greeting_language = $_POST["greeting_language"] ?? null;
//$translate = $_POST["translate"];
$greeting_message = $_POST["greeting_message"];
$greeting_description = $_POST["greeting_description"];
//clean the name
$greeting_name = str_replace("'", "", $greeting_name);
}
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
if (!empty($_POST) && empty($_POST["persistformvar"])) {
//delete the voicemail greeting
if (permission_exists('voicemail_greeting_delete')) {
@@ -102,18 +143,95 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//update the database
if ((empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") && permission_exists('voicemail_greeting_edit')) {
//build update array
$array['voicemail_greetings'][0]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
$array['voicemail_greetings'][0]['greeting_name'] = $greeting_name;
$array['voicemail_greetings'][0]['greeting_description'] = $greeting_description;
//execute update
$database = new database;
$database->app_name = 'voicemail_greetings';
$database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2';
$database->save($array);
unset($array);
//set message
message::add($text['message-update']);
//get current vm greeting ids for mailbox
$sql = "select greeting_id ";
$sql .= "from v_voicemail_greetings where domain_uuid = :domain_uuid ";
$sql .= "and voicemail_id = :voicemail_id ";
$sql .= "order by greeting_id asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['voicemail_id'] = $voicemail_id;
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (!empty($rows) && is_array($rows)) {
foreach ($rows as $row) {
$greeting_ids[] = $row['greeting_id'];
}
}
unset($sql, $parameters);
//set the recording format
$greeting_format = $greeting_format ?? 'wav';
//build the setting object and get the recording path
$greeting_path = $settings->get('switch', 'voicemail').'/default/'.$_SESSION['domain_name'].'/'.$voicemail_id.'/';
if ($action == 'add') {
//find the next available greeting id
$greeting_id = 0;
for ($i = 1; $i <= 9; $i++) {
if (!in_array($i, $greeting_ids) && !file_exists($greeting_path.'greeting_'.$i.'.'.$greeting_format)) {
$greeting_id = $i;
break;
}
}
}
if (!empty($greeting_id)) {
//set file name
$greeting_filename = 'greeting_'.$greeting_id.'.'.$greeting_format;
//text to audio - make a new audio file from the message
if ($speech_enabled == 'true' && !empty($greeting_voice) && !empty($greeting_message)) {
$speech->audio_path = $greeting_path;
$speech->audio_filename = $greeting_filename;
$speech->audio_format = $greeting_format;
//$speech->audio_model = $greeting_model ?? '';
$speech->audio_voice = $greeting_voice;
//$speech->audio_language = $greeting_language;
//$speech->audio_translate = $translate;
$speech->audio_message = $greeting_message;
$speech->speech();
//fix invalid riff & data header lengths in generated wave file
if ($speech_engine == 'openai') {
$greeting_filename_temp = str_replace('.'.$greeting_format, '.tmp.'.$greeting_format, $greeting_filename);
exec('sox --ignore-length '.$greeting_path.$greeting_filename.' '.$greeting_path.$greeting_filename_temp);
if (file_exists($greeting_path.$greeting_filename_temp)) {
exec('rm -f '.$greeting_path.$greeting_filename.' && mv '.$greeting_path.$greeting_filename_temp.' '.$greeting_path.$greeting_filename);
}
unset($greeting_filename_temp);
}
}
//audio to text - get the transcription from the audio file
if ($transcribe_enabled == 'true' && empty($greeting_voice) && empty($greeting_message)) {
$transcribe->audio_path = $greeting_path;
$transcribe->audio_filename = $greeting_filename;
$greeting_message = $transcribe->transcribe();
}
//build data array
$array['voicemail_greetings'][0]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
$array['voicemail_greetings'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
$array['voicemail_greetings'][0]['voicemail_id'] = $voicemail_id;
$array['voicemail_greetings'][0]['greeting_id'] = $greeting_id;
$array['voicemail_greetings'][0]['greeting_name'] = $greeting_name;
$array['voicemail_greetings'][0]['greeting_message'] = $greeting_message;
$array['voicemail_greetings'][0]['greeting_filename'] = $greeting_filename;
$array['voicemail_greetings'][0]['greeting_description'] = $greeting_description;
//execute query
$database = new database;
$database->app_name = 'voicemail_greetings';
$database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2';
$database->save($array);
unset($array);
//set message
message::add($text['message-'.($action == 'add' ? 'greeting_created' : 'update')]);
}
//redirect
header("Location: voicemail_greetings.php?id=".$voicemail_id);
exit;
@@ -121,16 +239,22 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
//pre-populate the form
if (count($_GET) > 0 && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) {
if (
$action == 'update' &&
!empty($voicemail_greeting_uuid) && is_uuid($voicemail_greeting_uuid) &&
(empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")
) {
$sql = "select * from v_voicemail_greetings ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and voicemail_greeting_uuid = :voicemail_greeting_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$greeting_id = $row["greeting_id"];
$greeting_name = $row["greeting_name"];
$greeting_message = $row["greeting_message"];
$greeting_description = $row["greeting_description"];
}
unset($sql, $parameters, $row);
@@ -141,17 +265,17 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$token = $object->create($_SERVER['PHP_SELF']);
//show the header
$document['title'] = $text['label-edit'];
$document['title'] = $text['label-'.($action == 'update' ? 'edit' : 'add')];
require_once "resources/header.php";
//show the content
echo "<form name='frm' id='frm' method='post'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['label-edit']."</b></div>\n";
echo " <div class='heading'><b>".$text['label-'.($action == 'update' ? 'edit' : 'add')]."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','collapse'=>'hide-xs','link'=>'voicemail_greetings.php?id='.urlencode($voicemail_id)]);
if (permission_exists('voicemail_greeting_delete')) {
if (permission_exists('voicemail_greeting_delete') && $action == 'update') {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','collapse'=>'hide-xs','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
}
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
@@ -159,7 +283,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('voicemail_greeting_delete')) {
if (permission_exists('voicemail_greeting_delete') && $action == 'update') {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
}
@@ -170,18 +294,124 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo " ".$text['label-name']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='greeting_name' maxlength='255' value=\"".escape($greeting_name)."\">\n";
echo " <input class='formfld' type='text' name='greeting_name' maxlength='255' value=\"".escape($greeting_name ?? '')."\">\n";
echo "<br />\n";
echo "".$text['description-name']."\n";
echo "</td>\n";
echo "</tr>\n";
if ($speech_enabled == 'true' || $transcribe_enabled == 'true') {
//models
if (!empty($models) && is_array($models)) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-model']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='greeting_model'>\n";
echo " <option value=''></option>\n";
foreach ($models as $model_id => $model_name) {
echo " <option value='".escape($model_id)."' ".($model_id == $greeting_model ? "selected='selected'" : '').">".escape($model_name)."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-model']."\n";
echo "</td>\n";
echo "</tr>\n";
}
// else {
// echo "<input class='formfld' type='hidden' name='greeting_model' maxlength='255' value=''>\n";
// }
//voices
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-voice']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if (!empty($voices) && is_array($voices)) {
echo " <select class='formfld' name='greeting_voice'>\n";
echo " <option value=''></option>\n";
foreach ($voices as $key => $voice) {
echo " <option value='".escape(gettype($key) === "integer" ? $voice : $key)."' ".(!empty($greeting_voice) && $voice == $greeting_voice ? "selected='selected'" : null).">".escape(ucwords($voice))."</option>\n";
}
echo " </select>\n";
}
else {
echo " <input class='formfld' type='text' name='greeting_voice' maxlength='255' value=\"".escape($greeting_voice ?? '')."\">\n";
}
echo "<br />\n";
echo $text['description-voice']."\n";
echo "</td>\n";
echo "</tr>\n";
if ($language_enabled) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-language']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if (!empty($languages) && is_array($languages)) {
sort($languages);
echo " <select class='formfld' name='greeting_language'>\n";
echo " <option value=''></option>\n";
foreach ($languages as $language) {
echo " <option value='".escape($language)."' ".($language == $greeting_language ? "selected='selected'" : null).">".escape($language)."</option>\n";
}
echo " </select>\n";
}
else {
echo " <input class='formfld' type='text' name='greeting_language' maxlength='255' value=\"".escape($greeting_language ?? '')."\">\n";
}
echo "<br />\n";
echo $text['description-languages']."\n";
echo "</td>\n";
echo "</tr>\n";
}
if ($translate_enabled) {
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-translate']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') {
echo " <label class='switch'>\n";
echo " <input type='checkbox' id='translate' name='translate' value='true' ".($translate == 'true' ? "checked='checked'" : null).">\n";
echo " <span class='slider'></span>\n";
echo " </label>\n";
}
else {
echo " <select class='formfld' id='translate' name='translate'>\n";
echo " <option value='true' ".($translate == 'true' ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " <option value='false' ".($translate == 'false' ? "selected='selected'" : null).">".$text['option-false']."</option>\n";
echo " </select>\n";
}
echo "<br />\n";
echo $text['description-translate']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-message']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <textarea class='formfld' name='greeting_message' style='width: 300px; height: 150px;'>".escape($greeting_message ?? '')."</textarea>\n";
echo "<br />\n";
echo $text['description-message']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='greeting_description' maxlength='255' value=\"".escape($greeting_description)."\">\n";
echo " <input class='formfld' type='text' name='greeting_description' maxlength='255' value=\"".escape($greeting_description ?? '')."\">\n";
echo "<br />\n";
echo "".$text['description-info']."\n";
echo "</td>\n";
@@ -190,7 +420,10 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo "</table>";
echo "<br /><br />";
echo "<input type='hidden' name='voicemail_greeting_uuid' value='".escape($voicemail_greeting_uuid)."'>\n";
if ($action == 'update' && !empty($voicemail_greeting_uuid) && is_uuid($voicemail_greeting_uuid)) {
echo "<input type='hidden' name='voicemail_greeting_uuid' value='".escape($voicemail_greeting_uuid)."'>\n";
echo "<input type='hidden' name='greeting_id' value='".escape($greeting_id ?? '')."'>\n";
}
echo "<input type='hidden' name='voicemail_id' value='".escape($voicemail_id)."'>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";

View File

@@ -17,13 +17,16 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2023
Portions created by the Initial Developer are Copyright (C) 2008-2024
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//set the max php execution time
ini_set('max_execution_time', 7200);
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
@@ -38,6 +41,10 @@
$language = new text;
$text = $language->get();
//add the settings object
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
$speech_enabled = $settings->get('speech', 'enabled');
//set the defaults
$sql_file_size = '';
@@ -51,7 +58,7 @@
//define order by default
if ($order_by == '') {
$order_by = "greeting_name";
$order_by = "greeting_id";
$order = "asc";
}
@@ -76,7 +83,7 @@
unset($sql, $parameters);
//define greeting directory
$greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id;
$greeting_dir = $_SESSION['switch']['voicemail']['dir'].'/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id;
//download the greeting
if (!empty($_GET['a']) && $_GET['a'] == "download" && (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download'))) {
@@ -345,23 +352,30 @@
echo " <div class='heading'><b>".$text['title']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>$_SESSION['back'][$_SERVER['PHP_SELF']]]);
$margin_left = false;
if (permission_exists('voicemail_greeting_add') && is_array($greetings) && @sizeof($greetings) < 9 && $speech_enabled == 'true') {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','style'=>'margin-left: 15px;','link'=>'voicemail_greeting_edit.php?voicemail_id='.urlencode($voicemail_id)]);
$margin_left = true;
}
if (permission_exists('voicemail_greeting_upload') && is_array($greetings) && @sizeof($greetings) < 9) {
echo "<form id='form_upload' class='inline' method='post' enctype='multipart/form-data'>\n";
echo "<input name='a' type='hidden' value='upload'>\n";
echo "<input type='hidden' name='id' value='".escape($voicemail_id)."'>\n";
echo "<input type='hidden' name='type' value='rec'>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','style'=>'margin-left: 15px;','onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]);
echo button::create(['type'=>'button','label'=>$text['button-upload'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_upload','style'=>(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]);
echo "<span id='form_upload' style='display: none;'>";
echo button::create(['label'=>$text['button-cancel'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'type'=>'button','id'=>'btn_upload_cancel','style'=>'margin-left: 15px;','onclick'=>"$('span#form_upload').fadeOut(250, function(){ document.getElementById('form_upload').reset(); $('#btn_add').fadeIn(250) });"]);
echo button::create(['label'=>$text['button-cancel'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'type'=>'button','id'=>'btn_upload_cancel','style'=>'margin-left: 15px;','onclick'=>"$('span#form_upload').fadeOut(250, function(){ document.getElementById('form_upload').reset(); $('#btn_upload').fadeIn(250) });"]);
echo "<input type='text' class='txt' style='width: 100px; cursor: pointer;' id='filename' placeholder='Select...' onclick=\"document.getElementById('ulfile').click(); this.blur();\" onfocus='this.blur();'>";
echo "<input type='file' id='ulfile' name='file' style='display: none;' accept='.wav,.mp3,.ogg' onchange=\"document.getElementById('filename').value = this.files.item(0).name; check_file_type(this);\">";
echo button::create(['type'=>'submit','label'=>$text['button-upload'],'icon'=>$_SESSION['theme']['button_icon_upload']]);
echo "</span>\n";
echo "</form>";
$margin_left = true;
}
if (permission_exists('voicemail_greeting_delete') && $greetings) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; '.(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"modal_open('modal-delete','btn_delete');"]);
$margin_left = true;
}
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";

View File

@@ -60,7 +60,7 @@
unset($sql, $parameters);
//define greeting directory
$greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$_SESSION['domain_uuid']]['domain_name'].'/'.$voicemail_id;
$greeting_dir = $_SESSION['switch']['voicemail']['dir'].'/default/'.$_SESSION['domains'][$_SESSION['domain_uuid']]['domain_name'].'/'.$voicemail_id;
//get voicemail greeting details from db
$sql = "select greeting_filename, greeting_base64, greeting_id ";
@@ -91,7 +91,7 @@
$temp_filename = 'waveform_'.$_GET['id'].'_'.rand(0000,9999).'.png';
//create temporary waveform image, if doesn't exist
if (file_exists($temp_filename)) {
if (file_exists($greeting_dir.'/'.$temp_filename)) {
$wf = true;
}
else {
@@ -106,14 +106,14 @@
Waveform::$singlePhase = empty($_SESSION['theme']['audio_player_waveform_single_phase']['boolean']) || $_SESSION['theme']['audio_player_waveform_single_phase']['boolean'] !== 'true' ? false : true; // positive phase only - left (a-leg) top, right (b-leg) bottom
Waveform::$singleAxis = empty($_SESSION['theme']['audio_player_waveform_single_axis']['boolean']) || $_SESSION['theme']['audio_player_waveform_single_axis']['boolean'] !== 'false' ? true : false; // combine channels into single axis
$height = !empty($_SESSION['theme']['audio_player_waveform_height']['text']) && is_numeric(str_replace('px','',$_SESSION['theme']['audio_player_waveform_height']['text'])) ? 2.2 * (int) str_replace('px','',$_SESSION['theme']['audio_player_waveform_height']['text']) : null;
$wf = $waveform->getWaveform($temp_filename, 1600, $height ?? 180); // input: png filename returns boolean true/false, or 'base64' returns base64 string
$wf = $waveform->getWaveform($greeting_dir.'/'.$temp_filename, 1600, $height ?? 180); // input: png filename returns boolean true/false, or 'base64' returns base64 string
}
//stream image to browser
if ($wf === true && file_exists($temp_filename)) {
if ($wf === true && file_exists($greeting_dir.'/'.$temp_filename)) {
ob_clean();
$fd = fopen($temp_filename, 'rb');
$fd = fopen($greeting_dir.'/'.$temp_filename, 'rb');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
@@ -122,7 +122,7 @@
header('Content-Disposition: attachment; filename="'.$temp_filename.'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: ".filesize($temp_filename));
header("Content-Length: ".filesize($greeting_dir.'/'.$temp_filename));
ob_clean();
fpassthru($fd);
@@ -140,7 +140,7 @@
unset($row);
//delete temp waveform image
@unlink($temp_filename);
@unlink($greeting_dir.'/'.$temp_filename);
}