Skip to content

mic_capture

diapason.desktop.mic_capture

Microphone capture for push-to-talk, outside any WebView.

Diapason's dictation captured audio with getUserMedia inside the WKWebView, so closing the window silenced the mic — the global hotkey would fire and record nothing. Capturing here, in the Python process via sounddevice, has no such coupling: the hotkey works with every window closed, which is the whole point of a push-to-talk key.

The DSP helpers (RMS level, linear resample, mono downmix) are separated from the live sounddevice stream so they can be unit-tested without a device.

MicCapture

Accumulate 16 kHz mono float audio while active; report a live level.

start() opens a sounddevice input stream on a background thread; stop() returns the captured mono buffer at 16 kHz. level is the most recent RMS, for a waveform/meter. The buffering itself is plain and testable via _ingest; only start/stop touch hardware.

buffer()

Concatenate everything captured so far as one 16 kHz mono array.

resample_linear(block, src_rate, dst_rate)

Linear resample a mono block. Good enough for speech; no SciPy needed.

The same linear interpolation Diapason's native recorder used to reach 16 kHz — cheap, dependency-free, and inaudible on voice.

rms_level(block)

Root-mean-square of a float block, as 0.0–100.0 for a UI meter.

to_mono(block)

Average channels down to mono, leaving a 1-D array.