1818
1919import re
2020import requests
21- from utils import get_app_data_dir , find_ffmpeg_path , sanitize_app_settings_for_backend
21+ from utils import get_app_data_dir , find_ffmpeg_path , sanitize_app_settings_for_backend , sanitize_text
2222
2323# Global logger instance - initialized once when module is imported
2424logger = logging .getLogger (__name__ )
@@ -566,6 +566,9 @@ def generate(script_text: str, app_settings: dict, output_filepath: str, status_
566566 logger .info ("Starting generation function." )
567567 status_callback ("Starting podcast generation..." )
568568
569+ # Sanitize the script text at the entry point of the generation logic
570+ sanitized_script_text = sanitize_text (script_text )
571+
569572 ffmpeg_path = find_ffmpeg_path ()
570573 if not ffmpeg_path :
571574 status_callback ("--- CRITICAL ERROR ---" )
@@ -592,12 +595,12 @@ def generate(script_text: str, app_settings: dict, output_filepath: str, status_
592595 if provider_name == "gemini" :
593596 speaker_mapping = (app_settings or {}).get ("speaker_voices" , {})
594597 provider = GeminiTTS (api_key = api_key )
595- return provider .synthesize (script_text = script_text , speaker_mapping = speaker_mapping ,
598+ return provider .synthesize (script_text = sanitized_script_text , speaker_mapping = speaker_mapping ,
596599 output_filepath = output_filepath , status_callback = status_callback )
597600 else :
598601 speaker_mapping = (app_settings or {}).get ("speaker_voices_elevenlabs" , {})
599602 provider = ElevenLabsTTS (api_key = api_key )
600- return provider .synthesize (script_text = script_text , speaker_mapping = speaker_mapping ,
603+ return provider .synthesize (script_text = sanitized_script_text , speaker_mapping = speaker_mapping ,
601604 output_filepath = output_filepath , status_callback = status_callback )
602605
603606
@@ -735,7 +738,7 @@ def sanitize_app_settings_for_backend(app_settings: Dict[str, Any]) -> Dict[str,
735738
736739 temp_script_file_path = None
737740 if args .script_text :
738- script_text = args .script_text
741+ script_text = sanitize_text ( args .script_text )
739742 script_source_description = "the provided text"
740743 if not args .output_filepath :
741744 parser .error ("argument --output is required when using --script-text." )
@@ -751,7 +754,7 @@ def sanitize_app_settings_for_backend(app_settings: Dict[str, Any]) -> Dict[str,
751754 else : # script_filepath is guaranteed to be not None here
752755 try :
753756 with open (args .script_filepath , 'r' , encoding = 'utf-8' ) as f :
754- script_text = f .read ()
757+ script_text = sanitize_text ( f .read () )
755758 script_filepath_for_demo = args .script_filepath
756759 script_source_description = f"'{ os .path .basename (args .script_filepath )} '"
757760 except FileNotFoundError :
0 commit comments