From 2de76e6c5e5aa916464f0ab7f29e59aac829dee4 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 14 Oct 2025 10:56:14 -0700 Subject: [PATCH] Update radio.py --- modules/radio.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/radio.py b/modules/radio.py index 019dba7..25bd3cb 100644 --- a/modules/radio.py +++ b/modules/radio.py @@ -25,7 +25,7 @@ if voxDetectionEnabled: import sounddevice as sd # pip install sounddevice sudo apt install portaudio19-dev from vosk import Model, KaldiRecognizer # pip install vosk import json - q = asyncio.Queue(maxsize=10) # what is a reasonable limit? + q = asyncio.Queue(maxsize=50) # queue for audio data if useLocalVoxModel: voxModel = Model(lang=localVoxModelPath) # use built in model for specified language @@ -153,8 +153,16 @@ def make_vox_callback(loop, q): try: loop.call_soon_threadsafe(q.put_nowait, bytes(indata)) except asyncio.QueueFull: - # Optionally log or just drop the oldest - logger.debug("RadioMon: VOX queue full, dropping audio frame") + # Drop the oldest item and add the new one + try: + q.get_nowait() # Remove oldest + except asyncio.QueueEmpty: + pass + try: + loop.call_soon_threadsafe(q.put_nowait, bytes(indata)) + except asyncio.QueueFull: + # If still full, just drop this frame + logger.debug("RadioMon: VOX queue full, dropping audio frame") except RuntimeError: # Loop may be closed pass