File size: 826 Bytes
03a6c5e
e5fa7fa
808b016
 
f8ffeeb
808b016
e5fa7fa
f8ffeeb
808b016
e5fa7fa
f8ffeeb
e5fa7fa
808b016
 
e5fa7fa
808b016
 
 
 
 
 
 
e5fa7fa
808b016
 
 
 
 
 
e5fa7fa
 
 
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
import os
import gradio as gr
from TTS.api import TTS
import torch

# Accept Coqui TTS license automatically
os.environ["COQUI_TOS_AGREED"] = "1"

device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2").to(device)

def clone_voice(sample_audio, text):
    if sample_audio is None or text.strip() == "":
        return None
    output_path = "output.wav"
    tts.tts_to_file(
        text=text,
        file_path=output_path,
        speaker_wav=sample_audio,
        language="en"
    )
    return output_path

demo = gr.Interface(
    fn=clone_voice,
    inputs=[gr.Audio(type="filepath"), gr.Textbox(label="Enter text")],
    outputs=gr.Audio(type="filepath"),
    title="🎤 Voice Cloning App (XTTS-v2)"
)

if __name__ == "__main__":
    demo.launch()