From 833dd6c9d4cb1e2f94c8dc8b37ef298b5c4d41d6 Mon Sep 17 00:00:00 2001 From: Twirre Meulenbelt <43213592+TwirreM@users.noreply.github.com> Date: Tue, 28 Oct 2025 10:58:28 +0100 Subject: [PATCH] feat: allow no audio input while robot is speaking The VAD agent will discard its current buffer and retry receiving data. ref: N25B-213 --- src/control_backend/agents/vad_agent.py | 10 ++-------- test/unit/agents/test_vad_streaming.py | 4 +--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/control_backend/agents/vad_agent.py b/src/control_backend/agents/vad_agent.py index 9075269..4fef563 100644 --- a/src/control_backend/agents/vad_agent.py +++ b/src/control_backend/agents/vad_agent.py @@ -53,20 +53,14 @@ class Streaming(CyclicBehaviour): self.audio_out_socket = audio_out_socket self.audio_buffer = np.array([], dtype=np.float32) - self.i_since_data = 0 # Used to avoid logging every cycle if audio input stops self.i_since_speech = 100 # Used to allow small pauses in speech async def run(self) -> None: data = await self.audio_in_poller.poll() if data is None: - if self.i_since_data % 10 == 0: - logger.debug( - "Failed to receive audio from socket for %d ms.", - self.audio_in_poller.timeout_ms * (self.i_since_data + 1), - ) - self.i_since_data += 1 + logger.debug("No audio data received. Discarding buffer until new data arrives.") + self.audio_buffer = np.array([], dtype=np.float32) return - self.i_since_data = 0 # copy otherwise Torch will be sad that it's immutable chunk = np.frombuffer(data, dtype=np.float32).copy() diff --git a/test/unit/agents/test_vad_streaming.py b/test/unit/agents/test_vad_streaming.py index bb1a40b..20f20a1 100644 --- a/test/unit/agents/test_vad_streaming.py +++ b/test/unit/agents/test_vad_streaming.py @@ -86,9 +86,7 @@ async def test_no_data(audio_in_socket, audio_out_socket, streaming): audio_in_poller.poll.return_value = None streaming.audio_in_poller = audio_in_poller - assert streaming.i_since_data == 0 - await streaming.run() audio_out_socket.send.assert_not_called() - assert streaming.i_since_data == 1 + assert len(streaming.audio_buffer) == 0