From 1cfefc8f8c1a6169d39d2fcab4c931a0d79d1f4b Mon Sep 17 00:00:00 2001 From: Twirre Meulenbelt <43213592+TwirreM@users.noreply.github.com> Date: Tue, 28 Oct 2025 13:30:45 +0100 Subject: [PATCH 1/3] fix: reduce debug log message amount when no audio received Used to be every `timeout` time that we'd get the message that no audio data is received. Now only the first time since no data is received. ref: N25B-213 --- src/control_backend/agents/vad_agent.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/control_backend/agents/vad_agent.py b/src/control_backend/agents/vad_agent.py index 4fef563..7b87fbb 100644 --- a/src/control_backend/agents/vad_agent.py +++ b/src/control_backend/agents/vad_agent.py @@ -58,8 +58,10 @@ class Streaming(CyclicBehaviour): async def run(self) -> None: data = await self.audio_in_poller.poll() if data is None: - logger.debug("No audio data received. Discarding buffer until new data arrives.") - self.audio_buffer = np.array([], dtype=np.float32) + if len(self.audio_buffer) > 0: + logger.debug("No audio data received. Discarding buffer until new data arrives.") + self.audio_buffer = np.array([], dtype=np.float32) + self.i_since_speech = 100 return # copy otherwise Torch will be sad that it's immutable From fd1facedd168b7965ca3933951f10e0b90201d87 Mon Sep 17 00:00:00 2001 From: Twirre Meulenbelt <43213592+TwirreM@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:00:51 +0100 Subject: [PATCH 2/3] chore: update integration test run instructions No longer `--only-group`, but `--group` so that it also uses the default dependencies. ref: N25B-213 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fa9584..22bcf3f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ uv run --only-group test pytest test/unit Or for integration tests: ```bash -uv run --only-group integration-test pytest test/integration +uv run --group integration-test pytest test/integration ``` ## GitHooks From f73f5106086e39a5ae686340c9f1e52d21e7da4c Mon Sep 17 00:00:00 2001 From: Twirre Meulenbelt <43213592+TwirreM@users.noreply.github.com> Date: Tue, 28 Oct 2025 18:13:00 +0100 Subject: [PATCH 3/3] fix: make VAD unit tests work with minimal dependencies By mocking PyTorch and ZMQ and adding the Numpy dependency. ref: N25B-213 --- pyproject.toml | 2 ++ test/unit/agents/test_vad_streaming.py | 3 +++ test/unit/conftest.py | 10 ++++++++++ uv.lock | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 8299d0f..ee3ca08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ requires-python = ">=3.13" dependencies = [ "fastapi[all]>=0.115.6", "mlx-whisper>=0.4.3 ; sys_platform == 'darwin'", + "numpy>=2.3.3", "openai-whisper>=20250625", "pyaudio>=0.2.14", "pydantic>=2.12.0", @@ -33,6 +34,7 @@ integration-test = [ "soundfile>=0.13.1", ] test = [ + "numpy>=2.3.3", "pytest>=8.4.2", "pytest-asyncio>=1.2.0", "pytest-cov>=7.0.0", diff --git a/test/unit/agents/test_vad_streaming.py b/test/unit/agents/test_vad_streaming.py index 20f20a1..9b38cd0 100644 --- a/test/unit/agents/test_vad_streaming.py +++ b/test/unit/agents/test_vad_streaming.py @@ -18,6 +18,9 @@ def audio_out_socket(): @pytest.fixture def streaming(audio_in_socket, audio_out_socket): + import torch + + torch.hub.load.return_value = (..., ...) # Mock return Streaming(audio_in_socket, audio_out_socket) diff --git a/test/unit/conftest.py b/test/unit/conftest.py index d7c10f2..76ef272 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -33,3 +33,13 @@ def pytest_configure(config): mock_config_module.settings = MagicMock() sys.modules["control_backend.core.config"] = mock_config_module + + # --- Mock torch and zmq for VAD --- + mock_torch = MagicMock() + mock_zmq = MagicMock() + mock_zmq.asyncio = mock_zmq + + # In individual tests, these can be imported and the return values changed + sys.modules["torch"] = mock_torch + sys.modules["zmq"] = mock_zmq + sys.modules["zmq.asyncio"] = mock_zmq.asyncio diff --git a/uv.lock b/uv.lock index 07ec3c1..c2bb61a 100644 --- a/uv.lock +++ b/uv.lock @@ -1332,6 +1332,7 @@ source = { virtual = "." } dependencies = [ { name = "fastapi", extra = ["all"] }, { name = "mlx-whisper", marker = "sys_platform == 'darwin'" }, + { name = "numpy" }, { name = "openai-whisper" }, { name = "pyaudio" }, { name = "pydantic" }, @@ -1358,6 +1359,7 @@ integration-test = [ { name = "soundfile" }, ] test = [ + { name = "numpy" }, { name = "pytest" }, { name = "pytest-asyncio" }, { name = "pytest-cov" }, @@ -1368,6 +1370,7 @@ test = [ requires-dist = [ { name = "fastapi", extras = ["all"], specifier = ">=0.115.6" }, { name = "mlx-whisper", marker = "sys_platform == 'darwin'", specifier = ">=0.4.3" }, + { name = "numpy", specifier = ">=2.3.3" }, { name = "openai-whisper", specifier = ">=20250625" }, { name = "pyaudio", specifier = ">=0.2.14" }, { name = "pydantic", specifier = ">=2.12.0" }, @@ -1392,6 +1395,7 @@ dev = [ ] integration-test = [{ name = "soundfile", specifier = ">=0.13.1" }] test = [ + { name = "numpy", specifier = ">=2.3.3" }, { name = "pytest", specifier = ">=8.4.2" }, { name = "pytest-asyncio", specifier = ">=1.2.0" }, { name = "pytest-cov", specifier = ">=7.0.0" },