|
import gradio as gr |
|
import os |
|
from coqui_tts import run_audio_generation_v1 |
|
from metaVoice import run_audio_generation_v2 |
|
import shutil |
|
|
|
|
|
os.environ["COQUI_TOS_AGREED"] = "1" |
|
|
|
def process_audio(input_text, speaker_audio, speaker_name, option_selected): |
|
try: |
|
|
|
os.makedirs("./tmp/audio/input_src/", exist_ok=True) |
|
os.makedirs("audio", exist_ok=True) |
|
print(f"Received audio file: {speaker_audio}") |
|
|
|
if not speaker_audio or not os.path.exists(speaker_audio): |
|
return "Error: The uploaded audio file is missing or invalid. Please upload again." |
|
|
|
|
|
speaker_audio_path = "./tmp/audio/input_src/0.wav" |
|
if os.path.exists(speaker_audio): |
|
shutil.copy(speaker_audio, speaker_audio_path) |
|
else: |
|
raise FileNotFoundError(f"Speaker audio file not found: {speaker_audio}") |
|
|
|
|
|
if option_selected == "Xtts_v2": |
|
|
|
run_audio_generation_v1(input_text) |
|
|
|
elif option_selected =="metaVoice": |
|
|
|
run_audio_generation_v2(input_text) |
|
print(os.listdir('./tmp/audio/')) |
|
else: |
|
return f"The option is not implemented yet." |
|
|
|
|
|
|
|
|
|
|
|
return "./tmp/audio/generated-custom.wav" |
|
|
|
except Exception as e: |
|
return str(e) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Audio Cloning and Text-to-Speech") |
|
|
|
with gr.Row(): |
|
text_input = gr.Textbox(label="Input Text", placeholder="Enter your text here.") |
|
|
|
with gr.Row(): |
|
speaker_audio = gr.Audio(label="Speaker Audio (to be cloned)", type='filepath', format='wav') |
|
speaker_name = gr.Textbox(label="Speaker Name", placeholder="Enter the speaker's name.") |
|
|
|
option_selected = gr.Dropdown(choices=["Xtts_v2", "metaVoice", "more"], label="Select an Option") |
|
|
|
submit_btn = gr.Button("Submit") |
|
|
|
output_audio = gr.Audio(label="Generated Audio Output", type='filepath') |
|
|
|
submit_btn.click( |
|
fn=process_audio, |
|
inputs=[text_input, speaker_audio, speaker_name, option_selected], |
|
outputs=output_audio, |
|
) |
|
|
|
|
|
demo.launch() |
|
|