Prgckwb commited on
Commit
629e135
1 Parent(s): ed071fe
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -1,39 +1,48 @@
 
 
1
  import gradio as gr
2
  import nltk
3
- import os
4
- os.system('python -m unidic download')
5
- from melo.api import TTS
6
 
7
- nltk.download('averaged_perceptron_tagger_eng')
 
 
 
8
 
9
  # Get device
10
- device = 'auto'
11
- model = TTS(language='EN', device=device)
12
  speaker_ids = model.hps.data.spk2id
13
 
14
 
15
- def inference(text: str, speed: float, speaker: str):
16
- output_path = 'audio.wav'
 
 
17
  model.tts_to_file(text, speaker_ids[speaker], output_path, speed=speed)
18
  return output_path
19
 
20
 
21
  if __name__ == "__main__":
22
  demo = gr.Interface(
23
- title='Text-to-Speech',
24
- description='Convert English text to speech',
25
  fn=inference,
26
  inputs=[
27
- gr.Textbox(label='Text to Synthesize'),
28
- gr.Slider(minimum=0.5, maximum=3.0, value=1.0, label='Speed'),
29
  gr.Dropdown(
30
- label='Speaker',
31
- choices=['EN', 'EN-US', 'EN-BR', 'EN_INDIA', 'EN-AU', 'EN-Default'],
32
- value='EN-US'
33
- )
34
  ],
35
- outputs=[
36
- gr.Audio()
 
 
 
 
 
37
  ],
38
  )
39
  demo.queue().launch()
 
1
+ import os
2
+
3
  import gradio as gr
4
  import nltk
 
 
 
5
 
6
+ os.system("python -m unidic download")
7
+ from melo.api import TTS # noqa: E402
8
+
9
+ nltk.download("averaged_perceptron_tagger_eng")
10
 
11
  # Get device
12
+ device = "auto"
13
+ model = TTS(language="EN", device=device)
14
  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
+ output_path = "audio.wav"
21
  model.tts_to_file(text, speaker_ids[speaker], output_path, speed=speed)
22
  return output_path
23
 
24
 
25
  if __name__ == "__main__":
26
  demo = gr.Interface(
27
+ title="Text-to-Speech",
28
+ description="Convert English text to speech",
29
  fn=inference,
30
  inputs=[
31
+ gr.Textbox(label="Text to Synthesize"),
32
+ gr.Slider(minimum=0.5, maximum=3.0, value=1.0, label="Speed"),
33
  gr.Dropdown(
34
+ label="Speaker",
35
+ choices=["EN", "EN-US", "EN-BR", "EN_INDIA", "EN-AU", "EN-Default"],
36
+ value="EN-US",
37
+ ),
38
  ],
39
+ outputs=[gr.Audio()],
40
+ examples=[
41
+ [
42
+ "Hello, my name is Chi-ku-wa-bu. I am a text-to-speech system designed to assist you. How can I help you today?",
43
+ 1.0,
44
+ "EN-US",
45
+ ],
46
  ],
47
  )
48
  demo.queue().launch()