-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
myRecognizer object freezes the script when using .listen
method (sometimes)
#798
Comments
I still have no idea why it behaves this way... shouldn't the software throw an Exception instead of doing this? What should I do about this? Do you need some additional info, or adittional tests, to figure out how to patch this issue? Please let me know |
Well... I just downloaded the whole EDIT: I have checked out your tag system: so, by intuition I guess the "mentioned master last commit" is v3.12.0 ... I am still not sure that the failure won't happen again in this mentioned last version, that's why I am not closing this ticket... yet |
By the way, the project I was working on with your speech_recognition llibrary goes way beyond the snippet I shown in this #798 issue. The snippet just isolates the failure I reported here with more simple code. I wonder: would you like that I share my project based on your project through a GitHub repository? |
I just confirmed right now, that even the last version (both the 3.12.0 downloaded from pip3 and the one downloaded by zip directly from you last master commit at 13th December 2024, just keep freezing the same way sometimes)... some other times, it just works like normal (until it freezes the first time, then it will probably keep freezing the same way until I reboot my computer)... What I said in the first post, it doesn't have to be interrupted with Ctrl+C and re-run necessarily to reproduce the bug. You could just run it once, it would print the voice several times as expected, and then freeze as I described in the first post. I empathize that this is not normal behaviour. By the way, I still feel dissapointed with the fact that you labelled a "bug report ticket" as a "help wanted ticket." |
I have made additional tests to see how exactly the 1- Line 458 starts executing. Please notice that it is way too weird that this part of the Something must be done to prevent this from happening, but I barely started diving in your algorithm, so I have no idea what is actually going on in that So now we have a hint, lads... |
@ftnext you're wrong. I don't want help. This is a bug report, and I gave you detailed info about it. What I actually want is to fix this bug. |
Well, I digged a little more in this __init__.py file by filling with Here you have the resulting output:
...despite using Ctrl+C exactly when the line 524's I have reproduced this bug several times with these custom |
I have gone a little further in the investigation about how to fix this bug... the previously spotted line 530 from __init__.py (within buffer = source.stream.read(source.CHUNK) ... return self.pyaudio_stream.read(size, exception_on_overflow=False) ...so, I think it would be a good way to go to allow users to obtain an Exception on overflow (being it def read(self, size):
return self.pyaudio_stream.read(size, exception_on_overflow=False) ...I think it should be modified to look like this: def read(self, size, raise_exceptions=False):
return self.pyaudio_stream.read(size, exception_on_overflow=raise_exceptions) ...then, we could make the Recognizer's constructor to accept a boolean parameter that would be store into an ad-hoc inner property, so when it reads the microphone's audio stream, the user of the SpeechRecognition library can set if they wanna get exceptions if overflow occurrs or not. I want to make a Pull Request for this. |
I experimented the approach suggested above: and nothing changed. Not even flagging What a shame. 3 years ago or so I used your library to craft a project that executes commands and responds with text to speech to whatever the user asked. I abandoned my project 3 years ago due to, despite it worked, this issue made it unreliable. "Isn't my machine powerful enough?" "¿is it an issue with my machine?" I wondered... Nowadays I try to resume the development I abandoned 3 years ago, and find out that this issue happened as well in my new machine (not only in the old one). So this time I dared making a bug report, yet you @ftnext flagged it as "help wanted" --hilarious! Something's wrong in your algorithm, that's obvious. But I can't reach to understand what is it. And your lack of interest to analyze this bug report is pissing me off. In two weeks I will barely have time to back-engineer your mess, so... good luck with that |
I opened the issue Uberi#798 in Uberi/speech_recognition repository (Uberi is, if I recall correctly, the original creator of speech_recognition library. More details about issue Uberi#798 here Uberi#798 I am being ignored, so I tried to fix it myself... I kept giving feedback about my resech on this bug in the link above. Last time I could observe that `MicrophoneStream.read` (located at line Uberi#190) uses a keyword argument named `exception_on_overflow` which receives `False` value. In this commit I tried to reform the methodology, so the class `Recognizer`'s constructor can this time accept a boolean flag to let the user choose if they want an exception on overflow or not. The issue that `Recognizer.listen` freezing the whole script execution DIDN'T STOP despite flagging `exception_on_overflow` as `True` via the Recognizer's constructor. So, this commit is mostly completely useless for other that just documenting the failed attempt to resolve the issue. :-( In my implementation experiments of this commit, even if I instantiate `Recognizer` using `r = sr.Recognizer(raise_overflow_exceptions=True)`, the issue keeps happening over and over... so, if it's not an overflow issue, ¿just what the heck is causing the `source.stream.read(source.CHUNK)` instructions to freeze any script's execution? I have no idea what it could be...
...more details about the failed attempt described above in this commit that I uploaded to my fork of this repository. |
Steps to reproduce
--- (How do you make the issue happen? Does it happen every time you try it?)
Summarizing: I start my computer. I run this code on Terminal. And it works as expected. After some tests, I interrupt the script with Ctrl + C. Then I feel like run it again, it works again, interrupt it again with Ctrl + C. Eventually, after running it several times, when I execute the script again, it always freezes when the
r.listen
statement is reached, and not even Ctrl + C will interrupt the execution.When I instantiate a
Recognizer
object, and then execute the methodmyRecognizer.listen(source, timeout=5, phrase_time_limit=5)
usingsr.Microphone()
as source, well... sometimes I run it and ev3rything works fine. But some other times I run the script and it freezes when usingmyRecognizer.listen
method... when this happens, not even using Ctrl + C will succeed interrupting the script. This happens despite using timeout parameters to make sure ambient noise doesn't keep it listening forever, and depite testing it in relatively silent places. Trying to catch any exceptions, or even trying multithreading didn't solve the issue. This happens no matter if I use either Google Recognition or Sphinx Recognition--- (Make sure to go into as much detail as needed to reproduce the issue. Posting your code here can help us resolve the problem much faster!)
Expected behaviour
I just expect it to execute without freezing... and if freezing is unevitable due to infinite loops or other issues with the internal algorithm, at least, I'd like to have a chance to capture that as some kind of Exception that I can deal with.
Actual behaviour
As I explained in "Steps to reproduce" (AKA "how to make the issue happen"), sometimes it behaves as expected when you run the script. But some other times, you run the script and the script freezes completely. And when this happens, not even Ctrl + C from the linux Terminal will interrupt the script successfully. When it comes to this, my only option is forcefully closing the Terminal window.
(If the library threw an exception, paste the full stack trace here)
NO, it did throw none Exception at all. BUT, when it runs, I usually see all this output in the Terminal, both the times that the code works, and the times when it freezes. This one is, to be accurate, extracted from one of the executions that lead to freeze the Terminal console... but I honestly think it is very similar to this when it works as well:
System information
(Delete all the statements that don't apply.)
My system is <Ubuntu 24.04 LTS x64>
My Python version is <3.12.3>
My Pip version is <24.3.1>.
My SpeechRecognition library version is <3.10.4>. // Confirmed this issue happens with <3.12.x> as well
My PyAudio library version is <0.2.14>
My microphones are: ['sof-essx8336: - (hw:0,5)', 'sof-essx8336: - (hw:0,6)', 'sof-essx8336: - (hw:0,7)', 'pipewire', 'default']
I installed PocketSphinx from --> pip3
The text was updated successfully, but these errors were encountered: