Archan commited on
Commit
04ea122
1 Parent(s): ee3be41

Create the TTS engine using Fastspeech

Browse files
Files changed (1) hide show
  1. tts.py +17 -0
tts.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
2
+ from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
3
+
4
+ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
5
+ "facebook/fastspeech2-en-ljspeech",
6
+ arg_overrides={"vocoder": "hifigan", "fp16": False}
7
+ )
8
+ model = models[0]
9
+ TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
10
+ generator = task.build_generator(model, cfg)
11
+
12
+ def tts(text):
13
+ text = "Hello, this is a test run."
14
+
15
+ sample = TTSHubInterface.get_model_input(task, text)
16
+ wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
17
+ return wave, rate