File size: 866 Bytes
8e63b0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import gradio as gr
from TTS.api import TTS

# Load XTTS model (voice cloning capable)
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=True, gpu=False)

# Voice cloning function
def clone_and_speak(text, ref_audio):
    output_path = "output.wav"
    tts.tts_to_file(text=text, speaker_wav=ref_audio, language="en", file_path=output_path)
    return output_path

# Gradio Interface
interface = gr.Interface(
    fn=clone_and_speak,
    inputs=[
        gr.Textbox(label="Enter text to synthesize", lines=5),
        gr.Audio(source="upload", type="filepath", label="Reference Voice (wav/mp3)")
    ],
    outputs=gr.Audio(type="filepath", label="Generated Speech"),
    title="Free Voice Cloning with XTTS v2",
    description="Upload reference voice and generate cloned speech for free (up to 3000 words)."
)

interface.launch()