chilge commited on
Commit
80be904
1 Parent(s): d8efc4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -43,7 +43,7 @@ _ = utils.load_checkpoint("logs/leo/G_4000.pth", net_g, None)
43
  random_emotion_root = "wavs"
44
  emotion_dict = json.load(open("configs/leo.json", "r"))
45
 
46
- def tts(txt, emotion, roma=False, length_scale=1):
47
  """emotion为参考情感音频路径或random_sample(随机抽取)"""
48
  if roma:
49
  stn_tst = get_text_byroma(txt, hps)
@@ -68,27 +68,17 @@ def tts(txt, emotion, roma=False, length_scale=1):
68
  else:
69
  print("emotion参数不正确")
70
 
 
 
71
  # Save the numpy array as a temporary file
72
- temp_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
73
- temp_file_path = temp_file.name
74
  write(temp_file_path, hps.data.sampling_rate, audio)
75
 
76
- # Display the audio
77
- ipd.display(ipd.Audio(temp_file_path, rate=hps.data.sampling_rate, normalize=False))
78
-
79
- # Delete the temporary file
80
- os.remove(temp_file_path)
81
 
82
- audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=0.667, noise_scale_w=0.8, length_scale=1.2, emo=emo)[0][0,0].data.float().numpy()
83
- return audio
84
 
85
- def generate_audio(txt, emotion):
86
- audio = tts(txt, emotion)
87
  return audio
88
 
89
- input_text = gr.inputs.Textbox(label="输入文本")
90
- input_emotion = gr.inputs.Dropdown(choices=["random_sample"] + os.listdir(random_emotion_root), label="参考情感音频")
91
- output_audio = gr.outputs.Audio(type="numpy", label="合成音频")
92
-
93
- iface = gr.Interface(fn=generate_audio, inputs=[input_text, input_emotion], outputs=output_audio)
94
- iface.launch()
 
43
  random_emotion_root = "wavs"
44
  emotion_dict = json.load(open("configs/leo.json", "r"))
45
 
46
+ def tts(txt, emotion, temp_file_path):
47
  """emotion为参考情感音频路径或random_sample(随机抽取)"""
48
  if roma:
49
  stn_tst = get_text_byroma(txt, hps)
 
68
  else:
69
  print("emotion参数不正确")
70
 
71
+ audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=0.667, noise_scale_w=0.8, length_scale=1.2, emo=emo)[0][0,0].data.float().numpy()
72
+
73
  # Save the numpy array as a temporary file
 
 
74
  write(temp_file_path, hps.data.sampling_rate, audio)
75
 
76
+ # Display the audio
77
+ ipd.display(ipd.Audio(temp_file_path, rate=hps.data.sampling_rate, normalize=False))
 
 
 
78
 
79
+ # Delete the temporary file
80
+ os.remove(temp_file_path)
81
 
 
 
82
  return audio
83
 
84
+ def generate