plugin_screen_hook_suffix = add_submenu_page( 'amazon_ai', 'Text-To-Speech', 'Text-To-Speech', 'manage_options', 'amazon_ai_polly', array( $this, 'amazonai_gui' )); } public function amazonai_gui() { ?>

Text To Speech - Amazon Polly

common = new AmazonAI_Common(); $this->common->init(); add_settings_section('amazon_ai_polly', "Amazon Polly configuration", array($this,'polly_gui'), 'amazon_ai_polly'); add_settings_field('amazon_ai_polly_enable', __('Enable text-to-speech support:', 'amazonpolly'), array($this,'polly_enabled_gui'), 'amazon_ai_polly', 'amazon_ai_polly', array('label_for' => 'amazon_ai_polly_enable')); register_setting('amazon_ai_polly', 'amazon_ai_polly_enable'); if ($this->is_language_supported()) { if ($this->common->validate_amazon_polly_access() ) { if ($this->common->is_polly_enabled()) { add_settings_field( 'amazon_polly_sample_rate', __('Sample rate:', 'amazonpolly'), array($this,'sample_rate_gui'), 'amazon_ai_polly', 'amazon_ai_polly', array('label_for' => 'amazon_polly_sample_rate')); add_settings_field( 'amazon_polly_voice_id', __( 'Voice name:', 'amazonpolly' ), array( $this, 'voices_gui' ), 'amazon_ai_polly', 'amazon_ai_polly', array( 'label_for' => 'amazon_polly_voice_id' ) ); add_settings_field( 'amazon_polly_auto_breaths', __( 'Automated breaths:', 'amazonpolly' ), array( $this, 'auto_breaths_gui' ), 'amazon_ai_polly', 'amazon_ai_polly', array( 'label_for' => 'amazon_polly_auto_breaths_id' ) ); add_settings_field( 'amazon_polly_ssml', __( 'Enable SSML support:', 'amazonpolly' ), array( $this, 'ssml_gui' ), 'amazon_ai_polly', 'amazon_ai_polly', array( 'label_for' => 'amazon_polly_ssml' ) ); add_settings_field( 'amazon_polly_lexicons', __( 'Lexicons:', 'amazonpolly' ), array( $this, 'lexicons_gui' ), 'amazon_ai_polly', 'amazon_ai_polly', array( 'label_for' => 'amazon_polly_lexicons' ) ); add_settings_field( 'amazon_polly_speed', __( 'Audio speed [%]:', 'amazonpolly' ), array( $this, 'audio_speed_gui' ), 'amazon_ai_polly', 'amazon_ai_polly', array( 'label_for' => 'amazon_polly_speed' ) ); add_settings_section( 'amazon_ai_playersettings', __( 'Player settings', 'amazonpolly' ), array( $this, 'playersettings_gui' ), 'amazon_ai_polly'); add_settings_field( 'amazon_polly_position', __( 'Player position:', 'amazonpolly' ), array( $this, 'playerposition_gui' ), 'amazon_ai_polly', 'amazon_ai_playersettings', array( 'label_for' => 'amazon_polly_position' ) ); add_settings_field( 'amazon_polly_player_label', __( 'Player label:', 'amazonpolly' ), array( $this, 'playerlabel_gui' ), 'amazon_ai_polly', 'amazon_ai_playersettings', array( 'label_for' => 'amazon_polly_player_label' ) ); add_settings_field( 'amazon_polly_defconf', __( 'New post default:', 'amazonpolly' ), array( $this, 'defconf_gui' ), 'amazon_ai_polly', 'amazon_ai_playersettings', array( '' => 'amazon_polly_defconf' ) ); add_settings_field( 'amazon_polly_autoplay', __( 'Autoplay:', 'amazonpolly' ), array( $this, 'autoplay_gui' ), 'amazon_ai_polly', 'amazon_ai_playersettings', array( 'label_for' => 'amazon_polly_autoplay' ) ); add_settings_section( 'amazon_ai_pollyadditional', __( 'Additional configuration', 'amazonpolly' ), array( $this, 'pollyadditional_gui' ), 'amazon_ai_polly'); add_settings_field( 'amazon_polly_update_all', __( 'Bulk update all posts:', 'amazonpolly' ), array( $this, 'update_all_gui' ),'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_polly_update_all' ) ); add_settings_field( 'amazon_polly_add_post_title', __( 'Add post title to audio:', 'amazonpolly' ), array( $this, 'add_post_title_gui' ), 'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_polly_add_post_title' ) ); add_settings_field( 'amazon_polly_add_post_excerpt', __( 'Add post excerpt to audio:', 'amazonpolly' ), array( $this, 'add_post_excerpt_gui' ), 'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_polly_add_post_excerpt' ) ); add_settings_field( 'amazon_ai_medialibrary_enabled', __( 'Enable Media Library support:', 'amazonpolly' ), array( $this, 'medialibrary_enabled_gui' ), 'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_ai_medialibrary_enabled' ) ); add_settings_field( 'amazon_ai_skip_tags', __( 'Skip tags:', 'amazonpolly' ), array( $this, 'skiptags_gui' ), 'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_ai_skip_tags' ) ); add_settings_field( 'amazon_ai_download_enabled', __( 'Enable download audio:', 'amazonpolly' ), array( $this, 'download_gui' ), 'amazon_ai_polly', 'amazon_ai_pollyadditional', array( 'label_for' => 'amazon_ai_download_enabled' ) ); //Registration register_setting('amazon_ai_polly', 'amazon_polly_sample_rate'); register_setting('amazon_ai_polly', 'amazon_polly_voice_id'); register_setting('amazon_ai_polly', 'amazon_polly_auto_breaths'); register_setting('amazon_ai_polly', 'amazon_polly_ssml'); register_setting('amazon_ai_polly', 'amazon_polly_lexicons'); register_setting('amazon_ai_polly', 'amazon_polly_speed'); register_setting('amazon_ai_polly', 'amazon_polly_position'); register_setting('amazon_ai_polly', 'amazon_polly_player_label'); register_setting('amazon_ai_polly', 'amazon_polly_defconf'); register_setting('amazon_ai_polly', 'amazon_polly_autoplay'); register_setting('amazon_ai_polly', 'amazon_polly_update_all'); register_setting('amazon_ai_polly', 'amazon_polly_add_post_title'); register_setting('amazon_ai_polly', 'amazon_polly_add_post_excerpt'); register_setting('amazon_ai_polly', 'amazon_ai_medialibrary_enabled'); register_setting('amazon_ai_polly', 'amazon_ai_skip_tags'); register_setting('amazon_ai_polly', 'amazon_ai_download_enabled'); } } } } /** * Render the Enable Text-To-Speech functionality option. * * @since 2.5.0 */ public function polly_enabled_gui() { if ($this->is_language_supported()) { $value = $this->common->checked_validator( 'amazon_ai_polly_enable' ); if ($this->common->validate_amazon_polly_access()) { echo 'common->checked_validator( 'amazon_ai_polly_enable' ) . '> '; } else { echo '

