File size: 1,122 Bytes
c636952
a416ccf
 
4a20039
 
 
a416ccf
 
 
 
 
 
 
 
 
 
 
c636952
 
 
a416ccf
c636952
 
a416ccf
 
 
 
 
 
 
 
 
 
 
 
c636952
a416ccf
c636952
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
import gradio as gr
from TTS.api import TTS

# Load the XTTS-v2 model and set it to use CPU
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
tts.to("cpu")  # Set the model to run on CPU

# Define the function for voice cloning
def generate_voice(text, speaker_audio):
    output_path = "output.wav"
    tts.tts_to_file(
        text=text,
        speaker_wav=speaker_audio.name,
        file_path=output_path,
        language="en"
    )
    return output_path

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# 🗣️ Voice Cloning with Coqui XTTS-v2")
    
    with gr.Row():
        text_input = gr.Textbox(label="Enter Text", placeholder="Type the text you want to synthesize...")
        speaker_audio_input = gr.Audio(label="Upload Speaker Audio (WAV)", type="file")
    
    output_audio = gr.Audio(label="Generated Voice", type="filepath")
    
    generate_button = gr.Button("Generate Voice")
    
    generate_button.click(
        fn=generate_voice,
        inputs=[text_input, speaker_audio_input],
        outputs=output_audio
    )

# Launch the Gradio app
demo.launch()