import json import gradio as gr import uuid from TTS.api import TTS f = open('speakers.json') data = json.load(f) tts_mod=data['tts_models']['en'] print (tts_mod.keys()) def next_line(inp): out=data['tts_models']['en'][inp] print (out) return gr.Dropdown(choices=out.keys(),interactive=True) def run_tts(text, s_g, s_s): #print (TTS.list_models()) #tts = TTS(TTS.list_models()[0]) #wav = tts.tts("This is a test! This is also a test!!", speaker=tts.speakers[0], language=tts.languages[0]) tts = TTS(model_name=f"tts_models/en/{s_g}/{s_s}", progress_bar=False).to("cpu") print (tts.config) #print (dir(tts)) uid=uuid.uuid4() tts.tts_to_file(text, file_path=f"{uid}-output.wav") return (f'{uid}-output.wav') with gr.Blocks() as app: with gr.Group(): with gr.Row(): in_t=gr.Textbox(lines=6) with gr.Column(): drop=gr.Dropdown(label="Speaker Group", choices=tts_mod.keys(), interactive=True) drop2=gr.Dropdown(label="Speaker") go_btn=gr.Button() with gr.Row(): out_aud=gr.Audio() drop.change(next_line,drop,drop2) go_btn.click(run_tts,[in_t,drop,drop2],out_aud) app.launch()