OpenVoiceOS / ovos-microphone-plugin-alsa

Apache License 2.0
0 stars 1 forks source link

unmitigated raise Empty on empty `Queue` #5

Open emphasize opened 10 months ago

emphasize commented 10 months ago

Reported in Chat by @goldyfruit

Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.200 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.202 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.206 - HiveMind-voice-sat - ovos_dinkum_listener.service:run:299 - ERROR - voice_loop failed
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: Traceback (most recent call last):
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:   File "/home/goldyfruit/.venvs/ovos/lib/python3.11/site-packages/ovos_dinkum_listener/service.py", line 294, in run
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:     self.voice_loop.run()
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:   File "/home/goldyfruit/.venvs/ovos/lib/python3.11/site-packages/ovos_dinkum_listener/voice_loop/voice_loop.py", line 198, in run
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:     chunk = self.mic.read_chunk()
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:             ^^^^^^^^^^^^^^^^^^^^^
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:   File "/home/goldyfruit/.venvs/ovos/lib/python3.11/site-packages/ovos_microphone_plugin_alsa/__init__.py", line 47, in read_chunk
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:     return self._queue.get(timeout=self.timeout)
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:   File "/usr/lib/python3.11/queue.py", line 179, in get
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]:     raise Empty
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: _queue.Empty
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.213 - HiveMind-voice-sat - hivemind_voice_satellite.service:on_error:24 - ERROR - HiveMind Voice Satellite failed to launch ().
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.216 - HiveMind-voice-sat - ovos_dinkum_listener.service:run:302 - INFO - Service stopping
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.219 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.224 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.226 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32
Nov 10 06:43:20 rpi4b8g hivemind-voice-sat[14077]: 2023-11-10 06:43:20.229 - HiveMind-voice-sat - ovos_microphone_plugin_alsa:_run:92 - WARNING - Bad chunk length: -32

just check for self._queue.qsize() in advance

emphasize commented 9 months ago

There are different issues leading to this raise, but ultimately the loop is not capable to fill the queue - self.chunk_size=4096[bytes] - in timeout (default=5 seconds)

Above issue is getting negative size microphone chunks, but mathematically it would only require 4096 / 5 - 1 bytes sized chunks/sec to raise (what likely happened in other cases without warning logs about the size)

full_chunk += mic_chunk
while len(full_chunk) >= self.chunk_size:
     self._queue.put_nowait(full_chunk[: self.chunk_size])
     full_chunk = full_chunk[self.chunk_size:]

time.sleep(0.0)

(What is this 0.0 wait about? check period size <=> chunk size)