diff --git a/app/recordings/app_config.php b/app/recordings/app_config.php index 97bcd5017e..4f20949887 100644 --- a/app/recordings/app_config.php +++ b/app/recordings/app_config.php @@ -178,6 +178,11 @@ $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'] = "recording_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']['text'] = "recording_description"; $apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "descr"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; diff --git a/app/recordings/recording_edit.php b/app/recordings/recording_edit.php index 2d6ba29e04..3216b5d982 100644 --- a/app/recordings/recording_edit.php +++ b/app/recordings/recording_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-2020 + Portions created by the Initial Developer are Copyright (C) 2008-2024 the Initial Developer. All Rights Reserved. Contributor(s): @@ -42,18 +42,38 @@ $language = new text; $text = $language->get(); +//add the settings object + $settings = new settings(["domain_uuid" => $SESSION['domain_uuid']]); + $speech_enabled = $settings->get('ai', 'speech_enabled'); + $transcribe_enabled = $settings->get('ai', 'transcribe_enabled'); + +//add the audio object and get the voices and languages arrays + if ($speech_enabled == 'true' || $transcribe_enabled == 'true') { + $ai = new ai($settings); + $voices = $ai->get_voices(); + $translate_enabled = false; + $language_enabled = false; + //$translate_enabled = $ai->get_translate_enabled(); + //$language_enabled = $ai->get_language_enabled(); + //$languages = $ai->get_languages(); + } + //get recording id if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $recording_uuid = $_REQUEST["id"]; } //get the form value and set to php variables - if (count($_POST) > 0) { + if (!empty($_POST)) { + $recording_filename = $_POST["recording_filename"]; $recording_filename_original = $_POST["recording_filename_original"]; $recording_name = $_POST["recording_name"]; + $recording_voice = $_POST["recording_voice"]; + $recording_language = $_POST["recording_language"]; + //$translate = $_POST["translate"]; + $recording_message = $_POST["recording_message"]; $recording_description = $_POST["recording_description"]; - //sanitize recording filename and name $recording_filename_ext = strtolower(pathinfo($recording_filename, PATHINFO_EXTENSION)); if (!in_array($recording_filename_ext, ['wav','mp3','ogg'])) { @@ -68,26 +88,29 @@ $recording_name = str_replace("'", '', $recording_name); } -if (count($_POST) > 0 && empty($_POST["persistformvar"])) { - //get recording uuid to edit +//process the HTTP POST + if (!empty($_POST) && empty($_POST["persistformvar"])) { + //get recording uuid to edit $recording_uuid = $_POST["recording_uuid"]; - //delete the recording + //delete the recording if (permission_exists('recording_delete')) { if ($_POST['action'] == 'delete' && is_uuid($recording_uuid)) { //prepare - $array[0]['checked'] = 'true'; - $array[0]['uuid'] = $recording_uuid; + $array[0]['checked'] = 'true'; + $array[0]['uuid'] = $recording_uuid; + //delete - $obj = new switch_recordings; - $obj->delete($array); + $obj = new switch_recordings; + $obj->delete($array); + //redirect - header('Location: recordings.php'); - exit; + header('Location: recordings.php'); + exit; } } - //validate the token + //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); @@ -95,10 +118,10 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { exit; } - //check for all required data + //check for all required data $msg = ''; - if (empty($recording_filename)) { $msg .= $text['label-edit-file']."
\n"; } - if (empty($recording_name)) { $msg .= $text['label-edit-recording']."
\n"; } + if (empty($recording_name)) { $msg .= $text['label-edit_recording']."
\n"; } + //if (empty($recording_filename)) { $msg .= $text['label-edit_file']."
\n"; } if (!empty($msg) && empty($_POST["persistformvar"])) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; @@ -112,43 +135,88 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { return; } - //update the database - if (empty($_POST["persistformvar"])) { - if (permission_exists('recording_edit')) { - //if file name is not the same then rename the file + //add the bridge_uuid + if (empty($recording_uuid)) { + $recording_uuid = uuid(); + } + + //set the default voice + if (empty($recording_voice)) { + $recording_voice = 'alloy'; + } + + //set the recording format + if (empty($recording_format)) { + $recording_format = 'wav'; + } + + //update the database + if (empty($_POST["persistformvar"])) { + if (permission_exists('recording_edit')) { + //if file name is not the same then rename the file if ($recording_filename != $recording_filename_original) { rename($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); } - //build array - $array['recordings'][0]['domain_uuid'] = $domain_uuid; - $array['recordings'][0]['recording_filename'] = $recording_filename; - $array['recordings'][0]['recording_name'] = $recording_name; - $array['recordings'][0]['recording_description'] = $recording_description; + //build the setting object and get the recording path + $recording_path = $settings->get('switch', 'recordings').'/'.$_SESSION['domain_name']; + + //create the file name + if (empty($recording_filename)) { + $recording_filename = $recording_name.'.'.$recording_format; + } + + //text to audio - make a new audio file from the message + if ($speech_enabled == 'true' && !empty($recording_voice) && !empty($recording_message)) { + $ai->audio_path = $recording_path; + $ai->audio_filename = $recording_filename; + $ai->audio_format = $recording_format; + $ai->audio_voice = $recording_voice; + //$ai->audio_language = $recording_language; + //$ai->audio_translate = $translate; + $ai->audio_message = $recording_message; + $ai->speech(); + } + + //audio to text - get the transcription from the audio file + if ($transcribe_enabled == 'true' && empty($recording_message)) { + $ai->audio_path = $recording_path; + $ai->audio_filename = $recording_filename; + $recording_message = $ai->transcribe(); + } + + //build array $array['recordings'][0]['domain_uuid'] = $domain_uuid; $array['recordings'][0]['recording_uuid'] = $recording_uuid; + $array['recordings'][0]['recording_filename'] = $recording_filename; + $array['recordings'][0]['recording_name'] = $recording_name; + if ($speech_enabled == 'true' || $transcribe_enabled == 'true') { + $array['recordings'][0]['recording_message'] = $recording_message; + } + $array['recordings'][0]['recording_description'] = $recording_description; - //execute update + //execute update $database = new database; $database->app_name = 'recordings'; $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e'; $database->save($array); unset($array); - //set message + //set message message::add($text['message-update']); - //redirect + //redirect header("Location: recordings.php"); exit; + } } } -} //pre-populate the form if (!empty($_GET) && empty($_POST["persistformvar"])) { $recording_uuid = $_GET["id"]; - $sql = "select recording_name, recording_filename, recording_description from v_recordings "; + $sql = "select recording_name, recording_filename, recording_message, recording_description "; + $sql .= "from v_recordings "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and recording_uuid = :recording_uuid "; $parameters['domain_uuid'] = $domain_uuid; @@ -158,6 +226,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { if (is_array($row) && @sizeof($row) != 0) { $recording_filename = $row["recording_filename"]; $recording_name = $row["recording_name"]; + $recording_message = $row["recording_message"]; $recording_description = $row["recording_description"]; } unset($sql, $parameters, $row); @@ -203,21 +272,105 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; - echo " ".$text['label-file_name']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - //echo $text['message-file']."\n"; - echo "\n"; - echo "\n"; + if (!empty($_REQUEST["id"])) { + echo "\n"; + echo "\n"; + echo " ".$text['label-file_name']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo $text['description-file_name']."\n"; + echo "\n"; + echo "\n"; + } + + if ($speech_enabled == 'true' || $transcribe_enabled == 'true') { + echo "\n"; + echo "\n"; + echo " ".$text['label-voice']."\n"; + echo "\n"; + echo "\n"; + if (!empty($voices)) { + echo " \n"; + } + else { + echo " \n"; + } + echo "
\n"; + echo $text['description-voice']."\n"; + echo "\n"; + echo "\n"; + + if ($language_enabled) { + echo "\n"; + echo "\n"; + echo " ".$text['label-language']."\n"; + echo "\n"; + echo "\n"; + if (!empty($languages)) { + sort($languages); + echo " \n"; + } + else { + echo " \n"; + } + echo "
\n"; + echo $text['description-languages']."\n"; + echo "\n"; + echo "\n"; + } + + if ($translate_enabled) { + echo "\n"; + echo "\n"; + echo " ".$text['label-translate']."\n"; + echo "\n"; + echo "\n"; + if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') { + echo " \n"; + } + else { + echo " \n"; + } + echo "
\n"; + echo $text['description-translate']."\n"; + echo "\n"; + echo "\n"; + } + + echo "\n"; + echo "\n"; + echo " ".$text['label-message']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-message']."\n"; + echo "\n"; + echo "\n"; + } echo "\n"; echo "\n"; - echo " Description\n"; + echo " ".$text['label-description']."\n"; echo "\n"; echo "\n"; echo " \n"; @@ -237,4 +390,4 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/recordings/recordings.php b/app/recordings/recordings.php index 418ac6b205..954a004334 100644 --- a/app/recordings/recordings.php +++ b/app/recordings/recordings.php @@ -402,12 +402,16 @@ echo "
\n"; echo "
".$text['title-recordings']." (".$num_rows.")
\n"; echo "
\n"; + if (permission_exists('recording_add') && $speech_enabled == 'true') { + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'recording_edit.php']); + } if (permission_exists('recording_upload')) { echo "
\n"; echo "\n"; echo "\n"; echo "\n"; - echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','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_add','onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]); echo "