File size: 1,270 Bytes
a8e2c93
 
 
 
a983024
 
a8e2c93
 
a983024
 
a8e2c93
a983024
 
a8e2c93
a983024
a8e2c93
a983024
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22d5c7e
a983024
a8e2c93
a983024
 
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
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()