Please verify your AWS Credentials are accurate

'; } } else { echo '

Text-To-Speech functionality not supported for this language

'; } } private function is_language_supported() { $selected_source_language = $this->common->get_source_language(); foreach ($this->common->get_all_polly_languages() as $language_code) { if (strcmp($selected_source_language, $language_code) === 0) { return true; } } return false; } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function update_all_gui() { $message = $this->common->get_price_message_for_update_all(); echo '

'; echo ''; echo ''; echo '

'; echo '
'; echo '

' . esc_html( $message ) . '

'; echo '

'; echo '
Loading...
'; echo '
'; } /** * Render the Add post excerpt to audio input. * * @since 2.0.0 */ public function add_post_excerpt_gui() { echo 'common->checked_validator( 'amazon_polly_add_post_excerpt' ) . '> '; echo '

If enabled, each audio file will have post excerpt at the beginning.

'; } public function download_gui() { echo 'common->checked_validator( 'amazon_ai_download_enabled' ) . '> '; echo '

If enabled, browser will show download button next to audio

'; } /** * Render the Add post title to audio input. * * @since 1.0.7 */ public function add_post_title_gui() { echo 'common->checked_validator( 'amazon_polly_add_post_title' ) . '> '; echo '

If enabled, each audio file will start from post title.

