| 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" |
| |
| |
| if len(text) > 50000: |
| return None, "⚠️ Máximo 50000 caracteres por audio" |
| |
| try: |
| |
| with tempfile.NamedTemporaryFile(delete=False, suffix='.mp3', dir='/tmp') as fp: |
| temp_path = fp.name |
| |
| |
| 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)}" |
|
|
| |
| 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 |
| """) |
| |
| |
| 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" |
| ) |
| |
| |
| generate_btn.click( |
| fn=text_to_speech, |
| inputs=[text_input, accent_select, speed_check], |
| outputs=[audio_output, status_text] |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |