Advertisement
Guest User

speakup

a guest
Jul 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def start_recording(self):
  2. self._logger.debug('start_recording')
  3. self._is_recording = True
  4.  
  5. r = sr.Recognizer()
  6. audios = []
  7.  
  8. while(self._is_recording):
  9. with sr.Microphone() as source:
  10. print("Speak!")
  11. audio = r.listen(source)
  12. audios.append(audio)
  13. print("Stopped!")
  14.  
  15.  
  16. speechStrings = []
  17. for audio in audios:
  18. try:
  19. speechString = r.recognize_google(audio)
  20. speechStrings.append(speechString)
  21.  
  22. except sr.UnknownValueError:
  23. print("Failed to understand")
  24. except sr.RequestError as e:
  25. print("Failed to request: {}".format(e))
  26.  
  27. print(speechStrings)
  28. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement