Advertisement
Guest User

Untitled

a guest
Sep 12th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import speech_recognition as sr
  2.  
  3. def get_audio():
  4.     r =  sr.Recognizer()
  5.  
  6.     with sr.Microphone() as source:
  7.         r.adjust_for_ambient_noise(source, duration=5)
  8.         print("listening... ")
  9.         audio = r.listen(source)
  10.         said = ""
  11.  
  12.     try:
  13.         said = r.recognize_google(audio)
  14.     except sr.UnknownValueError:
  15.         print("Google Speech Recognition could not understand audio")
  16.     except sr.RequestError as e:
  17.         print("Could not request results from Google Speech Recognition service; {0}".format(e))
  18.  
  19.     return said.lower()        
  20.  
  21. print(get_audio())
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement