File size: 449 Bytes
63dd1f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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)
|