'; } /** * Render the autoplay input. * * @since 1.0.0 */ public function autoplay_gui() { $selected_autoplay = get_option( 'amazon_polly_autoplay' ); if ( empty( $selected_autoplay ) ) { $checked = ' '; } else { $checked = ' checked '; } echo ' '; echo '

Automatically play audio content when page loads

'; } /** * Render the Default Configuration input. * * @since 1.0.0 */ public function defconf_gui() { $selected_defconf = get_option( 'amazon_polly_defconf' ); $defconf_values = [ 'Amazon Polly enabled', 'Amazon Polly disabled' ]; echo ''; } /** * Render the Player Label input. * * @since 1.0.3 */ public function skiptags_gui() { $tags = get_option( 'amazon_ai_skip_tags' ); echo ' '; } /** * Render the Player Label input. * * @since 1.0.3 */ public function playerlabel_gui() { $player_label = get_option( 'amazon_polly_player_label' ); echo ' '; } /** * Render the Position input. * * @since 1.0.0 */ public function playerposition_gui() { $selected_position = get_option( 'amazon_polly_position' ); $positions_values = array( 'Before post', 'After post', 'Do not show' ); echo ''; } /** * Render the Sample Rate input for this plugin * * @since 1.0.0 */ public function sample_rate_gui() { $sample_rate = $this->common->get_sample_rate(); $sample_array = array( '22050', '16000', '8000' ); echo ''; } /** * Render the Player Label input. * * @since 1.0.12 */ public function lexicons_gui() { $lexicons = $this->common->get_lexicons(); echo ' '; echo '

Specify lexicons names (seperated by space), which you have uploaded to your AWS account

'; } /** * Render the autoplay input. * * @since 1.0.5 */ public function audio_speed_gui() { $speed = $this->common->get_audio_speed(); echo ''; } /** * Render the enable SSML input. * * @since 1.0.7 */ public function medialibrary_enabled_gui() { $is_s3_enabled = $this->common->is_s3_enabled(); if ( !$is_s3_enabled ) { $is_medialibrary_enabled = $this->common->is_medialibrary_enabled(); if ( $is_medialibrary_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; } else { echo '

Local Storage needs to be enabled

'; } } /** * Render the enable SSML input. * * @since 1.0.7 */ public function ssml_gui() { $is_s3_enabled = $this->common->is_s3_enabled(); if ( $is_s3_enabled ) { $is_ssml_enabled = $this->common->is_ssml_enabled(); if ( $is_ssml_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; } else { echo '

Amazon S3 Storage needs to be enabled

'; } } /** * Render the Automated Breath input. * * @since 1.0.7 */ public function auto_breaths_gui() { echo 'common->checked_validator( 'amazon_polly_auto_breaths' ) . '> '; echo '

If enabled, Amazon Polly automatically creates breathing noises at appropriate intervals

'; } /** * Render the Polly Voice input for this plugin * * @since 1.0.0 */ public function voices_gui() { /** * Compare two voices for ordering purpose. * * @param string $voice1 First voice. * @param string $voice2 Second voice. * @since 1.0.0 */ function sort_voices( $voice1, $voice2 ) { return strcmp( $voice1['LanguageName'], $voice2['LanguageName'] ); } $voice_id = $this->common->get_voice_id(); $voice_list = $this->common->get_polly_voices(); $language_name = $this->common->get_source_language_name(); echo ''; } /** * Render the Access Key input for this plugin * * @since 1.0.0 */ function access_key_gui() { $access_key = get_option('amazon_polly_access_key'); echo ' '; echo '

Required only if you aren\'t using IAM roles

'; } function playersettings_gui() { // Empty } function polly_gui() { //Empty } function pollyadditional_gui() { //Empty } }