You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--- (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 method myRecognizer.listen(source, timeout=5, phrase_time_limit=5) using sr.Microphone() as source, well... sometimes I run it and ev3rything works fine. But some other times I run the script and it freezes when using myRecognizer.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!)
# -*- coding: utf-8 -*-importpyttsx3importspeech_recognitionassrGOOGLE_RECOGNITION=0SPHINX_RECOGNITION=1defspeech_to_string(language='es-es', recog_mode=GOOGLE_RECOGNITION):
#It takes microphone input from the user and returns string outputr=sr.Recognizer()
withsr.Microphone() assource:
print("Listening...")
r.pause_threshold=1r.adjust_for_ambient_noise(source)
audio=r.listen(source, timeout=5, phrase_time_limit=5)
query=""try:
print("Recognizing...")
ifrecog_mode==GOOGLE_RECOGNITION:
query=r.recognize_google(audio, language=language)
elifrecog_mode==SPHINX_RECOGNITION:
query=r.recognize_sphinx(audio, language=language)
else: # Defaultquery=r.recognize(audio, language=language)
#print(f"User said: {query}\n") #User query will be printed.exceptsr.WaitTimeoutErrorase:
print(e)
print("WAIT TIMEOUT ERROR")
exceptsr.UnknownValueErrorase:
print(e)
print("UNKNOWN VALUE ERROR")
exceptsr.RequestErrorase:
print(e)
print("UNKNOWN VALUE ERROR")
exceptExceptionase:
print(e)
print("SOME OTHER EXCEPTION...")
returnquery### MAIN CODEengine=pyttsx3.init()
whileTrue:
# XXX Should I run `speech_to_string` in a different thread to not block the main thread? TODO# I might add a variant of this main code using ThreadpoolExecutor for Multithreading# ...if required. For now I keep the snippet simple. It would freeze the same way anywaysmy_voice_str=speech_to_string('es-es', GOOGLE_RECOGNITION)
print(f"User said: {my_voice_str}\n")
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:
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Listening...
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>.
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:
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
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>.
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: