File size: 1,486 Bytes
068b7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from TTS.api import TTS
import os

# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"

# Initialize TTS model
tts = TTS(model_name="voice_conversion_models/multilingual/vctk/freevc24", progress_bar=False).to(device)

def voice_conversion(input_audio, target_voice):
    output_path = "output.wav"
    # Perform voice conversion
    tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice, file_path=output_path)
    return output_path

# Get examples from Examples folder
examples_folder = "Examples/"
example_files = [f for f in os.listdir(examples_folder) if f.endswith(".wav")]

# Define Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("## Voice Conversion using Coqui TTS")
    
    with gr.Row():
        input_audio = gr.Audio(source="microphone", label="Record or Upload Your Voice", type="filepath")
        target_voice = gr.Dropdown(choices=example_files, label="Select Target Voice from Examples", 
                                   value=example_files[0], info="Located in Examples/ folder")

    convert_button = gr.Button("Convert Voice")
    output_audio = gr.Audio(label="Converted Voice", type="filepath")

    with gr.Progress() as progress:
        convert_button.click(voice_conversion, inputs=[input_audio, target_voice], outputs=output_audio, 
                             progress=progress)

# Launch with public=True for public URL access and share link
demo.launch(share=True)