From 29214e7e67fa9653c5b95e829edfc6fb803729fe Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Wed, 28 Jan 2026 15:35:30 -0700 Subject: [PATCH] Fix voicemail greetings file extension Steps to reproduce the issue current greeting is a wav file. The text-to-speech provider used mp3. Then it would change the file type to mp3. Moved the $speech->get_format(); to the section of code that generates the text-to-speech. So that it doesn't overwrite the file type when its not the text to speech is not being used. --- .../voicemail_greeting_edit.php | 83 ++++++++++++------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/app/voicemail_greetings/voicemail_greeting_edit.php b/app/voicemail_greetings/voicemail_greeting_edit.php index 0e05188b14..e089803a64 100644 --- a/app/voicemail_greetings/voicemail_greeting_edit.php +++ b/app/voicemail_greetings/voicemail_greeting_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2024 + Portions created by the Initial Developer are Copyright (C) 2008-2026 the Initial Developer. All Rights Reserved. Contributor(s): @@ -47,7 +47,7 @@ $user_uuid = $_SESSION['user_uuid']; //add the settings object - $settings = new settings(["domain_uuid" => $domain_uuid, "user_uuid" => $user_uuid]); + $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); //as long as the class exists, enable speech using default settings $speech_enabled = class_exists('speech') && $settings->get('speech', 'enabled', false); @@ -65,18 +65,25 @@ $language_enabled = false; //add the speech object and get the voices and languages arrays - if ($speech_enabled && !empty($speech_engine)) { + if (class_exists('speech') && $speech_enabled && !empty($speech_engine)) { $speech = new speech($settings); $voices = $speech->get_voices(); - $greeting_format = $speech->get_format(); //$speech_models = $speech->get_models(); //$translate_enabled = $speech->get_translate_enabled(); //$language_enabled = $speech->get_language_enabled(); //$languages = $speech->get_languages(); + + // Determine the aray type single, or multi + $voices_array_type = array_type($voices); + + // Sort the array by language code keys alphabetically + if ($voices_array_type == 'multi') { + ksort($voices); + } } //add the transcribe object and get the languages arrays - if ($transcribe_enabled && !empty($transcribe_engine)) { + if (class_exists('transcribe') && $transcribe_enabled && !empty($transcribe_engine)) { $transcribe = new transcribe($settings); //$transcribe_models = $transcribe->get_models(); //$translate_enabled = $transcribe->get_translate_enabled(); @@ -118,15 +125,17 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { if (permission_exists('voicemail_greeting_delete')) { if (!empty($_POST['action']) && $_POST['action'] == 'delete' && is_uuid($voicemail_greeting_uuid)) { //prepare - $array[0]['checked'] = 'true'; - $array[0]['uuid'] = $voicemail_greeting_uuid; + $array[0]['checked'] = 'true'; + $array[0]['uuid'] = $voicemail_greeting_uuid; + //delete - $obj = new voicemail_greetings; - $obj->voicemail_id = $voicemail_id; - $obj->delete($array); + $obj = new voicemail_greetings; + $obj->voicemail_id = $voicemail_id; + $obj->delete($array); + //redirect - header("Location: voicemail_greetings.php?id=".$voicemail_id); - exit; + header("Location: voicemail_greetings.php?id=".$voicemail_id); + exit; } } @@ -162,7 +171,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { $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'] = $domain_uuid; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['voicemail_id'] = $voicemail_id; $rows = $database->select($sql, $parameters, 'all'); $greeting_ids = array(); @@ -177,7 +186,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { $greeting_path = $settings->get('switch', 'voicemail').'/default/'.$_SESSION['domain_name'].'/'.$voicemail_id; //set the recording format - $greeting_files = glob($greeting_path.'/greeting_'.$greeting_id.'.*'); + $greeting_files = glob($greeting_path.'/greeting_*'); if (empty($greeting_format) && !empty($greeting_files)) { $greeting_format = pathinfo($greeting_files[0], PATHINFO_EXTENSION); } else { @@ -195,14 +204,21 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { } } - if (!empty($greeting_id)) { + if (isset($greeting_id) && is_numeric($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 && !empty($greeting_voice) && !empty($greeting_message)) { + //set the greeting file format + $greeting_format = $speech->get_format(); + + //set file name + $greeting_filename = 'greeting_'.$greeting_id.'.'.$greeting_format; + $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; @@ -213,8 +229,8 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { //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('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); @@ -222,10 +238,10 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { } //audio to text - get the transcription from the audio file - if ($transcribe_enabled && empty($greeting_voice) && empty($greeting_message)) { + if ($transcribe_enabled && empty($greeting_message)) { $transcribe->audio_path = $greeting_path; $transcribe->audio_filename = $greeting_filename; - $greeting_message = $transcribe->transcribe(); + $greeting_message = $transcribe->transcribe('text'); } //if base64 is enabled base64 @@ -235,10 +251,11 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { //build data array $array['voicemail_greetings'][0]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid; - $array['voicemail_greetings'][0]['domain_uuid'] = $domain_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_voice'] = $greeting_voice; $array['voicemail_greetings'][0]['greeting_message'] = $greeting_message; $array['voicemail_greetings'][0]['greeting_filename'] = $greeting_filename; $array['voicemail_greetings'][0]['greeting_base64'] = $greeting_base64; @@ -257,21 +274,25 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { //redirect header("Location: voicemail_greetings.php?id=".$voicemail_id); - exit; + exit; } } //pre-populate the form - if ($action == 'update' && !empty($voicemail_greeting_uuid) && is_uuid($voicemail_greeting_uuid) && (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; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $greeting_id = $row["greeting_id"]; $greeting_name = $row["greeting_name"]; + $greeting_filename = $row['greeting_filename']; + $greeting_voice = $row["greeting_voice"]; $greeting_message = $row["greeting_message"]; $greeting_description = $row["greeting_description"]; } @@ -292,9 +313,9 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { echo "
\n"; echo "
".$text['label-'.($action == 'update' ? 'edit' : 'add')]."
\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','collapse'=>'hide-xs','link'=>'voicemail_greetings.php?id='.urlencode($voicemail_id)]); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','collapse'=>'hide-xs','link'=>'voicemail_greetings.php?id='.urlencode($voicemail_id)]); if (permission_exists('voicemail_greeting_delete') && $action == 'update') { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('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'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'name'=>'btn_delete','collapse'=>'hide-xs','style'=>'margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','collapse'=>'hide-xs']); echo "
\n"; @@ -338,9 +359,9 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { echo "\n"; echo "\n"; } -// else { -// echo "\n"; -// } + // else { + // echo "\n"; + // } //voices echo "\n"; @@ -352,8 +373,8 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { echo " \n"; } else { @@ -417,7 +438,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) { echo " ".$text['label-message']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-message']."\n"; echo "\n";