fork download
  1. import speech_recognition as sr
  2.  
  3. def recognize_speech():
  4. # Create a speech recognition object
  5. r = sr.Recognizer()
  6.  
  7. # Use the microphone as the audio source
  8. with sr.Microphone() as source:
  9. print("Please say something:")
  10. audio = r.listen(source)
  11.  
  12. try:
  13. # Recognize the speech
  14. text = r.recognize_google(audio)
  15. print("You said:", text)
  16. except sr.UnknownValueError:
  17. print("Sorry, I couldn't understand what you said.")
  18. except sr.RequestError:
  19. print("Error requesting speech recognition results.")
  20.  
  21. if __name__ == "__main__":
  22. recognize_speech()
  23.  
  24. -- your code goes here
Success #stdin #stdout #stderr 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "import": syntax error