【问题标题】:My pc is listening and does not advance, does not show me an error or anything我的电脑正在听,但没有前进,没有显示错误或任何东西
【发布时间】:2020-06-16 12:41:21
【问题描述】:

我正在尝试测试用于语音识别的 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')

但它什么也不做,甚至不给我错误或返回异常消息 一直这样

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

【问题讨论】:

  • 您确定您的麦克风索引正确吗?您是否运行了 README 中的代码以确定索引是什么?
  • 是的,我查过了,我只有一个麦克风,这就是它的索引,即使没有那个参数我也没有得到结果
  • 阅读speech_recognition#pyaudio-for-microphone-users 并验证是否有任何与您的设置相关的内容。

标签: python python-3.x speech-recognition speech-to-text


【解决方案1】:

很久以前我用同一个库做一些测试,我尝试了两台计算机,在较新的计算机上我遇到了问题,因为声卡自动过滤环境声音并且只识别最后一个单词。而在另一个方面,它似乎什么也没做或需要很长时间来处理识别。最后我通过添加这一行来做到这一点:

r.adjust_for_ambient_noise(source)

根据SpeechRecognition 3.8.1中的文档:

可能被设置为一个太高而无法开始的值,然后通过动态能量阈值调整自动调整为更低。在它处于良好水平之前,能量阈值非常高,以至于语音只是被认为是环境噪声。

解决方法是降低这个阈值,或者提前调用recognizer_instance.adjust_for_ambient_noise,它会自动将阈值设置为一个好的值。

这是一个例子: speech_recognition/examples/calibrate_energy_threshold.py

【讨论】:

  • 太好了,非常感谢,我按照这个例子做了,现在可以了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-21
  • 2013-03-22
  • 1970-01-01
相关资源
最近更新 更多