common = $common; } public function itron_polly_tts_add_menu() { $this->plugin_screen_hook_suffix = add_submenu_page( 'itron_polly_tts', 'Text-To-Speech', 'Text-To-Speech', 'manage_options', 'itron_polly_tts_polly', array( $this, 'render_text_to_speech_page' ) ); } public function render_text_to_speech_page() { $this->can_load_voice_catalog(); ?>

AI Text-to-Speech using AWS Polly

register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_polly_enable', array( $this, 'sanitize_checkbox_option' ) ); add_settings_section( 'itron_polly_tts_polly', 'Amazon Polly configuration', array( $this, 'polly_gui' ), 'itron_polly_tts_polly' ); add_settings_field( 'itron_polly_tts_source_language', __( 'Source language:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'source_language_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_source_language' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_source_language', array( $this, 'sanitize_source_language' ) ); add_settings_field( 'itron_polly_tts_polly_enable', __( 'Enable text-to-speech support:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'polly_enabled_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_polly_enable' ) ); add_settings_field( 'itron_polly_tts_disable_post_voice_override', __( 'Lock post voice to global setting:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'disable_post_voice_override_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_disable_post_voice_override' ) ); add_settings_field( 'itron_polly_tts_voice_id', __( 'Voice name:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'voices_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_voice_id' ) ); add_settings_field( 'itron_polly_tts_neural', __( 'Neural Text-To-Speech:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'neural_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_neural' ) ); add_settings_field( 'itron_polly_tts_speaking_style', __( 'Speaking Style:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'speaking_style_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_speaking_style' ) ); add_settings_field( 'itron_polly_tts_sample_rate', __( 'Sample rate:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'sample_rate_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_sample_rate' ) ); add_settings_field( 'itron_polly_tts_auto_breaths', __( 'Automated breaths:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'auto_breaths_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_auto_breaths_id' ) ); add_settings_field( 'itron_polly_tts_ssml', __( 'Enable SSML support:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'ssml_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_ssml' ) ); add_settings_field( 'itron_polly_tts_lexicons', __( 'Lexicons:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'lexicons_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_lexicons' ) ); add_settings_field( 'itron_polly_tts_speed', __( 'Audio speed [%]:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'audio_speed_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_polly', array( 'label_for' => 'itron_polly_tts_speed' ) ); add_settings_section( 'itron_polly_tts_playersettings', __( 'Player settings', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'playersettings_gui' ), 'itron_polly_tts_polly' ); add_settings_field( 'itron_polly_tts_position', __( 'Player position:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'playerposition_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_playersettings', array( 'label_for' => 'itron_polly_tts_position' ) ); add_settings_field( 'itron_polly_tts_player_label', __( 'Player label:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'playerlabel_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_playersettings', array( 'label_for' => 'itron_polly_tts_player_label' ) ); add_settings_field( 'itron_polly_tts_defconf', __( 'New post default:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'defconf_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_playersettings', array( '' => 'itron_polly_tts_defconf' ) ); add_settings_field( 'itron_polly_tts_autoplay', __( 'Autoplay:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'autoplay_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_playersettings', array( 'label_for' => 'itron_polly_tts_autoplay' ) ); add_settings_field( 'itron_polly_tts_coming_soon_text', __( 'Coming Soon Text:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'coming_soon_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_playersettings', array( 'label_for' => 'itron_polly_tts_coming_soon' ) ); add_settings_section( 'itron_polly_tts_pollyadditional', __( 'Additional configuration', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'pollyadditional_gui' ), 'itron_polly_tts_polly' ); add_settings_field( 'itron_polly_tts_add_post_title', __( 'Add post title to audio:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'add_post_title_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_add_post_title' ) ); add_settings_field( 'itron_polly_tts_add_post_excerpt', __( 'Add post excerpt to audio:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'add_post_excerpt_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_add_post_excerpt' ) ); add_settings_field( 'itron_polly_tts_medialibrary_enabled', __( 'Enable Media Library support:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'medialibrary_enabled_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_medialibrary_enabled' ) ); add_settings_field( 'itron_polly_tts_skip_tags', __( 'Skip tags:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'skiptags_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_skip_tags' ) ); add_settings_field( 'itron_polly_tts_download_enabled', __( 'Enable download audio:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'download_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_download_enabled' ) ); add_settings_field( 'itron_polly_tts_s3', __( 'Store audio in Amazon S3:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 's3_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_s3' ) ); add_settings_field( 'itron_polly_tts_posttypes', __( 'Post types:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'posttypes_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_posttypes' ) ); add_settings_field( 'itron_polly_tts_cloudfront', __( 'Amazon CloudFront (CDN) domain name:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'cloudfront_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_cloudfront' ) ); add_settings_field( 'itron_polly_tts_poweredby', __( 'Display public AWS Polly credit:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'poweredby_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_poweredby' ) ); add_settings_field( 'itron_polly_tts_logging', __( 'Enable logging:', 'ai-text-to-speech-using-aws-polly' ), array( $this, 'logging_gui' ), 'itron_polly_tts_polly', 'itron_polly_tts_pollyadditional', array( 'label_for' => 'itron_polly_tts_logging' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_disable_post_voice_override', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_voice_id', array( $this, 'sanitize_voice_id' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_neural', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_speaking_style', array( $this, 'sanitize_speaking_style' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_sample_rate', array( $this, 'sanitize_sample_rate' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_auto_breaths', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_ssml', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_lexicons', array( $this, 'sanitize_text_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_speed', array( $this, 'sanitize_audio_speed' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_position', array( $this, 'sanitize_player_position' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_player_label', array( $this, 'sanitize_text_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_defconf', array( $this, 'sanitize_default_configuration' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_autoplay', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_coming_soon_text', array( $this, 'sanitize_textarea_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_add_post_title', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_add_post_excerpt', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_medialibrary_enabled', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_skip_tags', array( $this, 'sanitize_text_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_download_enabled', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_s3', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_posttypes', array( $this, 'sanitize_posttypes' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_cloudfront', array( $this, 'sanitize_text_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_poweredby', array( $this, 'sanitize_checkbox_option' ) ); $this->register_sanitized_setting( 'itron_polly_tts_polly', 'itron_polly_tts_logging', array( $this, 'sanitize_checkbox_option' ) ); } private function register_sanitized_setting( string $option_group, string $option_name, callable $sanitize_callback ): void { register_setting( $option_group, $option_name, array( 'sanitize_callback' => $sanitize_callback, ) ); } private function is_option_enabled( string $option_name ): bool { return ! empty( get_option( $option_name, '' ) ); } private function can_load_voice_catalog(): bool { if ( ! $this->common->is_polly_enabled() || ! $this->common->has_aws_credentials() ) { return false; } if ( null !== $this->catalog_available ) { return $this->catalog_available; } try { $this->catalog_available = ! empty( $this->common->get_polly_voices()['Voices'] ); } catch ( \Throwable $e ) { $this->catalog_available = false; } if ( ! $this->catalog_available ) { add_settings_error( 'itron_polly_tts_polly', 'itron_polly_tts_catalog_unavailable', __( 'Unable to load Amazon Polly voices. Check your AWS credentials, region, polly:DescribeVoices permission and server connectivity. Existing settings have been preserved.', 'ai-text-to-speech-using-aws-polly' ) ); } return $this->catalog_available; } public function sanitize_checkbox_option( $value ): string { return empty( $value ) ? '' : 'on'; } public function sanitize_text_option( $value ): string { return sanitize_text_field( wp_unslash( (string) $value ) ); } public function sanitize_textarea_option( $value ): string { return sanitize_textarea_field( wp_unslash( (string) $value ) ); } public function sanitize_source_language( $language_code ): string { $language_code = sanitize_text_field( wp_unslash( (string) $language_code ) ); if ( ! in_array( $language_code, $this->common->get_all_languages(), true ) ) { $language_code = $this->common->get_source_language(); } $this->source_language_for_sanitization = $language_code; return $language_code; } public function sanitize_player_position( $position ): string { $position = sanitize_text_field( wp_unslash( (string) $position ) ); $allowed = array( 'Before post', 'After post', 'Do not show' ); if ( in_array( $position, $allowed, true ) ) { return $position; } return 'Before post'; } public function sanitize_default_configuration( $value ): string { $value = sanitize_text_field( wp_unslash( (string) $value ) ); $allowed = array( 'Amazon Polly enabled', 'Amazon Polly disabled' ); if ( in_array( $value, $allowed, true ) ) { return $value; } return 'Amazon Polly disabled'; } /** * Render the Enable Text-To-Speech functionality option. * * @since 0.1 */ public function polly_enabled_gui() { echo 'is_option_enabled( 'itron_polly_tts_polly_enable' ), true, false ) . '> '; } /** * Render the public AWS Polly credit option. * * @since 0.1 */ function poweredby_gui() { echo 'common->is_poweredby_enabled(), true, false ) . '>

'; echo '

Optional public text credit for AWS Polly. Disabled by default. The plugin does not add external links to the public site.

'; } /** * Render the Amazon Polly source language input. * * @since 0.1 */ public function source_language_gui() { $selected_source_language = $this->common->get_source_language(); echo ''; } /** * Render the 'use CloudFront' input. * * @since 0.1 */ public function cloudfront_gui() { $is_s3_enabled = $this->common->is_s3_enabled(); if ( $is_s3_enabled ) { $cloudfront_domain_name = get_option( 'itron_polly_tts_cloudfront' ); echo ' '; echo '

If you have a CloudFront distribution for your S3 bucket, enter the domain name. For more information and pricing, see https://aws.amazon.com/cloudfront

'; } else { echo ''; echo '

Amazon S3 storage needs to be enabled

'; } } /** * Render the 'store in S3' input. * * @since 0.1 */ function s3_gui() { $is_s3_enabled = $this->common->is_s3_enabled(); if ( $is_s3_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo '

'; echo '

Audio files are saved to and streamed from Amazon S3. For more information, see https://aws.amazon.com/s3

'; } /** * Render the 'Enable Logging' input. * * @since 0.1 */ function logging_gui() { $checked = $this->common->checked_validator( 'itron_polly_tts_logging' ); echo '

'; } /** * Render the Add post excerpt to audio input. * * @since 0.1 */ public function add_post_excerpt_gui() { echo 'is_option_enabled( 'itron_polly_tts_add_post_excerpt' ), true, false ) . '> '; echo '

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

'; } public function download_gui() { echo 'is_option_enabled( 'itron_polly_tts_download_enabled' ), true, false ) . '> '; echo '

If enabled, viewers will see a download button next to the audio

'; } /** * Render the Add post title to audio input. * * @since 0.1 */ public function add_post_title_gui() { echo 'is_option_enabled( 'itron_polly_tts_add_post_title' ), true, false ) . '> '; echo '

If enabled, each audio file will start from the post\'s title.

'; } /** * Render the Post Type input box. * * @since 0.1 */ public function posttypes_gui() { $posttypes = $this->common->get_posttypes(); echo ' '; echo '

Post types in your WordPress environment

'; } public function sanitize_voice_id( $voice_id ) { $voice_id = sanitize_text_field( wp_unslash( $voice_id ) ); if ( ! $this->can_load_voice_catalog() ) { return $voice_id; } $language_code = $this->source_language_for_sanitization ?? $this->common->get_source_language(); return $this->common->get_resolved_polly_voice_option( 'itron_polly_tts_voice_id', $language_code, 'Matthew', array( 'requested_voice_id' => $voice_id, ) ); } public function sanitize_sample_rate( $sample_rate ) { return $this->common->normalize_sample_rate( sanitize_text_field( wp_unslash( $sample_rate ) ) ); } public function sanitize_posttypes( $posttypes ) { return $this->common->normalize_posttypes( wp_unslash( $posttypes ) ); } public function sanitize_audio_speed( $speed ) { return $this->common->normalize_audio_speed( wp_unslash( $speed ) ); } public function sanitize_speaking_style( $style ) { return $this->common->normalize_polly_speaking_style( sanitize_text_field( wp_unslash( $style ) ) ); } private function render_dynamic_checkbox_option( $option_name, $option_id, $is_checked, $show_checkbox, $description, $message, array $data_attributes = array() ) { echo '
$attribute_value ) { echo ' data-' . esc_attr( $attribute_name ) . '="' . esc_attr( $attribute_value ) . '"'; } echo '>'; echo ''; echo ''; echo ''; echo '
'; } private function render_dynamic_radio_option( $option_name, $option_id, $selected_value, $show_group, $description, $message, array $choices, array $data_attributes = array() ) { echo '
$attribute_value ) { echo ' data-' . esc_attr( $attribute_name ) . '="' . esc_attr( $attribute_value ) . '"'; } echo '>'; echo ''; echo ''; echo ''; echo '
'; } /** * Render the Neural GUI * */ public function neural_gui() { if ( ! $this->can_load_voice_catalog() ) { $this->render_dynamic_checkbox_option( 'itron_polly_tts_neural', 'itron_polly_tts_neural', $this->is_option_enabled( 'itron_polly_tts_neural' ), true, 'Controls whether the plugin uses the Neural engine for compatible voices. Voice compatibility is checked when text-to-speech is enabled and credentials are configured.', '' ); return; } $voice_id = $this->common->get_resolved_polly_voice_option( 'itron_polly_tts_voice_id', $this->common->get_source_language(), 'Matthew' ); $is_region_supported = $this->common->is_neural_supported_in_region(); $is_voice_supported = $this->common->is_neural_supported_for_voice( $voice_id ); $show_checkbox = $is_region_supported && $is_voice_supported; $message = $is_region_supported ? 'Option not supported for this voice. Choose a voice from the Standard + Neural or Neural-only groups.' : 'Option not supported in this region'; $this->render_dynamic_checkbox_option( 'itron_polly_tts_neural', 'itron_polly_tts_neural', $this->common->is_polly_neural_requested(), $show_checkbox, 'Controls whether the plugin uses the Neural engine for compatible voices. Neural-only voices require this setting to remain enabled.', $message, array( 'region-supported' => $is_region_supported ? '1' : '0', 'message-region' => 'Option not supported in this region', 'message-voice' => 'Option not supported for this voice. Choose a voice from the Standard + Neural or Neural-only groups.', ) ); } public function speaking_style_gui() { if ( ! $this->can_load_voice_catalog() ) { $this->render_dynamic_radio_option( 'itron_polly_tts_speaking_style', 'itron_polly_tts_speaking_style', $this->common->normalize_polly_speaking_style( get_option( 'itron_polly_tts_speaking_style', '' ) ), true, 'Choose one Neural speaking style. Voice compatibility is checked when text-to-speech is enabled and credentials are configured.', '', array( array( 'value' => '', 'label' => 'Default', 'visible' => true, ), array( 'value' => 'news', 'label' => 'Newscaster Style', 'visible' => true, ), ) ); return; } $voice_id = $this->common->get_resolved_polly_voice_option( 'itron_polly_tts_voice_id', $this->common->get_source_language(), 'Matthew' ); $is_region_supported = $this->common->is_neural_supported_in_region(); $is_neural_requested = $this->common->is_polly_neural_requested(); $supports_news = $this->common->is_news_style_for_voice( $voice_id ); $show_group = $is_region_supported && $is_neural_requested && $supports_news; $selected_style = $this->common->get_active_polly_speaking_style( $voice_id ); if ( ! $is_region_supported ) { $message = 'Option not supported in this region'; } elseif ( ! $is_neural_requested ) { $message = 'Neural needs to be enabled'; } else { $message = 'The current voice does not support Newscaster style'; } $this->render_dynamic_radio_option( 'itron_polly_tts_speaking_style', 'itron_polly_tts_speaking_style', $selected_style, $show_group, 'Use the default voice or apply Newscaster style to a supported Neural voice.', $message, array( array( 'value' => '', 'label' => 'Default', 'visible' => true, ), array( 'value' => 'news', 'label' => 'Newscaster Style', 'visible' => $supports_news, ), ), array( 'region-supported' => $is_region_supported ? '1' : '0', 'message-region' => 'Option not supported in this region', 'message-neural' => 'Neural needs to be enabled', 'message-voice' => 'The current voice does not support Newscaster style', ) ); } /** * Render the autoplay input. * * @since 0.1 */ public function autoplay_gui() { $selected_autoplay = get_option( 'itron_polly_tts_autoplay' ); if ( empty( $selected_autoplay ) ) { $checked = ' '; } else { $checked = ' checked '; } echo ' '; echo '

Automatically play audio content when page loads

'; } public function coming_soon_gui() { $coming_soon = get_option( 'itron_polly_tts_coming_soon_text' ); echo ' '; } /** * Render the Default Configuration input. * * @since 0.1 */ public function defconf_gui() { $selected_defconf = get_option( 'itron_polly_tts_defconf' ); $defconf_values = array( 'Amazon Polly enabled', 'Amazon Polly disabled' ); echo ''; } /** * Render the Player Label input. * * @since 0.1 */ public function skiptags_gui() { $tags = get_option( 'itron_polly_tts_skip_tags' ); echo ' '; } /** * Render the Player Label input. * * @since 0.1 */ public function playerlabel_gui() { $player_label = get_option( 'itron_polly_tts_player_label' ); echo ' '; } /** * Render the Position input. * * @since 0.1 */ public function playerposition_gui() { $selected_position = get_option( 'itron_polly_tts_position' ); $positions_values = array( 'Before post', 'After post', 'Do not show' ); echo ''; } /** * Render the Sample Rate input for this plugin * * @since 0.1 */ public function sample_rate_gui() { $sample_rate = $this->common->get_sample_rate(); $sample_array = array( '24000', '22050', '16000', '8000' ); echo ''; } /** * Render the Player Label input. * * @since 0.1 */ public function lexicons_gui() { $lexicons = $this->common->get_lexicons(); echo ' '; echo '

Specify the lexicons names, seperated by spaces, that you have uploaded to your AWS account

'; } /** * Render the autoplay input. * * @since 0.1 */ public function audio_speed_gui() { $speed = $this->common->get_audio_speed(); echo ''; } public function disable_post_voice_override_gui() { echo 'common->is_post_voice_override_disabled(), true, false ) . '> '; echo '

When enabled, posts cannot override the global Polly voice. Existing per-post voice selections are ignored.

'; } /** * Render the enable SSML input. * * @since 0.1 */ 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 ''; echo '

Local storage needs to be enabled

'; } } /** * Render the enable SSML input. * * @since 0.1 */ public function ssml_gui() { echo 'common->is_ssml_enabled(), true, false ) . '> '; } /** * Render the Automated Breath input. * * @since 0.1 */ public function auto_breaths_gui() { echo 'is_option_enabled( 'itron_polly_tts_auto_breaths' ), true, false ) . '> '; echo '

Creates breathing noises at appropriate intervals

'; } private function render_voice_options( $language_code, $selected_voice_id ) { $voice_groups = $this->common->get_grouped_polly_voices( $language_code ); $has_voices = false; foreach ( $voice_groups as $group_key => $group ) { if ( empty( $group['voices'] ) ) { continue; } $has_voices = true; echo ''; foreach ( $group['voices'] as $voice ) { $is_neural_only = 'neural_only' === $group_key; $supported_engines = implode( ',', $voice['SupportedEngines'] ?? array() ); $capability_label = $this->common->get_polly_voice_capability_label( $voice ); echo ''; } echo ''; } return $has_voices; } /** * Render the Polly Voice input for this plugin * * @since 0.1 */ public function voices_gui() { $current_voice_id = sanitize_text_field( (string) get_option( 'itron_polly_tts_voice_id', '' ) ); if ( ! $this->can_load_voice_catalog() ) { echo ''; echo '

The saved voice will remain unchanged. Enable text-to-speech and configure AWS credentials to load available voices.

'; return; } $language_code = $this->common->get_source_language(); $voice_id = $this->common->get_resolved_polly_voice_option( 'itron_polly_tts_voice_id', $language_code, 'Matthew' ); $available_voice_list = $this->common->get_available_polly_voices( $language_code ); if ( empty( $available_voice_list ) ) { echo '

No supported voices are currently available for this language in the selected AWS region.

'; return; } echo ''; echo '

No supported voices are currently available for this language in the selected AWS region.

'; return; } echo ''; echo '

Voices are grouped by engine support. All voices stay selectable; choosing a Standard voice turns Neural off, and choosing a Neural-only voice turns Neural on automatically.

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