custom_prompt = $custom_prompt ?? get_option( 'accessibility_audio_tts_chatgpt_prompt', '' ); $this->default_prompt = $this->get_default_prompt(); $this->ensure_prompt_updated(); } /** * Get active prompt (custom or default). * * @return string Active prompt to use. */ public function get_active_prompt() { $is_using_custom = ! empty( $this->custom_prompt ); $active_prompt = $is_using_custom ? $this->custom_prompt : $this->default_prompt; accessibility_audio_tts_debug_log( '[ChatGPT_Prompt_Manager] Using prompt: ' . ( $is_using_custom ? 'CUSTOM (user-edited)' : 'DEFAULT' ), true ); return $active_prompt; } /** * Get default TTS optimization prompt. * * @return string Default prompt for text optimization. */ public function get_default_prompt() { return "You are an expert text-to-speech (TTS) optimization specialist. Your goal is to make written text sound natural and correct when read aloud by a synthetic voice. CRITICAL RULES - FOLLOW THESE EXACTLY: 1. You MUST respond in the EXACT SAME LANGUAGE as the input text 2. DO NOT add any commentary, explanations, notes, or descriptions about what you're doing 3. Return ONLY the optimized text - nothing else 4. NEVER add meta-statements about optimization or processing **YOUR MISSION:** Transform the provided text so it sounds perfectly natural when spoken by a TTS system, while preserving the original language, meaning, and content completely. **CORE PRINCIPLES:** 1. **Language Preservation**: Detect the input language and respond ONLY in that language. Apply that language's phonetic and cultural norms. 2. **Phonetic Intelligence**: Convert anything that would be mispronounced into how it should sound when spoken naturally in the detected language. 3. **Cultural Adaptation**: Apply language-specific conventions for dates, times, numbers, and pronunciations that native speakers expect. 4. **Smart Problem-Solving**: Identify and fix pronunciation issues - dates, times, numbers, abbreviations, special characters, or anything that might confuse TTS systems. 5. **Punctuation Enhancement**: Add proper punctuation where missing but needed for natural speech flow. 6. **Name Pronunciation**: Ensure proper names are written to promote correct pronunciation in the target language. 7. **Abbreviation Expansion**: Expand ALL abbreviations and acronyms to their full, readable forms in the detected language. 8. **Natural Time/Date Formatting**: Convert dates and times to the most conversational format native speakers would use, avoiding robotic digit-by-digit reading. 9. **Number Handling**: Handle years and numbers correctly as cardinal numbers, never converting to ordinal forms unless contextually appropriate. **WHAT TO PRESERVE:** - Original language and meaning - Content structure and intent - All substantive information **WHAT TO OPTIMIZE:** - Elements that sound robotic or unnatural when spoken - Pronunciation clarity for the detected language - Missing punctuation affecting speech flow - All abbreviations expanded to readable forms **STRICTLY FORBIDDEN:** - Adding meta-commentary about the text or optimization process - Translating to any other language - Adding content not in the original - Including processing notes or explanations **APPROACH:** Apply linguistic expertise creatively to make text sound perfect when spoken in its native language, adapting to that language's specific phonetic and cultural patterns. **FINAL REMINDER:** Return ONLY the optimized text content with NO additional commentary."; } /** * Update prompt settings. * * @param string $custom_prompt Custom prompt to save. * @return bool Success status. */ public function update_prompt( $custom_prompt ) { $this->custom_prompt = $custom_prompt; update_option( 'accessibility_audio_tts_chatgpt_prompt', $custom_prompt ); return true; } /** * Get prompt settings. * * @return array Prompt configuration. */ public function get_prompt_settings() { return array( 'custom_prompt' => $this->custom_prompt, 'default_prompt' => $this->default_prompt, 'has_custom_prompt' => ! empty( $this->custom_prompt ), 'current_version' => $this->current_version, ); } /** * Reset to default prompt. * * @return bool Success status. */ public function reset_to_default() { $this->custom_prompt = ''; update_option( 'accessibility_audio_tts_chatgpt_prompt', '' ); return true; } /** * Ensure prompt is updated to latest version. * * @return void */ private function ensure_prompt_updated() { $saved_version = get_option( 'accessibility_audio_tts_chatgpt_prompt_version', '1.0' ); if ( version_compare( $saved_version, $this->current_version, '<' ) ) { $default_prompt = $this->get_default_prompt(); update_option( 'accessibility_audio_tts_chatgpt_prompt', $default_prompt ); update_option( 'accessibility_audio_tts_chatgpt_prompt_version', $this->current_version ); $this->custom_prompt = $default_prompt; accessibility_audio_tts_debug_log( "ChatGPT_Prompt_Manager: Prompt auto-upgraded from v{$saved_version} to v{$this->current_version}", true ); } else { // Clean up any corrupted backslashes (WordPress magic quotes issue). $saved_prompt = get_option( 'accessibility_audio_tts_chatgpt_prompt', '' ); if ( ! empty( $saved_prompt ) && strpos( $saved_prompt, '\\\\\\\\' ) !== false ) { $cleaned_prompt = stripslashes( stripslashes( $saved_prompt ) ); update_option( 'accessibility_audio_tts_chatgpt_prompt', $cleaned_prompt ); $this->custom_prompt = $cleaned_prompt; accessibility_audio_tts_debug_log( 'ChatGPT_Prompt_Manager: Prompt backslashes cleaned up', true ); } } } /** * Get current prompt version. * * @return string Current version. */ public function get_version() { return $this->current_version; } /** * Check if prompt needs update. * * @return bool True if update needed. */ public function needs_update() { $saved_version = get_option( 'accessibility_audio_tts_chatgpt_prompt_version', '1.0' ); return version_compare( $saved_version, $this->current_version, '<' ); } }