-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTTS.py
More file actions
26 lines (21 loc) · 696 Bytes
/
TTS.py
File metadata and controls
26 lines (21 loc) · 696 Bytes
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
# Converts the text present in label file to speech
# Check label file before running this code
from gtts import gTTS
LABEL_PATH = "Model/labels.txt"
# insert label path here
folder = open(LABEL_PATH, 'r')
label = folder.read().splitlines()
print(label)
FOLDER = "Speech"
# audio samples stored here
for i in range(len(label)):
text = label[i]
print(f"\n Converting {label[i]}...")
tts = gTTS(text, slow=False, lang='en')
# converts the given text to speech
if not tts.save(f'{FOLDER}/{text}.mp3'):
print(f"\nSaving {text} to {FOLDER}/{text}.mp3")
print("\n Success!")
else:
# if fails to convert
print(f"!!{text} ERROR!!")