Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import speech_recognition as sr
  2.  
  3. # obtain audio from the microphone
  4. r = sr.Recognizer()
  5. d= ''
  6. while (d!='exit' and d!='quit'):
  7.     with sr.Microphone() as source:
  8.         print("Say something!")
  9.         audio = r.listen(source)
  10.    
  11. # recognize speech using Google Speech Recognition
  12.     try:
  13.         # for testing purposes, we're just using the default API key
  14.         # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
  15.         # instead of `r.recognize_google(audio)`
  16.         data = r.recognize_google(audio)
  17.         print("Google Speech Recognition thinks you said " + data)
  18.     except sr.UnknownValueError:
  19.         print("Google Speech Recognition could not understand audio")
  20.     except sr.RequestError as e:
  21.         print("Could not request results from Google Speech Recognition service; {0}".format(e))
  22.     d = data