feat: AudioRecorder accepts device param — reads audio.device from config
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
-1
@@ -112,7 +112,9 @@ async def toggle_recording(user: dict = Depends(current_user)):
|
|||||||
return {"action": "reset"}
|
return {"action": "reset"}
|
||||||
if state.status == Status.IDLE:
|
if state.status == Status.IDLE:
|
||||||
from audio import AudioRecorder
|
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._recorder.start()
|
||||||
state.recording_user = user["username"]
|
state.recording_user = user["username"]
|
||||||
state._recording_output_dir = os.path.join(user["output_dir"], user["username"])
|
state._recording_output_dir = os.path.join(user["output_dir"], user["username"])
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import numpy as np
|
|||||||
|
|
||||||
|
|
||||||
class AudioRecorder:
|
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.sample_rate = sample_rate
|
||||||
|
self.device = device or None
|
||||||
self._buffer: list[np.ndarray] = []
|
self._buffer: list[np.ndarray] = []
|
||||||
self._stream = None
|
self._stream = None
|
||||||
self.is_recording = False
|
self.is_recording = False
|
||||||
@@ -25,6 +26,7 @@ class AudioRecorder:
|
|||||||
channels=1,
|
channels=1,
|
||||||
dtype="int16",
|
dtype="int16",
|
||||||
callback=self._callback,
|
callback=self._callback,
|
||||||
|
device=self.device,
|
||||||
)
|
)
|
||||||
self._stream.start()
|
self._stream.start()
|
||||||
|
|
||||||
|
|||||||
@@ -27,3 +27,14 @@ def test_recorder_save_wav(tmp_path):
|
|||||||
with wave.open(out) as wf:
|
with wave.open(out) as wf:
|
||||||
assert wf.getframerate() == 16000
|
assert wf.getframerate() == 16000
|
||||||
assert wf.getnchannels() == 1
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user