Created
February 8, 2020 07:19
-
-
Save nkpro2000sr/2c5ce048f8c8210d090871646063706d to your computer and use it in GitHub Desktop.
text_to_speech you can hear speech by calling say("text")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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