import copy from .TTS import synthesize_dictionary_batch, synthesize_dictionary from .translate import translate_dictionary from .audio_builder import build_audio original_language = "en" batch_tts_synthesize = False skip_translation = False stop_after_translation = False skip_translation = False skip_synthesize = False two_pass_voice_synth = False # Azure doesn't need two pass voice synth, so disable it def manually_prepare_dictionary(dictionaryToPrep): ### Do additional Processing to match the format produced by translation function # Create new key 'translated_text' and set it to the value of 'text' for key, value in dictionaryToPrep.items(): dictionaryToPrep[key]['translated_text'] = value['text'] # Convert the keys to integers and return the dictionary return {int(k): v for k, v in dictionaryToPrep.items()} # Process a language: Translate, Synthesize, and Build Audio def process_language(langData, originalLanguageSubsDict, totalAudioLength, translatedSrtFileName, outputFileName, outputFolder): langDict = { 'targetLanguage': langData['translation_target_language'], 'sourceLanguage': langData['translation_source_language'], 'voiceName': langData['synth_voice_name'], 'languageCode': langData['synth_language_code'], 'voiceGender': langData['synth_voice_gender'], 'translateService': langData['translate_service'], 'formality': langData['formality'] } individualLanguageSubsDict = copy.deepcopy(originalLanguageSubsDict) # Check for special case where original language is the same as the target language if langDict['languageCode'].lower() == original_language.lower(): print("Original language is the same as the target language. Skipping translation.") individualLanguageSubsDict = manually_prepare_dictionary(individualLanguageSubsDict) elif skip_translation == False: # Translate individualLanguageSubsDict = translate_dictionary(individualLanguageSubsDict, langDict, translatedSrtFileName, skipTranslation=skip_translation) if stop_after_translation: print("Stopping at translation is enabled. Skipping TTS and building audio.") return # Synthesize if batch_tts_synthesize == True: individualLanguageSubsDict = synthesize_dictionary_batch(individualLanguageSubsDict, langDict, skipSynthesize=skip_synthesize) else: individualLanguageSubsDict = synthesize_dictionary(individualLanguageSubsDict, langDict, outputFolder, skipSynthesize=skip_synthesize) print(individualLanguageSubsDict) # Build audio individualLanguageSubsDict = build_audio(individualLanguageSubsDict, langDict, totalAudioLength, outputFileName, two_pass_voice_synth)