cn-speech-esss / app.py
gitgato's picture
Update app.py
733181b verified
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"),
)
# Lanzar la interfaz
iface.launch()