Skip to content

feat: add auto-select best microphone option#515

Open
jalvarezz13 wants to merge 1 commit intoOpenWhispr:mainfrom
jalvarezz13:feat/auto-mic-selection
Open

feat: add auto-select best microphone option#515
jalvarezz13 wants to merge 1 commit intoOpenWhispr:mainfrom
jalvarezz13:feat/auto-mic-selection

Conversation

@jalvarezz13
Copy link
Copy Markdown

Summary

  • Adds an "Auto (best input)" option to the microphone selection dropdown
  • Probes all available audio input devices (~300ms each), measures RMS energy, and automatically selects the one with the strongest signal
  • Caches the selected device for the session; invalidates on devicechange events
  • Falls back to system default if probing fails or no devices are available

Changes

  • src/helpers/audioManager.js:

    • New probeDevices() method: opens each mic briefly via getUserMedia() + AnalyserNode, computes peak RMS, returns best deviceId
    • Updated getAudioConstraints(): when selectedMicDeviceId === "auto", runs probe and caches result
    • Constructor: added devicechange listener to clear cache when in auto mode
  • src/components/ui/MicrophoneSettings.tsx:

    • Added "Auto (best input)" as first dropdown option before "System Default"
    • Updated SelectValue display for auto mode
    • Added description text when auto is selected
  • i18n: Added microphoneSettings.auto and microphoneSettings.autoDescription to all 10 locale files

How it works

  1. User selects "Auto (best input)" from the mic dropdown
  2. On next recording, getAudioConstraints() detects selectedMicDeviceId === "auto"
  3. probeDevices() sequentially opens each audio input for ~300ms, measuring RMS audio energy via AnalyserNode.getByteTimeDomainData()
  4. The device with the highest peak RMS wins and is cached
  5. Cache is cleared automatically on devicechange events (plug/unplug)

Testing

  • npm run build:renderer passes (Vite build clean)
  • No new LSP diagnostics
  • No settings store changes needed — uses existing selectedMicDeviceId with "auto" as a special value

Closes #514

Add 'Auto (best input)' option to the microphone dropdown that probes
all available audio inputs (~300ms each), measures RMS energy, and
selects the device with the strongest signal. Cache is invalidated on
device change events.

Closes OpenWhispr#514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Auto-select best microphone based on audio input level

1 participant