speech_recognition
speech_recognition copied to clipboard
Cannot open microphone stream (PyAudio errors -9999, -9998 etc)
Steps to reproduce
- Install latest SpeechRecognition (from PyPI or github)
- Run the 'microphone_recognition.py' example (taken from examples dir on github)
Expected behaviour
I expected the sample to act the same as the inbuilt testing when you enter python -m speech_recognition
. Actually, this latter command never fails and does exactly what it's supposed to do: finds and initializes the mic correctly etc... Which seems magic to me, 'cos the main.py file in the Lib\site-packages\speech_recognition\ is almost the same as the 'microphone_recognition.py' example file.
Actual behaviour
Console output:
Say something!
Traceback (most recent call last):
File "microphone_recognition.py", line 23, in <module>
audio = r.listen(source)
File "c:\_PROG_\WPy64-3720\python-3.7.2.amd64\lib\site-packages\speech_recognition\__init__.py", line 638, in listen
assert source.stream is not None, "Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?"
AssertionError: Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "microphone_recognition.py", line 98, in <module>
print("Could not request results from IBM Speech to Text service; {0}".format(e))
File "c:\_PROG_\WPy64-3720\python-3.7.2.amd64\lib\site-packages\speech_recognition\__init__.py", line 188, in __exit__
self.stream.close()
AttributeError: 'NoneType' object has no attribute 'close'
System information
(Delete all the statements that don't apply.)
My system is Windows 10 x64
My Python version is 3.7.2
My SpeechRecognition library version is 3.8.1
My PyAudio library version is 0.2.11
My working microphones are: NONE! (sr.Microphone.list_working_microphones()
always returns an empty dict!)
The reason is there might be firewall or something which would be blocking the listeining of events for the microphone. Additionally, if you are using pycharm there might be something which you blocked the hardware access (for the firewall grant of Pycharm)
Hi! Thanks for the suggestion. Could you give a tip on where to look for blocking in Windows 10? -- Iskander 17.09.2019, 08:54, "Muhammad Shafay Amjad" [email protected]:The reason is there might be firewall or something which would be blocking the listeining of events for the microphone. Additionally, if you are using pycharm there might be something which you blocked the hardware access (for the firewall grant of Pycharm)—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.
for me the function for getting working mics does not even exist!
The reason is there might be firewall or something which would be blocking the listeining of events for the microphone. Additionally, if you are using pycharm there might be something which you blocked the hardware access (for the firewall grant of Pycharm)
Thanks @shafaypro. Uninstall my antivirus worked to me,