import sounddevice as sd import soundfile as sf import numpy as np from pathlib import Path def record_to_wav(duration_sec: int, out_path: Path, fs: int = 16000) -> None: """ Interfaces directly with the local machine's sound architecture to capture a mono-channel audio array. """ recording = sd.rec(int(duration_sec * fs), samplerate=fs, channels=1, dtype=np.float32) sd.wait() sf.write(str(out_path), recording, fs)