Spaces:
Running
on
T4
Running
on
T4
mrfakename
commited on
Commit
•
1241f18
1
Parent(s):
f961a56
Multilingual Support
Browse files
app.py
CHANGED
@@ -5,19 +5,30 @@ from melo.api import TTS
|
|
5 |
speed = 1.0
|
6 |
import tempfile
|
7 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
bio = io.BytesIO()
|
12 |
-
|
13 |
return bio.getvalue()
|
|
|
|
|
14 |
with gr.Blocks() as demo:
|
15 |
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.')
|
16 |
with gr.Group():
|
17 |
speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-Default', label='Speaker')
|
|
|
|
|
18 |
speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
|
19 |
text = gr.Textbox(label="Text to speak", value='The field of text to speech has seen rapid development recently')
|
20 |
btn = gr.Button('Synthesize', variant='primary')
|
21 |
aud = gr.Audio(interactive=False)
|
22 |
-
btn.click(synthesize, inputs=[speaker, text, speed], outputs=[aud])
|
23 |
demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)
|
|
|
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),
|
11 |
+
'FR': TTS(language='FR', device=device),
|
12 |
+
'ZH': TTS(language='ZH', device=device),
|
13 |
+
'JP': TTS(language='JP', device=device),
|
14 |
+
'KR': TTS(language='KR', device=device),
|
15 |
+
}
|
16 |
+
speaker_ids = models['EN'].hps.data.spk2id
|
17 |
+
def synthesize(speaker, text, speed=1.0, language, progress=gr.Progress()):
|
18 |
bio = io.BytesIO()
|
19 |
+
models[language].tts_to_file(text, speaker_ids[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
|
20 |
return bio.getvalue()
|
21 |
+
def load_language(language):
|
22 |
+
return models[language].hps.data.spk2id
|
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.\n\nThis demo currently only supports English, but the model itself supports other languages.')
|
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 |
demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)
|