Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(dictation): stop Chromium's Windows mic aliases defeating the device pin (#2180)
Gabriel Stein878e7587548e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9500f2c20..102944b4c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Dictation+- **Windows pins the real microphone again.** Chromium lists the Windows default input twice, once as `default` and once as the `communications` alias, both with the device's own label. The selection code required exactly one label match, saw two, and fell back to Chromium's generic default, which it never caches, so every hotkey press re-resolved the device. Aliases are now ignored when matching, and the device is resolved once when the dictation window loads instead of on the first press. (#2180, thanks @Chadpiha)- **Dictation starts listening sooner on Windows.** Pressing the hotkey could take two seconds before the microphone opened. Since 1.9.0 the app pins the system-default microphone to a real device so its health checks can run, and on Windows finding that device means starting a PowerShell process that compiles C# on the fly — a lookup that ran on the first dictation after launch and again whenever an audio device came or went, and expired after 30 seconds either way. The answer is now resolved once at launch, kept until the OS reports a device change, and shared between windows, so the hotkey path only has to open the microphone. (#2178)- **Learned corrections skip everyday words.** When you fixed a transcript by swapping one common word for another, such as "why" for "what", the app treated the replacement as a mishearing and saved it to your dictionary. Those entries taught the cleanup model nothing and padded every request. Corrections that resolve to a common English word are no longer learned; names and jargon are unaffected. (#2178)diff --git a/src/helpers/microphoneSelection.js b/src/helpers/microphoneSelection.jsindex 5386563cb..dae995efc 100644--- a/src/helpers/microphoneSelection.js+++ b/src/helpers/microphoneSelection.js@@ -3,6 +3,11 @@ import { resolveMicDeviceSelection } from "./micDeviceSelection";export const MICROPHONE_SELECTION_MODES = ["system", "built-in", "specific"];+// Chromium lists the Windows default input twice ("default" and the+// "communications" role alias) under the device's own label. They are aliases,+// not candidates: matching them makes every Windows mic tie with itself.+const CHROMIUM_ALIAS_DEVICE_IDS = new Set(["default", "communications"]);+export function getMicrophoneSelectionMode(settings = {}) {if (MICROPHONE_SELECTION_MODES.includes(settings.microphoneSelectionMode)) {return settings.microphoneSelectionMode;@@ -30,7 +35,7 @@ function comparableLabel(label) {export function resolveSystemDefaultMicDevice(devices, systemDefault) {const inputs = devices.filter((device) => device.kind === "audioinput");const chromiumDefault = inputs.find((device) => device.deviceId === "default") || null;- const physicalInputs = inputs.filter((device) => device.deviceId !== "default");+ const physicalInputs = inputs.filter((device) => !CHROMIUM_ALIAS_DEVICE_IDS.has(device.deviceId));const nativeName = systemDefault?.name?.trim();if (nativeName) {@@ -80,7 +85,8 @@ export function resolveMicrophoneSelection(devices, settings, systemDefault = nuif (mode === "built-in") {const device = inputs.find(- (candidate) => candidate.deviceId !== "default" && isBuiltInMicrophone(candidate.label)+ (candidate) =>+ !CHROMIUM_ALIAS_DEVICE_IDS.has(candidate.deviceId) && isBuiltInMicrophone(candidate.label));return { mode, device: device || null, status: device ? "built-in" : "unavailable" };}diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.jsindex 97b6a21df..0837f1cab 100644--- a/src/hooks/useAudioRecording.js+++ b/src/hooks/useAudioRecording.js@@ -316,6 +316,10 @@ export const useAudioRecording = (toast, options = {}) => {useEffect(() => {audioManagerRef.current = new AudioManager();+ // Resolve and pin the input device now, not on the first hotkey press, which+ // would otherwise wait on the device lookup before the mic can open.+ void audioManagerRef.current.cacheMicrophoneDeviceId?.();+// Reset stale main-process state after a renderer reload or crash recovery.reportLifecycle("idle");diff --git a/test/helpers/microphoneSelection.test.js b/test/helpers/microphoneSelection.test.jsindex c69a900d9..9823c029d 100644--- a/test/helpers/microphoneSelection.test.js+++ b/test/helpers/microphoneSelection.test.js@@ -63,3 +63,58 @@ test("legacy microphone preferences retain their behavior", async () => {);assert.equal(getMicrophoneSelectionMode({ preferBuiltInMic: false }), "system");});++test("system mode ignores Chromium's Windows 'communications' alias when matching the native default", async () => {+ const { isCacheableMicrophoneResolution, resolveMicrophoneSelection } =+ await import("../../src/helpers/microphoneSelection.js");+ const expected = mic("9f2c1e5a7b3d", "Microphone (Realtek(R) Audio)");+ const result = resolveMicrophoneSelection(+ [+ mic("default", "Default - Microphone (Realtek(R) Audio)"),+ mic("communications", "Communications - Microphone (Realtek(R) Audio)"),+ expected,+ ],+ { microphoneSelectionMode: "system" },+ { name: "Microphone (Realtek(R) Audio)" }+ );++ assert.equal(result.device, expected);+ assert.equal(result.status, "native-exact");+ assert.equal(isCacheableMicrophoneResolution(result), true);+});++test("system mode ignores the alias when the native name is only contained in the Chromium label", async () => {+ const { isCacheableMicrophoneResolution, resolveMicrophoneSelection } =+ await import("../../src/helpers/microphoneSelection.js");+ const expected = mic("9f2c1e5a7b3d", "Microphone (Realtek(R) Audio)");+ const result = resolveMicrophoneSelection(+ [+ mic("default", "Default - Microphone (Realtek(R) Audio)"),+ mic("communications", "Communications - Microphone (Realtek(R) Audio)"),+ expected,+ ],+ { microphoneSelectionMode: "system" },+ { name: "Realtek(R) Audio" }+ );++ assert.equal(result.device, expected);+ assert.equal(result.status, "native-compatible");+ assert.equal(isCacheableMicrophoneResolution(result), true);+});++test("built-in mode pins the physical built-in device, not Chromium's Windows aliases", async () => {+ const { resolveMicrophoneSelection } = await import("../../src/helpers/microphoneSelection.js");+ const expected = mic("9f2c1e5a7b3d", "Microphone Array (Realtek(R) Audio)");+ const result = resolveMicrophoneSelection(+ [+ mic("default", "Default - Microphone Array (Realtek(R) Audio)"),+ mic("communications", "Communications - Microphone Array (Realtek(R) Audio)"),+ expected,+ mic("7a1b", "Jabra Evolve2 65"),+ ],+ { microphoneSelectionMode: "built-in" }+ );++ assert.equal(result.device, expected);+ assert.equal(result.status, "built-in");+});diff --git a/test/helpers/useAudioRecordingMicPrecache.test.js b/test/helpers/useAudioRecordingMicPrecache.test.jsnew file mode 100644index 000000000..52f34418b--- /dev/null+++ b/test/helpers/useAudioRecordingMicPrecache.test.js@@ -0,0 +1,72 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const React = require("react");+const { createRoot } = require("react-dom/client");+const {+ createRendererServer,+ installBrowserGlobals,+ installHookDom,+} = require("../lib/rendererTestHarness");++// Counts cacheMicrophoneDeviceId() calls. The electronAPI stub below omits+// getSttConfig, so the streaming warm-up (which also calls it) never runs and+// the single call must come from the mount effect.+const FAKE_AUDIO_MANAGER_SOURCE = `+export const micPrecache = { calls: 0 };+export default class FakeAudioManager {+ getState() {+ return {};+ }+ setCallbacks() {}+ cacheMicrophoneDeviceId() {+ micPrecache.calls += 1;+ }+ cancelPreparedMicCapture() {}+ cleanup() {}+}+`;++test("the mount effect pre-caches the microphone device id when streaming is off", async (t) => {+ let root = null;+ t.after(async () => {+ if (root) await React.act(async () => root.unmount());+ });++ const noopDispose = () => () => {};+ installBrowserGlobals(t, {+ window: {+ electronAPI: {+ onToggleDictation: noopDispose,+ onToggleVoiceAgent: noopDispose,+ onToggleTranslation: noopDispose,+ onStartDictation: noopDispose,+ onPrepareDictation: noopDispose,+ onCancelDictationPreparation: noopDispose,+ onStopDictation: noopDispose,+ dictationLifecycleStateChanged: () => {},+ },+ },+ });+ const container = installHookDom(t);++ const vite = await createRendererServer(t, {+ cachePrefix: "openwhispr-audio-recording-mic-precache-",+ mockModules: {+ "/helpers/audioManager": FAKE_AUDIO_MANAGER_SOURCE,+ },+ });+ const { useAudioRecording } = await vite.ssrLoadModule("/hooks/useAudioRecording.js");+ const { micPrecache } = await vite.ssrLoadModule("/helpers/audioManager");++ function Harness() {+ useAudioRecording(() => {}, { onDemoEvent: () => {} });+ return null;+ }++ root = createRoot(container);+ await React.act(async () => {+ root.render(React.createElement(Harness));+ });++ assert.equal(micPrecache.calls, 1);+});