Skip to content

Add support for OpenAI text-to-speech instructions parameter#1011

Merged
dkotter merged 8 commits intodevelopfrom
feat/998-instruction-param
Sep 24, 2025
Merged

Add support for OpenAI text-to-speech instructions parameter#1011
dkotter merged 8 commits intodevelopfrom
feat/998-instruction-param

Conversation

@faisal-alvi
Copy link
Contributor

@faisal-alvi faisal-alvi commented Sep 18, 2025

Description of the Change

This PR adds support for OpenAI's instructions parameter in the text-to-speech feature, allowing users to control voice characteristics using natural language instructions.

image

Changes made:

  • Added a new "Voice instructions" textarea field to the OpenAI Text-to-Speech settings

  • Updated default settings to include the instructions parameter

  • Modified the API request to include instructions when provided

  • Added get_instructions() method with filter support

  • Added two new filters: classifai_openai_text_to_speech_instructions and classifai_openai_text_to_speech_request_body

  • Users can now control voice characteristics with natural language (e.g., "Speak in a calm, professional tone")

  • Provides more flexibility in audio generation

  • Maintains backward compatibility (instructions are optional)

Approaches considered:

  • Initially considered making this a universal setting across all TTS providers, but research showed that each provider uses different approaches (OpenAI uses natural language, Amazon Polly uses SSML, Azure uses SSML tags, ElevenLabs uses technical parameters)
  • Decided to keep this OpenAI-specific to maintain clean separation of concerns

Closes #998, Closes #997

How to test the Change

  1. Build the frontend assets:

    npm run build
  2. Access the settings:

    • Go to WordPress Admin > Tools > ClassifAI > Language Processing > Text to Speech > Settings
    • Select "OpenAI Text to Speech" as provider
    • Verify the new "Voice instructions" field appears below "Audio speed"
  3. Test the functionality:

    • Enter test instructions like "Say Welcome before starting", "Speak in a calm, professional tone" or "Use a more energetic delivery"
    • Save settings
    • Create/edit a post and generate text-to-speech audio
    • Verify the audio reflects the voice characteristics specified in instructions
  4. Test filters:

    add_filter( 'classifai_openai_text_to_speech_instructions', function( $instructions ) {
        return $instructions . ' Speak with enthusiasm.';
    });

Changelog Entry

Added - Support for OpenAI text-to-speech instructions parameter to control voice characteristics

Credits

Props @swissky @dkotter @faisalalvi

Checklist:

@faisal-alvi faisal-alvi self-assigned this Sep 18, 2025
@github-actions github-actions bot added this to the Future Release milestone Sep 18, 2025
/home/runner/work/classifai/classifai/src/js/settings/components/provider-settings/openai-text-to-speech.js
Error:   209:29  error  Replace `·onChange(·{·instructions:·value·}·)·` with `⏎↹↹↹↹↹↹onChange(·{·instructions:·value·}·)⏎↹↹↹↹↹`  prettier/prettier
Error:   212:20  error  Use ellipsis character (…) in place of three dots                                                        @wordpress/i18n-ellipsis
@faisal-alvi faisal-alvi marked this pull request as ready for review September 19, 2025 14:30
@faisal-alvi faisal-alvi requested review from a team, dkotter and jeffpaul as code owners September 19, 2025 14:30
@faisal-alvi faisal-alvi removed request for a team and jeffpaul September 19, 2025 14:30
@github-actions github-actions bot added the needs:code-review This requires code review. label Sep 19, 2025
@dkotter dkotter merged commit b79234f into develop Sep 24, 2025
19 checks passed
@dkotter dkotter deleted the feat/998-instruction-param branch September 24, 2025 15:16
@dkotter dkotter modified the milestones: Future Release, 3.7.1 Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for the instructions parameter when generating speech using OpenAI Controll Text2Speak Language

2 participants