溢出 - 读者阅读速度不够快 PyAudio
当我遇到问题时,我目前正在尝试使用 Python 构建语音助手。 我使用 porcupine/picovoice 进行唤醒词检测,然后我调用一个函数,该函数一旦调用它就可以识别我所说的所有内容。
这就是函数:
def recognizevoicecommand():
try:
r = sr.Recognizer()
print("A moment of silence, please...")
with sr.Microphone() as source:
time.sleep(2)
r.adjust_for_ambient_noise(source)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
while True:
print("Say something!")
with m as source:
time.sleep(2)
print("Now!")
audio = r.listen(source)
print("Got it! Now to recognize it...")
try:
# recognize speech using Google Speech Recognition
value = r.recognize_google(audio)
print(value)
return value
break
except sr.UnknownValueError():
print("OOps")
break
except KeyboardInterrupt:
pass
如果我只是单独调用该函数,它就可以正常工作,识别我所说的内容,然后将其打印出来。
但问题是,一旦我将它与唤醒词检测器一起使用,我就会收到垃圾邮件 溢出 - 读者阅读速度不够快 后 请默哀片刻…… 被打印出来。
这是唤醒词检测代码,它本身以及在脚本中都可以正常工作,问题似乎出在识别部分,
porcupine = pvporcupine.create(access_key = accesskey, keywords=['computer'])
recorder = PvRecorder(device_index = 0, frame_length = porcupine.frame_length)
recorder.start()
while True:
pcm = recorder.read()
result = porcupine.process(pcm)
if(result >= 0):
print("Keyword detected")
print(recognizevoicecommand())
except pvporcupine.PorcupineInvalidArgumentError as e:
print("One or more arguments provided to Procupine is invalid!")
raise e
except pvporcupine.PorcupineActivationError as e:
print("Accesskey denied.")
raise e
except pvporcupine.PorcupineActivationLimitError as e:
print("Accesskey has reached it's temporary device limit.")
raise e
except pvporcupine.PorcupineActivationRefusedError as e:
print("Accesskey refused.")
raise e
except pvporcupine.PorcupineActivationThrottledError as e:
print("Accesskey has been throttled.")
raise e
except pvporcupine.PorcupineError as e:
print("Failed to initialize Porcupine.")
raise e
except KeyboardInterrupt:
print("Stopping")
finally:
if porcupine is not None:
porcupine.delete()
if recorder is not None:
recorder.delete()
老实说我不知道为什么它不起作用。希望能找到解决办法!
I'm currently trying to build a voice assistant with Python when I ran into a problem.
I'm using porcupine/picovoice for wakeword detection and then I call a function that recognizes everything I say as soon as I call it.
This is the function:
def recognizevoicecommand():
try:
r = sr.Recognizer()
print("A moment of silence, please...")
with sr.Microphone() as source:
time.sleep(2)
r.adjust_for_ambient_noise(source)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
while True:
print("Say something!")
with m as source:
time.sleep(2)
print("Now!")
audio = r.listen(source)
print("Got it! Now to recognize it...")
try:
# recognize speech using Google Speech Recognition
value = r.recognize_google(audio)
print(value)
return value
break
except sr.UnknownValueError():
print("OOps")
break
except KeyboardInterrupt:
pass
If i just call the function alone, it works perfectly fine, recognizes what I say and then prints it out.
But the problem is that as soon as I use it together with the wakeword detector, I get spammed with
Overflow - reader is not reading fast enough
after
A moment of silence, please...
is printed out.
This is the wakeword detection code, works fine on it's own as well as in the script, the problem seems to be in the recognizing part
porcupine = pvporcupine.create(access_key = accesskey, keywords=['computer'])
recorder = PvRecorder(device_index = 0, frame_length = porcupine.frame_length)
recorder.start()
while True:
pcm = recorder.read()
result = porcupine.process(pcm)
if(result >= 0):
print("Keyword detected")
print(recognizevoicecommand())
except pvporcupine.PorcupineInvalidArgumentError as e:
print("One or more arguments provided to Procupine is invalid!")
raise e
except pvporcupine.PorcupineActivationError as e:
print("Accesskey denied.")
raise e
except pvporcupine.PorcupineActivationLimitError as e:
print("Accesskey has reached it's temporary device limit.")
raise e
except pvporcupine.PorcupineActivationRefusedError as e:
print("Accesskey refused.")
raise e
except pvporcupine.PorcupineActivationThrottledError as e:
print("Accesskey has been throttled.")
raise e
except pvporcupine.PorcupineError as e:
print("Failed to initialize Porcupine.")
raise e
except KeyboardInterrupt:
print("Stopping")
finally:
if porcupine is not None:
porcupine.delete()
if recorder is not None:
recorder.delete()
I am honestly clueless why its not working. Hope to find a solution tho!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的错误,正如其他人指出的那样,这似乎是音频设备被多个进程使用的结果。我通过在其他操作发生时停止 Pico 录音机然后再次启动它来解决这个问题:
I ran in to the same error and it seems to be - as others have indicated - the result of the audio device being used by more than one process. I resolved it by stopping the Pico Voice recorder while the other action was taking place and then starting it again:
我正在执行类似的任务并遇到同样的问题。我发现解决方案是避免使用两种不同的录音方式。
PvRecorder 类将记录的数据表示为有符号整数。
据我所知,这与 wav 数据通常存储在音频文件中的方式不同。如果您查看 PvRecorder 如何保存 wav 文件,您可以看到它们使用 struct 模块:
您可以使用它来构造要传递的音频文件。
我将它与 Vosk 一起使用,效果非常好!
I'm working on a similar task and running into the same issue. I've found that the solution is to avoid using two different means of recording audio.
The PvRecorder class represents the recorded data as signed integers.
This is different AFAIK than how wav data is typically stored in an audio file. If you look to how PvRecorder saves wav files, you can see they use the struct module:
You can use that to construct the audio file to pass along.
I'm using it with Vosk and it works great!