File size: 1,116 Bytes
168a18b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# !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")