Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.44k stars 2.4k forks source link

Cannot open microphone stream (PyAudio errors -9999, -9998 etc) #423

Open S0mbre opened 5 years ago

S0mbre commented 5 years ago

Steps to reproduce

  1. Install latest SpeechRecognition (from PyPI or github)
  2. 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!)

shafaypro commented 5 years ago

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)

S0mbre commented 5 years ago

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" notifications@github.com: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.

rudrathegreat commented 4 years ago

for me the function for getting working mics does not even exist!

renatocava commented 1 year ago

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,