Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Cargar el modelo de TTS en español
|
| 6 |
+
# Usamos "suno/bark" que soporta español latino muy bien
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
|
| 9 |
+
# Pipeline de texto a voz
|
| 10 |
+
synthesiser = pipeline("text-to-speech", "suno/bark-small", device=device)
|
| 11 |
+
|
| 12 |
+
def text_to_speech(text, voice_preset="v2/es_speaker_0"):
|
| 13 |
+
"""
|
| 14 |
+
Convierte texto a voz en español latino
|
| 15 |
+
"""
|
| 16 |
+
if not text.strip():
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
# Generar audio
|
| 20 |
+
speech = synthesiser(
|
| 21 |
+
text,
|
| 22 |
+
voice_preset=voice_preset,
|
| 23 |
+
do_sample=True
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Guardar el audio
|
| 27 |
+
output_path = "output.wav"
|
| 28 |
+
speech["audio"].export(output_path, format="wav")
|
| 29 |
+
|
| 30 |
+
return output_path
|
| 31 |
+
|
| 32 |
+
# Voces disponibles en español
|
| 33 |
+
voces_es = [
|
| 34 |
+
"v2/es_speaker_0", # Hombre
|
| 35 |
+
"v2/es_speaker_1", # Mujer
|
| 36 |
+
"v2/es_speaker_2", # Hombre
|
| 37 |
+
"v2/es_speaker_3", # Mujer
|
| 38 |
+
"v2/es_speaker_4", # Hombre
|
| 39 |
+
"v2/es_speaker_5", # Mujer
|
| 40 |
+
"v2/es_speaker_6", # Hombre
|
| 41 |
+
"v2/es_speaker_7", # Mujer
|
| 42 |
+
"v2/es_speaker_8", # Hombre
|
| 43 |
+
"v2/es_speaker_9", # Mujer
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
# Crear la interfaz de Gradio
|
| 47 |
+
with gr.Blocks(title="🎙️ Lector de Texto a Voz - Español Latino") as demo:
|
| 48 |
+
gr.Markdown("""
|
| 49 |
+
# 🎙️ Lector de Texto a Voz
|
| 50 |
+
### Español Latino - Gratis & Sin Límites
|
| 51 |
+
|
| 52 |
+
Escribe o pega cualquier texto y conviértelo a voz en segundos.
|
| 53 |
+
""")
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
with gr.Column():
|
| 57 |
+
text_input = gr.Textbox(
|
| 58 |
+
label="📝 Tu Texto",
|
| 59 |
+
placeholder="Escribe o pega aquí el texto que quieres escuchar...",
|
| 60 |
+
lines=5
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
voice_select = gr.Dropdown(
|
| 64 |
+
choices=voces_es,
|
| 65 |
+
value="v2/es_speaker_0",
|
| 66 |
+
label="🎭 Selecciona Voz"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
generate_btn = gr.Button("🔊 Generar Voz", variant="primary")
|
| 70 |
+
|
| 71 |
+
with gr.Column():
|
| 72 |
+
audio_output = gr.Audio(
|
| 73 |
+
label="🔊 Audio Generado",
|
| 74 |
+
type="filepath"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
gr.Markdown("""
|
| 78 |
+
### 💡 Tips:
|
| 79 |
+
- Usa puntuación para mejores pausas
|
| 80 |
+
- Textos largos pueden tardar más
|
| 81 |
+
- Prueba diferentes voces para encontrar tu favorita
|
| 82 |
+
""")
|
| 83 |
+
|
| 84 |
+
# Ejemplos predefinidos
|
| 85 |
+
gr.Examples(
|
| 86 |
+
examples=[
|
| 87 |
+
["Hola, ¿cómo estás? Bienvenido a este lector de texto a voz en español latino.", "v2/es_speaker_0"],
|
| 88 |
+
["El café de Colombia es reconocido mundialmente por su sabor y aroma únicos.", "v2/es_speaker_3"],
|
| 89 |
+
["¡Qué día tan hermoso para salir a caminar por el parque!", "v2/es_speaker_5"],
|
| 90 |
+
],
|
| 91 |
+
inputs=[text_input, voice_select],
|
| 92 |
+
label="🎯 Ejemplos Rápidos"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
# Evento del botón
|
| 96 |
+
generate_btn.click(
|
| 97 |
+
fn=text_to_speech,
|
| 98 |
+
inputs=[text_input, voice_select],
|
| 99 |
+
outputs=audio_output
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# Lanzar la app
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
demo.launch()
|