Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Created September 13, 2016 03:16
Show Gist options
  • Save erinxocon/161992079f608ef963120a1307eb0470 to your computer and use it in GitHub Desktop.
Save erinxocon/161992079f608ef963120a1307eb0470 to your computer and use it in GitHub Desktop.
import speech_recognition as sr
import tpfd
p = tpfd.Parser()
@p.on_recognize('{Play} song')
def main(kwargs):
print(kwargs.get('play'))
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
string = r.recognize_google(audio)
print("Google Speech Recognition thinks you said " + string)
p.parse_string(string)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment