Skip to content

Instantly share code, notes, and snippets.

@henry16lin
Created September 10, 2019 17:07
Show Gist options
  • Save henry16lin/0b1ac1d32e0aba52a52e9d2fef5ba2df to your computer and use it in GitHub Desktop.
Save henry16lin/0b1ac1d32e0aba52a52e9d2fef5ba2df to your computer and use it in GitHub Desktop.
def speeker(texts,lang='zh-tw'):
mixer.init()
with tempfile.NamedTemporaryFile(delete=True) as fp:
tts = gTTS(text=texts,lang=lang)
tts.save("{}.mp3".format(fp.name))
mixer.music.load('{}.mp3'.format(fp.name))
mixer.music.play()
def listener():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
audio = r.listen(source)
return r.recognize_google(audio,language = 'zh-tw')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment