File size: 2,257 Bytes
4300fed
 
e383d75
19dca80
4300fed
 
 
886cf85
 
 
 
 
 
 
19dca80
 
d798cbb
19dca80
e383d75
 
19dca80
 
 
 
406e977
 
 
19dca80
e383d75
 
 
 
 
4300fed
 
 
e383d75
 
 
 
 
b8401e1
4300fed
e383d75
4300fed
 
19dca80
7a62809
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import os, torch, io
import sys
#os.system('python -m unidic download')
from melo.api import TTS
speed = 1.0
import tempfile
if torch.cuda.is_available():
    device = "cuda"
elif torch.backends.mps.is_available():
    device = "mps"
else:
    device = "cpu"
#device = 'cuda' if torch.cuda.is_available() else 'cpu'

languages = ["EN", "ES", "FR", "ZH", "JP", "KR"]
en = ["EN-Default", "EN-US", "EN-BR", "EN_INDIA", "EN-AU"]

LANG = sys.argv[1]

#model = TTS(language='EN', device=device)
def synthesize(language, speaker, text, speed=1.0, progress=gr.Progress()):
    model = TTS(language=language, device=device)
    speaker_ids = model.hps.data.spk2id
    bio = io.BytesIO()
    model.tts_to_file(text, speaker_ids[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
    return bio.getvalue()

#def lang(language):
#    if language == "EN":
#        return gr.update(choices=en, value="EN-Default")
#    else:
#        return gr.update(choices=[language], value=language)
with gr.Blocks() as demo:
    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.')
    with gr.Group():
#        language = gr.Dropdown(languages, interactive=True, value='EN', label='Language')
        if LANG == "EN":
            speaker = gr.Dropdown(en, interactive=True, value='EN-Default', label='Speaker')
        else:
            speaker = gr.Dropdown([LANG], interactive=True, value='EN-Default', label='Speaker')
        speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
        text = gr.Textbox(label="Text to speak", value='The field of text to speech has seen rapid development recently')
#    language.change(fn=lang, inputs=[language], outputs=[speaker])
    btn = gr.Button('Synthesize', variant='primary')
    aud = gr.Audio(interactive=False)
    btn.click(synthesize, inputs=[language, speaker, text, speed], outputs=[aud])
demo.queue(api_open=False, default_concurrency_limit=10).launch(show_api=False)