cn-speech-esss / app.py
gitgato's picture
Update app.py
a983024 verified
raw
history blame
2 kB
import gradio as gr
import torch
from TTS.api import TTS
import os
# Aceptar términos de uso de Coqui TTS
os.environ["COQUI_TOS_AGREED"] = "1"
# Configurar para usar CPU si no hay GPU disponible
device = "cuda" if torch.cuda.is_available() else "cpu"
# Inicializar el modelo de TTS con manejo seguro de carga
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=torch.cuda.is_available()).to(device)
# Función para clonar la voz y generar el archivo de audio
def clone(text, audio):
output_path = "./output.wav"
tts.tts_to_file(text=text, speaker_wav=audio, language="es", file_path=output_path)
return output_path
# Interfaz de Gradio
iface = gr.Interface(
fn=clone,
inputs=[
gr.Textbox(label='Text'),
gr.Audio(type='filepath', label='Voice reference audio file')
],
outputs=gr.Audio(type='filepath'),
title='cn-speech-esss',
description="""
by [Gitgato](gitgato)
This space uses the xtts_v2 model. Non-commercial use only. [Coqui Public Model License](https://coqui.ai/cpml)
Please ❤️ this Space. <a href="mailto:a@om">Email me</a>.
""",
theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"),
examples=[
["Hey! It's me Dorthy, from the Wizard of Oz. Type in whatever you'd like me to say.", "./audio/Wizard-of-Oz-Dorthy.wav"],
["It's me Vito Corleone, from the Godfather. Type in whatever you'd like me to say.", "./audio/Godfather.wav"],
["Hey, it's me Paris Hilton. Type in whatever you'd like me to say.", "./audio/Paris-Hilton.mp3"],
["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.", "./audio/Megan-Fox.mp3"],
["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.", "./audio/Jeff-Goldblum.mp3"],
["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.", "./audio/Heath-Ledger.mp3"],
]
)
# Lanzar la interfaz
iface.launch()