File size: 3,845 Bytes
e34d85a 69eefaf e34d85a 69eefaf d053998 69eefaf e34d85a 69eefaf 54ec337 e34d85a d053998 69eefaf d053998 69eefaf 9d14874 69eefaf d053998 e34d85a 69eefaf e34d85a 69eefaf 54ec337 69eefaf e34d85a 69eefaf d053998 69eefaf e34d85a | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | import gradio as gr
from gtts import gTTS
import os
import tempfile
def text_to_speech(text, tld='com.mx', slow=False):
"""
Convierte texto a voz usando Google TTS
tld='com.mx' = Español de México (latino)
tld='es' = Español de España
tld='com.ar' = Español de Argentina
"""
if not text or not text.strip():
return None, "⚠️ Por favor ingresa algún texto"
# Limitar longitud (gTTS tiene límite técnico)
if len(text) > 50000:
return None, "⚠️ Máximo 50000 caracteres por audio"
try:
# Crear archivo temporal
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp3', dir='/tmp') as fp:
temp_path = fp.name
# Generar audio
tts = gTTS(
text=text,
lang='es',
tld=tld,
slow=slow
)
tts.save(temp_path)
return temp_path, "✅ ¡Audio generado con éxito!"
except Exception as e:
return None, f"❌ Error: {str(e)}"
# CSS personalizado
custom_css = """
.gradio-container {
max-width: 900px !important;
margin: 0 auto;
}
"""
with gr.Blocks(css=custom_css, title="🎙️ TTS Español Latino") as demo:
gr.Markdown("""
# 🎙️ Lector de Texto a Voz
### Español Latino - Gratis & Sin Límites
Escribe cualquier texto y escúchalo en voz alta al instante.
""")
with gr.Row():
with gr.Column(scale=2):
text_input = gr.Textbox(
label="📝 Texto a convertir",
placeholder="Escribe o pega aquí tu texto en español...",
lines=5
)
with gr.Row():
accent_select = gr.Dropdown(
choices=[
("🇲🇽 Español Latino (México)", "com.mx"),
("🇪🇸 Español de España", "es"),
("🇦🇷 Español Latino (Argentina)", "com.ar"),
],
value="com.mx",
label="🌍 Acento"
)
speed_check = gr.Checkbox(
label="🐌 Lento",
value=False
)
generate_btn = gr.Button(
"🔊 Generar Voz",
variant="primary",
size="lg"
)
status_text = gr.Textbox(
label="Estado",
interactive=False,
value="✅ Listo"
)
with gr.Column(scale=1):
audio_output = gr.Audio(
label="🔊 Tu Audio",
type="filepath"
)
gr.Markdown("""
**Características:**
- ✅ Gratis y sin registro
- ⚡ Generación instantánea
- 🎵 Calidad de voz natural
- 📥 Descarga directa
**Límite:** 50000 caracteres por audio
""")
# Ejemplos
gr.Examples(
examples=[
["Hola, ¿cómo estás? Bienvenido a este lector de texto a voz en español latino.", "com.mx", False],
["El café de Colombia es reconocido mundialmente por su sabor único y aroma inigualable.", "com.mx", False],
["¡Buenos días! Espero que tengas un excelente día lleno de éxitos y alegrías.", "com.ar", False],
],
inputs=[text_input, accent_select, speed_check],
label="🎯 Probar ejemplos"
)
# Eventos
generate_btn.click(
fn=text_to_speech,
inputs=[text_input, accent_select, speed_check],
outputs=[audio_output, status_text]
)
if __name__ == "__main__":
demo.launch() |