AI Text to Speech

How can we help?

Search the documentation or ask the AI agent anything about the plugin.

Hooks, filters and code examples

Updated September 15, 2026

AI Text to Speech provides filters and actions to change the text sent to OpenAI, the file URL, and the player HTML, plus a few helper functions. This reference covers version 3.2.0. Add snippets to a child theme’s functions.php or a code snippets plugin, and test on a staging site first.

Filters

FilterArgumentsPurpose
ai_tts_post_content$content, $post_idRaw text before any clean-up. $post_id is 0 on the Generator page. PRO uses priorities 10 and 100 to add custom text.
ai_tts_chunks$chunksArray of [ text, voice ] pairs after clean-up and the title intro, before splitting to API limits.
ai_tts_openai_tts_chunk_limits$limits, $voice_modelArray with max_chars (clamped 1 to 6000) and max_tokens (clamped 1 to 1800).
modify_ai_tts_file_url$file_url, $file_path, $file_name, $post_idAfter the MP3 is written, before the URL is saved to the post. Return a WP_Error to abort; the local file is deleted. Used by the Dropbox integration.
ai_tts_file_url$file_urlThe URL returned to the browser after saving. Post meta is already saved by this point.
ai_tts_audio_player$html, $post_idThe <audio> element HTML. The player label is appended after this filter.

Actions

ActionArgumentsWhen it fires
delete_ai_tts_file$file_url, $file_path, $post_idWhen a post’s audio is deleted, before its meta is removed.
ai_tts_meta_box_after$postAt the end of the AI TTS box in the editor.
aitts_settings_afternoneAfter the Settings and Generator pages (outputs the sidebar).
ai_tts_show_all_statsnoneAt the top of the PRO Statistics page.

Helper functions

  • ai_tts_get_option( $key ): read a setting from ai_tts_settings, with defaults.
  • ai_tts_create_audio_player(): returns the player and label HTML for the current post in the loop, or an empty string.
  • ai_tts_get_voices() and ai_tts_get_voice_styles(): arrays of available voices and styles.
  • ai_tts_delete_file_by_post( $post_id ): deletes a post’s audio and meta; returns true or WP_Error.

Example: leave code blocks and tables out of the audio

add_filter( 'ai_tts_post_content', function ( $content, $post_id ) {
    $content = preg_replace( '#<pre[^>]*>.*?</pre>#is', ' ', $content );
    $content = preg_replace( '#<table[^>]*>.*?</table>#is', ' ', $content );
    return $content;
}, 5, 2 );

Example: remove the automatic player on pages

add_action( 'wp', function () {
    if ( is_page() ) {
        remove_filter( 'the_content', 'ai_tts_add_audio_player' );
    }
} );

Example: output the player in a theme template

Remove the automatic player (as above, without the is_page() check), then call the helper inside the loop in your template:

<?php
if ( function_exists( 'ai_tts_create_audio_player' ) ) {
    echo ai_tts_create_audio_player(); // Player HTML is escaped by the plugin.
}
?>

Example: wrap the player in a container

add_filter( 'ai_tts_audio_player', function ( $html, $post_id ) {
    return '<div class="my-audio-box"><p>Prefer to listen?</p>' . $html . '</div>';
}, 20, 2 );

Example: use smaller API requests

add_filter( 'ai_tts_openai_tts_chunk_limits', function ( $limits, $model ) {
    $limits['max_chars'] = 3000;
    return $limits;
}, 10, 2 );

There is no dedicated hook to run code after audio is generated. You can use updated_post_meta / added_post_meta for the ai_tts_file_url key if you need that.

Related

Was this article helpful?