gpt4 book ai didi

python - 语音识别python卡在听

转载 作者:行者123 更新时间:2023-12-03 00:34:58 24 4
gpt4 key购买 nike

我正在使用 nextech 桌面麦克风进行输入,我知道它可以工作,因为我在设置中对其进行了测试。我正在使用python 2.7。当我执行下面的代码时,脚本就像卡在 audio = r.listen(source) .当我执行键盘中断以终止脚本时,这是回溯:

Traceback (most recent call last):
File "test_audio.py", line 12, in <module>
listen()
File "test_audio.py", line 6, in listen
audio = r.listen(source)
File "/usr/local/lib/python2.7/dist-packages/speech_recognition /__init__.py", line 559, in listen
buffer = source.stream.read(source.CHUNK)
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 161, in read
return self.pyaudio_stream.read(size, exception_on_overflow=False)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
KeyboardInterrupt

这是代码:
import speech_recognition as sr

def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
print(r.recognize_wit(audio, key="############################"))
except sr.RequestError as e:
return "There was an error with the speech recognititon software."

listen()

最佳答案

这可能会让你感兴趣:

The recognizer tries to recognize speech even when I’m not speaking, or after I’m done speaking.

Try increasing the recognizer_instance.energy_threshold property. This is basically how sensitive the recognizer is to when recognition should start. Higher values mean that it will be less sensitive, which is useful if you are in a loud room.



来源: https://pypi.python.org/pypi/SpeechRecognition/

关于python - 语音识别python卡在听,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42470223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com