Heaven / app.py
Sebasthene's picture
Create app.py
bb0427c verified
Raw
History Blame Contribute Delete
1.83 kB
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)