Skip to content

Instantly share code, notes, and snippets.

@nkpro2000sr
Created February 8, 2020 07:19
Show Gist options
  • Save nkpro2000sr/2c5ce048f8c8210d090871646063706d to your computer and use it in GitHub Desktop.
Save nkpro2000sr/2c5ce048f8c8210d090871646063706d to your computer and use it in GitHub Desktop.
text_to_speech you can hear speech by calling say("text")
from gtts import gTTS
from io import BytesIO
import pygame; pygame.mixer.init()
def say(text):
tts = gTTS(text=text, lang='en')
fp = BytesIO()
tts.write_to_fp(fp)
fp.seek(0)
pygame.mixer.music.load(fp)
pygame.mixer.music.play()
return fp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment