Spaces:
Runtime error
Runtime error
File size: 2,053 Bytes
a46600d 1a79c99 1599948 1a79c99 654ba73 9b28923 1a79c99 |
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 50 51 52 |
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 = "<p style='text-align: center'><a href='https://matheo.uliege.be/handle/2268.2/6801' target='_blank'>Real-Time Voice Cloning</a> | <a href='https://github.com/CorentinJ/Real-Time-Voice-Cloning' target='_blank'>Github Repo</a></p>"
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) |