speech2text.py 432 B

12345678910111213141516
  1. import speech_recognition as sr
  2. # obtain audio from the microphone
  3. r = sr.Recognizer()
  4. with sr.Microphone() as source:
  5. print("Say something!")
  6. audio = r.listen(source)
  7. # recognize speech using Sphinx
  8. try:
  9. print("Sphinx thinks you said " + r.recognize_google_cloud(audio))
  10. except sr.UnknownValueError:
  11. print("Sphinx could not understand audio")
  12. except sr.RequestError as e:
  13. print("Sphinx error; {0}".format(e))