fix(voice): capture at the input device's native sample rate - #61463
fix(voice): capture at the input device's native sample rate#61463bricelb wants to merge 2 commits into
Conversation
Duplicate of #20788 (OPEN, earliest) -- both add |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
What the PR Does
Capture audio at the input device native sample rate instead of forcing 16 kHz, fixing compatibility with mics that reject 16 kHz capture.
Assessment
- Correctness: Device native rate is used via query_devices; falls back gracefully to SAMPLE_RATE (16 kHz) on any error.
- Testing: Comprehensive test coverage: device default rate, query failure fallback, non-numeric fallback, stream opened at device rate, WAV written at capture rate.
Note: PR was previously unreviewed.
Reviewed by Hermes Agent
|
Thanks for adding coverage for devices that reject 16 kHz. The reported hard-coded capture rate is still present on current main at Problems
Suggested changes
Automated hermes-sweeper review. |
c043134 to
7ce9e6e
Compare
The TUI launcher installs dependencies with npm install --workspace ui-tui, which intentionally leaves unrelated workspaces (apps/desktop, web) out of npm's hidden lockfile. _tui_need_npm_install() then compares the entire root package-lock.json against that hidden lockfile, so every subsequent launch sees the missing unrelated entries as staleness and re-runs npm install — a false-positive reinstall on every TUI start from a source checkout. Walk the lockfile dependency graph from the ui-tui workspace entry (following workspace links and npm's nested node_modules resolution candidates) and restrict the comparison to that closure, so only packages the scoped install is actually responsible for can mark the install stale.
AudioRecorder hard-codes SAMPLE_RATE (16 kHz) when opening the input stream, but some capture devices (e.g. USB microphones exposed through ALSA hw) reject 16 kHz outright — sd.InputStream fails with PaErrorCode -9997 (Invalid sample rate) and voice recording is broken. Query the default input device for its native default_samplerate at recording start and open the stream / write the WAV at that rate, falling back to the Whisper-friendly 16 kHz constant when the backend does not expose a usable rate. STT providers accept standard WAV rates, so downstream transcription is unaffected.
7ce9e6e to
0b46539
Compare
|
Merged into main via consolidated salvage PR #73520 (merge Your contribution is credited to you in git history. Thank you! Closing this PR as merged-via-salvage. |
What does this PR do?
Fixes broken voice recording on capture devices that reject 16 kHz input.
AudioRecorderhard-codesSAMPLE_RATE(16 kHz) when opening the input stream, but some devices (e.g. USB microphones exposed directly through ALSA hw) do not support 16 kHz capture —sd.InputStreamfails withPaErrorCode -9997(Invalid sample rate) and voice mode is unusable. Reproduced with a common "USB PnP Sound Device" microphone whose only supported rates are 44.1/48 kHz.The fix queries the default input device for its native
default_samplerateat recording start, opens the stream and writes the WAV at that rate, and falls back to the Whisper-friendly 16 kHz constant when the backend does not expose a usable rate. STT providers accept standard WAV sample rates, so downstream transcription is unaffected.Related Issue
No existing issue found for this; happy to open one if preferred.
Type of Change
Changes Made
tools/voice_mode.py: add_default_input_samplerate();AudioRecordertracks the capture rate per recording (self._sample_rate) and uses it for the input stream, the min-duration check, and the WAV header (_write_wavbecomes an instance method).tests/tools/test_voice_mode.py: newTestDefaultInputSamplerateclass (5 tests) covering device-rate selection, fallback on query failure / non-numeric rate, stream opening at the device rate, and WAV written at the capture rate.How to Test
python -c "import sounddevice as sd; sd.check_input_settings(samplerate=16000, channels=1, dtype='int16')"), enable voice mode and start a recording.pytest tests/tools/test_voice_mode.py -q— 78 passed.Checklist
Code
tests/tools/test_voice_mode.py, 78 passed)Documentation & Housekeeping
cli-config.yaml.example: N/A (no config keys changed)CONTRIBUTING.md/AGENTS.md: N/A