Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 25, 2019 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/cbdefb7110d9cbf91bf8fb980abd5b48 to your computer and use it in GitHub Desktop.
Save parzibyte/cbdefb7110d9cbf91bf8fb980abd5b48 to your computer and use it in GitHub Desktop.
"""
Convertir texto a voz (TTS) con
Python usando gTTS
Ejemplo 4: Escribir hola mundo en un archivo, en idioma español
y después reproducirlo
@author parzibyte
"""
from gtts import gTTS
from playsound import playsound
NOMBRE_ARCHIVO = "sonido_generado.mp3"
tts = gTTS('Hola mundo. Estamos convirtiendo texto a voz con Python.', lang='es-us')
# Nota: podríamos llamar directamente a save
with open(NOMBRE_ARCHIVO, "wb") as archivo:
tts.write_to_fp(archivo)
playsound(NOMBRE_ARCHIVO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment