Created
September 13, 2016 03:16
-
-
Save erinxocon/161992079f608ef963120a1307eb0470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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