-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_interactive_demo.py
33 lines (28 loc) · 1.21 KB
/
run_interactive_demo.py
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
import datetime
import os
import sys
import warnings
import torch
from InferenceInterfaces.InferenceFastSpeech2 import InferenceFastSpeech2
if __name__ == '__main__':
warnings.filterwarnings("ignore", category=UserWarning)
available_models = os.listdir("Models")
available_fastspeech_models = list()
for model in available_models:
if model.startswith("FastSpeech2_"):
available_fastspeech_models.append(model.lstrip("FastSpeech_2"))
model_id = input("Which model do you want? \nCurrently supported are: {}\n".format("".join("\n\t- {}".format(key) for key in available_fastspeech_models)))
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = InferenceFastSpeech2(device=device, model_name=model_id, alpha=1.3)
tts.set_language(lang_id=input("Which Language?\n"))
while True:
try:
text = input("\nWhat should I say? (or 'exit')\n")
except EOFError as e:
sys.exit()
if text == "exit":
sys.exit()
if text:
tts.read_aloud(text, view=True, blocking=True)
file_location = f"{int(datetime.datetime.today().timestamp() * 1000)}.wav"
tts.read_to_file([text], file_location)