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)