import gradio as gr import os import shlex import uuid import torch cpu_param = "--cpu" if not torch.cuda.is_available() else "" def inference(audio_path, text, mic_path=None): if mic_path: audio_path = mic_path output_path = f"/tmp/output_{uuid.uuid4()}.wav" os.system( f"python demo_cli.py --no_sound {cpu_param} --audio_path {audio_path} --text {shlex.quote(text.strip())} --output_path {output_path}") return output_path title = "Real-Time-Voice-Cloning" description = "Gradio demo for Real-Time-Voice-Cloning: Clone a voice in 600 seconds to generate arbitrary speech in real-time. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below." article = "
" def toggle(choice): if choice == "mic": return gr.update(visible=True, value=None), gr.update(visible=False, value=None) else: return gr.update(visible=False, value=None), gr.update(visible=True, value=None) with gr.Blocks() as demo: with gr.Row(): with gr.Column(): radio = gr.Radio(["mic", "file"], value="mic", label="How would you like to upload your audio?") mic_input = gr.Mic(label="Input", type="filepath", visible=False) audio_file = gr.Audio( type="filepath", label="Input", visible=True) text_input = gr.Textbox(label="Text") with gr.Column(): audio_output = gr.Audio(label="Output") inputs=[audio_file, text_input](expected 200, got 100) , outputs=[audio_output](expected 200, got 100) btn = gr.Button(Generate) btn.click(inference, inputs=[audio_file, text_input, mic_input], outputs=audio_output) radio.change(toggle, radio, [mic_input, audio_file]) demo.launch(enable_queue=True)