Prgckwb commited on
Commit
54ebdcc
1 Parent(s): 716153a
Files changed (2) hide show
  1. app.py +23 -11
  2. audio.wav +0 -0
app.py CHANGED
@@ -15,17 +15,31 @@ speaker_ids = model.hps.data.spk2id
15
 
16
 
17
  def inference(
18
- text: str, speed: float, speaker: str, progress=gr.Progress(track_tqdm=True)
19
  ):
20
- out_path = "audio.wav"
21
- model.tts_to_file(text, speaker_ids[speaker], out_path, speed=speed, format='wav')
 
 
 
 
 
 
 
 
 
22
  return out_path
23
 
24
 
25
  if __name__ == "__main__":
26
  theme = gr.themes.Soft(
27
- primary_hue=gr.themes.colors.emerald,
28
- secondary_hue=gr.themes.colors.emerald
 
 
 
 
 
29
  )
30
 
31
  demo = gr.Interface(
@@ -33,7 +47,7 @@ if __name__ == "__main__":
33
  description="Convert English text to speech",
34
  fn=inference,
35
  inputs=[
36
- gr.Textbox(label="Text to Synthesize"),
37
  gr.Slider(minimum=0.5, maximum=3.0, value=1.0, label="Speed"),
38
  gr.Dropdown(
39
  label="Speaker",
@@ -41,17 +55,15 @@ if __name__ == "__main__":
41
  value="EN-US",
42
  ),
43
  ],
44
- outputs=[gr.Audio()],
45
  examples=[
46
  [
47
- "Hello, my name is Chi-ku-wa-bu. "
48
- "I am a text-to-speech system designed to assist you. "
49
- "How can I help you today?",
50
  1.0,
51
  "EN-US",
52
  ],
53
  ],
54
  cache_examples=False,
55
- theme=theme
56
  )
57
  demo.queue().launch()
 
15
 
16
 
17
  def inference(
18
+ text: str, speed: float, speaker: str, progress=gr.Progress(track_tqdm=True)
19
  ):
20
+ try:
21
+ out_path = "audio.wav"
22
+ model.tts_to_file(
23
+ text,
24
+ speaker_ids[speaker],
25
+ out_path,
26
+ speed=speed,
27
+ format="wav",
28
+ )
29
+ except Exception as e:
30
+ return gr.Error(str(e))
31
  return out_path
32
 
33
 
34
  if __name__ == "__main__":
35
  theme = gr.themes.Soft(
36
+ primary_hue=gr.themes.colors.emerald, secondary_hue=gr.themes.colors.emerald
37
+ )
38
+
39
+ sample_text = (
40
+ "Hello, my name is Chi-ku-wa-bu. "
41
+ "I am a text-to-speech system designed to assist you. "
42
+ "How can I help you today?"
43
  )
44
 
45
  demo = gr.Interface(
 
47
  description="Convert English text to speech",
48
  fn=inference,
49
  inputs=[
50
+ gr.Textbox(label="Text to Synthesize", value=sample_text),
51
  gr.Slider(minimum=0.5, maximum=3.0, value=1.0, label="Speed"),
52
  gr.Dropdown(
53
  label="Speaker",
 
55
  value="EN-US",
56
  ),
57
  ],
58
+ outputs=[gr.Audio(value="audio.wav")],
59
  examples=[
60
  [
61
+ sample_text,
 
 
62
  1.0,
63
  "EN-US",
64
  ],
65
  ],
66
  cache_examples=False,
67
+ theme=theme,
68
  )
69
  demo.queue().launch()
audio.wav ADDED
Binary file (660 kB). View file