From ef4aa2a8402c3a9d0159bea5d2c014bdb07bf0df Mon Sep 17 00:00:00 2001 From: "thomas.kopp" Date: Wed, 1 Apr 2026 20:32:44 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20AudioRecorder=20accepts=20device=20para?= =?UTF-8?q?m=20=E2=80=94=20reads=20audio.device=20from=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- api/router.py | 4 +++- audio.py | 4 +++- tests/test_audio.py | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api/router.py b/api/router.py index 49a2e48..863e690 100644 --- a/api/router.py +++ b/api/router.py @@ -112,7 +112,9 @@ async def toggle_recording(user: dict = Depends(current_user)): return {"action": "reset"} if state.status == Status.IDLE: from audio import AudioRecorder - state._recorder = AudioRecorder() + cfg = load_config() + audio_device = cfg.get("audio", {}).get("device") or None + state._recorder = AudioRecorder(device=audio_device) state._recorder.start() state.recording_user = user["username"] state._recording_output_dir = os.path.join(user["output_dir"], user["username"]) diff --git a/audio.py b/audio.py index 5b64345..8fa76cf 100644 --- a/audio.py +++ b/audio.py @@ -4,8 +4,9 @@ import numpy as np class AudioRecorder: - def __init__(self, sample_rate: int = 16000): + def __init__(self, sample_rate: int = 16000, device: str | None = None): self.sample_rate = sample_rate + self.device = device or None self._buffer: list[np.ndarray] = [] self._stream = None self.is_recording = False @@ -25,6 +26,7 @@ class AudioRecorder: channels=1, dtype="int16", callback=self._callback, + device=self.device, ) self._stream.start() diff --git a/tests/test_audio.py b/tests/test_audio.py index fef3f84..2935d3b 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -27,3 +27,14 @@ def test_recorder_save_wav(tmp_path): with wave.open(out) as wf: assert wf.getframerate() == 16000 assert wf.getnchannels() == 1 + + +def test_recorder_stores_device_param(): + from audio import AudioRecorder + rec = AudioRecorder(device="my-pipewire-source") + assert rec.device == "my-pipewire-source" + +def test_recorder_device_none_when_empty_string(): + from audio import AudioRecorder + rec = AudioRecorder(device="") + assert rec.device is None