AlexK-PL commited on
Commit
848f2f7
·
1 Parent(s): cb82d78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -9,26 +9,26 @@ from melgan.model.generator import Generator
9
  from melgan.utils.hparams import load_hparam
10
 
11
  torch.manual_seed(1234)
12
- MAX_WAV_VALUE = 32768.0
13
-
14
- # load trained tacotron2 + GST model:
15
- model = load_model(hparams)
16
- checkpoint_path = "trained_models/checkpoint_78000.model"
17
- model.load_state_dict(torch.load(checkpoint_path)['state_dict'])
18
- model.to('cuda')
19
- _ = model.eval()
20
-
21
- # load pre trained MelGAN model for mel2audio:
22
- vocoder_checkpoint_path = "trained_models/nvidia_tacotron2_LJ11_epoch6400.pt"
23
- checkpoint = torch.load(vocoder_checkpoint_path)
24
- hp_melgan = load_hparam("melgan/config/default.yaml")
25
- vocoder_model = Generator(80)
26
- vocoder_model.load_state_dict(checkpoint['model_g'])
27
- vocoder_model = vocoder_model.to('cuda')
28
- vocoder_model.eval(inference=False)
29
-
30
- gst_head_scores = np.array([0.5, 0.15, 0.35]) # originally ([0.5, 0.15, 0.35])
31
- gst_scores = torch.from_numpy(gst_head_scores).cuda().float()
32
 
33
  def synthesize(text):
34
  sequence = np.array(text_to_sequence(text, ['english_cleaners']))[None, :]
@@ -40,8 +40,13 @@ def synthesize(text):
40
  with torch.no_grad():
41
  audio = vocoder_model.inference(mel_outputs_postnet)
42
 
43
- audio_numpy = audio.data.cpu().detach().numpy()
44
- write(save_path, 22050, audio_numpy)
45
 
46
- iface = gr.Interface(fn=synthesize, inputs="text", outputs="audio")
47
- iface.launch()
 
 
 
 
 
 
 
9
  from melgan.utils.hparams import load_hparam
10
 
11
  torch.manual_seed(1234)
12
+
13
+ def init_models(hparams):
14
+ # load trained tacotron2 + GST model:
15
+ model = load_model(hparams)
16
+ checkpoint_path = "trained_models/checkpoint_78000.model"
17
+ model.load_state_dict(torch.load(checkpoint_path)['state_dict'])
18
+ model.to('cuda')
19
+ _ = model.eval()
20
+
21
+ # load pre trained MelGAN model for mel2audio:
22
+ vocoder_checkpoint_path = "trained_models/nvidia_tacotron2_LJ11_epoch6400.pt"
23
+ checkpoint = torch.load(vocoder_checkpoint_path)
24
+ hp_melgan = load_hparam("melgan/config/default.yaml")
25
+ vocoder_model = Generator(80)
26
+ vocoder_model.load_state_dict(checkpoint['model_g'])
27
+ vocoder_model = vocoder_model.to('cuda')
28
+ vocoder_model.eval(inference=False)
29
+
30
+ gst_head_scores = np.array([0.5, 0.15, 0.35]) # originally ([0.5, 0.15, 0.35])
31
+ gst_scores = torch.from_numpy(gst_head_scores).cuda().float()
32
 
33
  def synthesize(text):
34
  sequence = np.array(text_to_sequence(text, ['english_cleaners']))[None, :]
 
40
  with torch.no_grad():
41
  audio = vocoder_model.inference(mel_outputs_postnet)
42
 
43
+ audio_numpy = audio.data.cpu().detach().numpy()
 
44
 
45
+ return [22050, audio_numpy]
46
+
47
+ if __name__ == "__main__":
48
+
49
+ init_models(hparams)
50
+ iface = gr.Interface(fn=synthesize, inputs="text", outputs="audio")
51
+ iface.launch()
52
+