cocktailpeanut commited on
Commit
19dca80
1 Parent(s): 5983359
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -1,6 +1,6 @@
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
@@ -11,19 +11,31 @@ elif torch.backends.mps.is_available():
11
  else:
12
  device = "cpu"
13
  #device = 'cuda' if torch.cuda.is_available() else 'cpu'
14
- model = TTS(language='EN', device=device)
15
- speaker_ids = model.hps.data.spk2id
16
- def synthesize(speaker, text, speed=1.0, progress=gr.Progress()):
 
 
 
 
17
  bio = io.BytesIO()
18
  model.tts_to_file(text, speaker_ids[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
19
  return bio.getvalue()
 
 
 
 
 
 
20
  with gr.Blocks() as demo:
21
  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.\n\nThis demo currently only supports English, but the model itself supports other languages.')
22
  with gr.Group():
 
23
  speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-Default', label='Speaker')
24
  speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
25
  text = gr.Textbox(label="Text to speak", value='The field of text to speech has seen rapid development recently')
 
26
  btn = gr.Button('Synthesize', variant='primary')
27
  aud = gr.Audio(interactive=False)
28
- btn.click(synthesize, inputs=[speaker, text, speed], outputs=[aud])
29
  demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)
 
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
 
11
  else:
12
  device = "cpu"
13
  #device = 'cuda' if torch.cuda.is_available() else 'cpu'
14
+
15
+ languages = ["EN", "ES", "FR", "ZH", "JP", "KR"]
16
+
17
+ #model = TTS(language='EN', device=device)
18
+ def synthesize(language, speaker, text, speed=1.0, progress=gr.Progress()):
19
+ model = TTS(language=language, device=device)
20
+ speaker_ids = model.hps.data.spk2id
21
  bio = io.BytesIO()
22
  model.tts_to_file(text, speaker_ids[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
23
  return bio.getvalue()
24
+
25
+ def lang(language):
26
+ if language == "EN":
27
+ return gr.update(choices=["EN-Default", "EN-US", "EN-BR", "EN_INDIA", "EN-AU"]
28
+ else:
29
+ return gr.update(choices=[language])
30
  with gr.Blocks() as demo:
31
  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.\n\nThis demo currently only supports English, but the model itself supports other languages.')
32
  with gr.Group():
33
+ language = gr.Dropdown(languages, interactive=True, value='EN', label='Language')
34
  speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-Default', label='Speaker')
35
  speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
36
  text = gr.Textbox(label="Text to speak", value='The field of text to speech has seen rapid development recently')
37
+ language.change(fn=lang, inputs=[language], outputs=[speaker])
38
  btn = gr.Button('Synthesize', variant='primary')
39
  aud = gr.Audio(interactive=False)
40
+ btn.click(synthesize, inputs=[language, speaker, text, speed], outputs=[aud])
41
  demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)