# !pip install tts # !pip install python-espeak-ng from TTS.api import TTS import os # Init TTS with the target model name tts = TTS(model_name="tts_models/de/thorsten/tacotron2-DDC", progress_bar=False) def ttsForAllFiles(): # source text directory directory = os.fsencode("translatedTranscripts") # go through source text files for file in os.listdir(directory): filename = os.fsdecode(file) print(f'reading {filename}') if (filename.endswith(".txt")): file_path = f"translatedTranscripts/{filename}" with open(file_path, 'r', encoding='utf8') as f: sourceText = f.read() # read source text fname = filename.replace(".txt", "") # Run TTS tts.tts_to_file(text=sourceText, file_path=f"tts/{fname}.wav") def ttsSingleFile(videoId): file_path = f"translatedTranscripts/{videoId}.txt" with open(file_path, 'r', encoding='utf8') as f: sourceText = f.read() # read source text # Run TTS tts.tts_to_file(text=sourceText, file_path=f"tts/{videoId}.wav")