Sometime source.listen fail: listening timed out while waiting for phrase to start

问题描述 投票:0回答:0

我的密码是:

   r = sr.Recognizer()
   try:
       with sr.Microphone() as source:
       audio = r.listen(source, 20, 10)
   except:
       .....

有时它会进入 except 块并出现错误:等待短语开始时收听超时。

我检查了 lib 代码,似乎是由于:

 def listen(self, source, timeout=None, phrase_time_limit=None, snowboy_configuration=None):
    .......
    buffer = source.stream.read(source.CHUNK)
    if len(buffer) == 0:break

len(buffer)
为零,所以不能录音。 有时这就是问题所在,似乎是因为某些启动缓冲区为空。大多数时候我都能正常听到声音。

如果收不到声音,我的功能将失败所以我想检查声音是否为空,我想等到它可以开始录音。你知道为什么并且有解决这个问题的方法吗? 语音识别版本:3.9.0

audio speech-recognition record
© www.soinside.com 2019 - 2024. All rights reserved.