mrfakename commited on
Commit
532dc11
1 Parent(s): 23840ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -9
app.py CHANGED
@@ -1,10 +1,14 @@
 
 
1
  import gradio as gr
2
  import os, torch, io
3
- os.system('python -m unidic download')
 
4
  from melo.api import TTS
5
  speed = 1.0
6
  import tempfile
7
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
 
8
  models = {
9
  'EN': TTS(language='EN', device=device),
10
  'ES': TTS(language='ES', device=device),
@@ -14,22 +18,44 @@ models = {
14
  'KR': TTS(language='KR', device=device),
15
  }
16
  speaker_ids = models['EN'].hps.data.spk2id
 
 
 
 
 
 
 
 
 
 
17
  def synthesize(speaker, text, speed, language, progress=gr.Progress()):
18
  bio = io.BytesIO()
19
  models[language].tts_to_file(text, models[language].hps.data.spk2id[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
20
  return bio.getvalue()
21
- def load_speakers(language):
22
- return gr.update(value=list(models[language].hps.data.spk2id.keys())[0], choices=list(models[language].hps.data.spk2id.keys()))
 
 
 
 
23
  with gr.Blocks() as demo:
24
- gr.Markdown('# MeloTTS\n\nAn unofficial demo of [MeloTTS](https://github.com/myshell-ai/MeloTTS) from MyShell AI. MeloTTS is a permissively licensed (MIT) SOTA multi-speaker TTS model.\n\nI am not affiliated with MyShell AI in any way.')
25
  with gr.Group():
26
  speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-Default', label='Speaker')
27
  language = gr.Radio(['EN', 'ES', 'FR', 'ZH', 'JP', 'KR'], label='Language', value='EN')
28
- language.input(load_speakers, inputs=language, outputs=speaker)
29
  speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
30
- text = gr.Textbox(label="Text to speak", value='The field of text to speech has seen rapid development recently')
 
31
  btn = gr.Button('Synthesize', variant='primary')
32
  aud = gr.Audio(interactive=False)
33
  btn.click(synthesize, inputs=[speaker, text, speed, language], outputs=[aud])
34
- gr.Markdown('Demo by [mrfakename](https://twitter.com/realmrfakename).')
35
- demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)
 
 
 
 
 
 
 
 
 
1
+ # WebUI by mrfakename <X @realmrfakename / HF @mrfakename>
2
+ # Demo also available on HF Spaces: https://huggingface.co/spaces/mrfakename/MeloTTS
3
  import gradio as gr
4
  import os, torch, io
5
+ # os.system('python -m unidic download')
6
+ print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
7
  from melo.api import TTS
8
  speed = 1.0
9
  import tempfile
10
+ import click
11
+ device = 'auto'
12
  models = {
13
  'EN': TTS(language='EN', device=device),
14
  'ES': TTS(language='ES', device=device),
 
18
  'KR': TTS(language='KR', device=device),
19
  }
20
  speaker_ids = models['EN'].hps.data.spk2id
21
+
22
+ default_text_dict = {
23
+ 'EN': 'The field of text-to-speech has seen rapid development recently.',
24
+ 'ES': 'El campo de la conversión de texto a voz ha experimentado un rápido desarrollo recientemente.',
25
+ 'FR': 'Le domaine de la synthèse vocale a connu un développement rapide récemment',
26
+ 'ZH': 'text-to-speech 领域近年来发展迅速',
27
+ 'JP': 'テキスト読み上げの分野は最近急速な発展を遂げています',
28
+ 'KR': '최근 텍스트 음성 변환 분야가 급속도로 발전하고 있습니다.',
29
+ }
30
+
31
  def synthesize(speaker, text, speed, language, progress=gr.Progress()):
32
  bio = io.BytesIO()
33
  models[language].tts_to_file(text, models[language].hps.data.spk2id[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
34
  return bio.getvalue()
35
+ def load_speakers(language, text):
36
+ if text in list(default_text_dict.values()):
37
+ newtext = default_text_dict[language]
38
+ else:
39
+ newtext = text
40
+ return gr.update(value=list(models[language].hps.data.spk2id.keys())[0], choices=list(models[language].hps.data.spk2id.keys())), newtext
41
  with gr.Blocks() as demo:
42
+ gr.Markdown('# MeloTTS WebUI\n\nA WebUI for MeloTTS.')
43
  with gr.Group():
44
  speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-Default', label='Speaker')
45
  language = gr.Radio(['EN', 'ES', 'FR', 'ZH', 'JP', 'KR'], label='Language', value='EN')
 
46
  speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
47
+ text = gr.Textbox(label="Text to speak", value=default_text_dict['EN'])
48
+ language.input(load_speakers, inputs=[language, text], outputs=[speaker, text])
49
  btn = gr.Button('Synthesize', variant='primary')
50
  aud = gr.Audio(interactive=False)
51
  btn.click(synthesize, inputs=[speaker, text, speed, language], outputs=[aud])
52
+ gr.Markdown('WebUI by [mrfakename](https://twitter.com/realmrfakename).')
53
+ @click.command()
54
+ @click.option('--share', '-s', is_flag=True, show_default=True, default=False, help="Expose a publicly-accessible shared Gradio link usable by anyone with the link. Only share the link with people you trust.")
55
+ @click.option('--host', '-h', default=None)
56
+ @click.option('--port', '-p', default=None)
57
+ def main(share, host, port):
58
+ demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False, share=share, server_name=host, server_port=port)
59
+
60
+ if __name__ == "__main__":
61
+ main()