我的电脑正在监听但不前进,不向我显示错误或任何内容

My pc is listening and does not advance, does not show me an error or anything

我正在尝试测试用于语音识别的 Python 语音识别库并转到文本,但是当我 运行 程序时光标保持闪烁并且不前进,没有错误出现, 我必须按 Ctrl + C 才能打断它

这是我的代码,是唯一的例子

import speech_recognition as sr

   r = sr.Recognizer() 
   mic = sr.Microphone(device_index=0)
   with mic as source:
      print('Di algo: ')
      audio = r.listen(source)

      try:
         text = r.recognize_google(audio, language="es-EC")
         print('Tu dijiste:', text)
      except:
         print('No puedo escucharte')

但它什么都不做,甚至没有给我一个错误或 return 异常消息 保持这样

PS C:\Users\dell\Documents\Cuarentena\Pruebas de reconocimiento de voz> & C:/Users/dell/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/dell/Documents/Cuarentena/Pruebas de reconocimiento de voz/prueba1.py"
Di algo:
|

当我中断程序时,我得到这个:

File "c:/Users/kathy/Documents/Cuarentena/Pruebas de reconocimiento de voz/prueba1.py", line 9, in <module>
    audio = r.listen(source)
  File "C:\Users\kathy\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 652, in listen
    buffer = source.stream.read(source.CHUNK)
  File "C:\Users\kathy\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 161, in read
    return self.pyaudio_stream.read(size, exception_on_overflow=False)
  File "C:\Users\kathy\AppData\Local\Programs\Python\Python38\lib\site-packages\pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
KeyboardInterrupt

我很久以前用同一个库做一些测试,我试了两台电脑,在较新的电脑上我遇到了问题,因为声卡自动过滤了环境声音,只识别了最后的话。而在另一个中,它似乎什么也没做,或者花了很长时间来处理识别。最后我通过添加这一行来做到这一点:

r.adjust_for_ambient_noise(source)

根据 SpeechRecognition 3.8.1 中的文档:

is probably set to a value that is too high to start off with, and then being adjusted lower automatically by dynamic energy threshold adjustment. Before it is at a good level, the energy threshold is so high that speech is just considered ambient noise.

The solution is to decrease this threshold, or call recognizer_instance.adjust_for_ambient_noise beforehand, which will set the threshold to a good value automatically.

举个例子: speech_recognition/examples/calibrate_energy_threshold.py