1import speech_recognition as sr
2r = sr.Recognizer()
3with sr.Microphone() as source: # use the default microphone as the audio source
4 audio = r.listen(source) # listen for the first phrase and extract it into audio data
5
6try:
7 print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
8except LookupError: # speech is unintelligible
9 print("Could not understand audio")
10