File size: 1,830 Bytes
bb0427c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import gradio as gr
import torch
import numpy as np
import os

print("πŸš€ Loading XTTS model...")

from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts

# Load model
config = XttsConfig()
config.load_json("https://coqui.gateway.scarf.sh/tts/xtts/v1.1/config.json")
model = Xtts.init_from_config(config)
model.load_checkpoint(config, checkpoint_dir="https://coqui.gateway.scarf.sh/tts/xtts/v1.1/", eval=True)

if torch.cuda.is_available():
    model.cuda()
    print("βœ… Model on GPU")
else:
    model.cpu()
    print("βœ… Model on CPU")

def generate_speech(text):
    """Generate speech using your cloned voice"""
    output = model.synthesize(
        text,
        config,
        speaker_audio_path="reference.wav",
        language="en",
        temperature=0.7,
    )
    return (24000, np.array(output["wav"]))

# Create the web interface
with gr.Blocks(title="My Voice Clone", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # 🎀 My Voice Clone
    
    Type any English text below and hear it in my voice!
    
    *Powered by Coqui XTTS*
    """)
    
    with gr.Row():
        with gr.Column():
            text_input = gr.Textbox(
                label="Text to speak",
                placeholder="Type anything you want me to say...",
                lines=4,
                value="Hello! This is my cloned voice. I can now speak any text you write here."
            )
            generate_btn = gr.Button("πŸ”Š Generate Speech", variant="primary")
        
        with gr.Column():
            audio_output = gr.Audio(label="Generated Speech", type="numpy")
    
    generate_btn.click(
        fn=generate_speech,
        inputs=[text_input],
        outputs=audio_output
    )

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)