File size: 1,185 Bytes
ba111ef
a37cd11
 
9a0bd5c
1ed8960
a37cd11
1ed8960
 
a37cd11
 
 
 
 
 
 
 
 
 
 
1ed8960
 
a37cd11
9a0bd5c
1ed8960
9a0bd5c
 
20cf7bd
 
1ed8960
a37cd11
1ed8960
 
 
 
 
9a0bd5c
1ed8960
20cf7bd
1ed8960
 
 
a37cd11
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
import os
import gradio as gr
import torch
import numpy as np

# ✅ Forzar consentimiento de licencia
os.environ["COQUI_TOS_AGREED"] = "1"

# ✅ Monkey patch: Sobrescribir torch.load temporalmente para desactivar weights_only
original_torch_load = torch.load

def patched_torch_load(f, *args, **kwargs):
    kwargs["weights_only"] = False  # 👈 Fuerza que no sea weights_only
    return original_torch_load(f, *args, **kwargs)

torch.load = patched_torch_load  # 🚨 Peligroso en general, pero necesario aquí

# ✅ Cargar el modelo después del parche
from TTS.api import TTS
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")

# 🎤 Función principal
def generate_audio(text, language, speaker_wav):
    if speaker_wav is not None:
        audio = tts.tts(text=text, speaker_wav=speaker_wav, language=language)
    audio_np = np.array(audio, dtype=np.float16)
    return (24000, audio_np)
    

# 🎛️ Interfaz
iface = gr.Interface(
    fn=generate_audio,
    inputs=[
        gr.Text(label="Texto"),
        gr.Text(label="Idioma (ej: 'es', 'en')"),
        gr.Audio(type="filepath", label="Audio de voz")
    ],
    outputs="audio"
)

iface.launch()