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(linux:meetings): filter production captures from Linux prompts (#1916)
Idris Gadidacba9bd22ab
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1587ff8ca..cf652ac1d 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -685,7 +685,7 @@ Detects meetings via three independent sources, orchestrated by `MeetingDetectio- macOS: `macos-mic-listener` binary — CoreAudio process-object input monitoring, excluding the background `com.apple.CoreSpeech` service (it runs input during ordinary playback). `CAPABILITY PID` transitions prompt on their own. `CAPABILITY AGGREGATE` device activity (no process objects — roughly macOS < 14.2 — or a transient snapshot failure) includes playback on combined input/output devices, so it prompts only while a known meeting app is running; the helper retries PID monitoring every 30s from its heartbeat and the detector accepts the later `CAPABILITY PID`. Capability is logged at info level; `sustained-audio-detected` carries `attributed`- Windows: `windows-mic-listener.exe` — WASAPI `IAudioSessionManager2` session monitoring; self-mic exclusion happens in JavaScript using current OpenWhispr and capture-helper PIDs-- Linux: `pactl subscribe` — PulseAudio source-output events+- Linux: `pactl subscribe` — PulseAudio source-output events. Production captures (`media.role=production`, e.g. OBS) and sink-monitor captures (`stream.capture.sink=true`) still hold the mic for auto-end but don't prompt; the unfiltered fallbacks (a failed or JSON-less `pactl` listing, a failed excluded-pid lookup while polling, `pw-cli`) can't tell them apart- Windows/Linux: Fall back to polling if the native binary/command is unavailable. macOS has no safe polling signal: a missing binary pauses audio prompts, a crashed listener is respawned with exponential backoff (5s → 60s), and meanwhile only calendar reminders prompt while auto-end uses its existing silence fallback**Calendar Reminders** (scheduled meetings):diff --git a/src/helpers/audioActivityDetector.js b/src/helpers/audioActivityDetector.jsindex 5eedafdb8..ce045a701 100644--- a/src/helpers/audioActivityDetector.js+++ b/src/helpers/audioActivityDetector.js@@ -20,6 +20,32 @@ const LISTENER_RESPAWN_BASE_MS = 5 * 1000;const LISTENER_RESPAWN_MAX_MS = 60 * 1000;const EXEC_OPTS = { timeout: 5000, encoding: "utf8" };+function isLinuxMeetingPromptSourceOutput(sourceOutput) {+ const properties = sourceOutput?.properties ?? {};+ return properties["media.role"] !== "production" && properties["stream.capture.sink"] !== "true";+}++// Every pid holding a capture stream, and those whose streams are all+// production or sink-monitor capture, which are not meeting evidence.+function classifyLinuxCapturePids(sourceOutputs) {+ const capturePids = new Set();+ const meetingCapturePids = new Set();+ for (const sourceOutput of sourceOutputs) {+ // Audio-server plumbing (module-echo-cancel, loopbacks) legitimately+ // lacks application.process.id — client streams always carry it. Skip+ // such streams instead of surrendering PID reliability, or systems+ // with these modules loaded could never arm auto-end.+ const processId = Number(sourceOutput?.properties?.["application.process.id"]);+ if (!Number.isInteger(processId) || processId <= 0) continue;+ capturePids.add(processId);+ if (isLinuxMeetingPromptSourceOutput(sourceOutput)) meetingCapturePids.add(processId);+ }+ const nonMeetingCapturePids = new Set(+ [...capturePids].filter((processId) => !meetingCapturePids.has(processId))+ );+ return { capturePids, nonMeetingCapturePids };+}+class AudioActivityDetector extends EventEmitter {// `getExcludedProcessIds` lists every pid whose mic use is OpenWhispr's own:// the Electron process tree by default, plus any live capture helpers when@@ -42,6 +68,7 @@ class AudioActivityDetector extends EventEmitter {this._checking = false;this._listenerProcess = null;this._activeMicPids = new Set();+ this._nonMeetingCapturePids = new Set();this._activeSources = 0;this._sustainedTimer = null;this._running = false;@@ -225,6 +252,7 @@ class AudioActivityDetector extends EventEmitter {// still-running call as gone._resetListenerState() {this._activeMicPids.clear();+ this._nonMeetingCapturePids.clear();this._activeSources = 0;this._lastKnownMicState = false;this._externalCapturePids.clear();@@ -623,27 +651,20 @@ class AudioActivityDetector extends EventEmitter {const sourceOutputs = JSON.parse(stdout);if (!Array.isArray(sourceOutputs)) throw new Error("pactl returned a non-array response");- const activeMicPids = new Set();- for (const sourceOutput of sourceOutputs) {- // Audio-server plumbing (module-echo-cancel, loopbacks) legitimately- // lacks application.process.id — client streams always carry it. Skip- // such streams instead of surrendering PID reliability, or systems- // with these modules loaded could never arm auto-end.- const processId = Number(sourceOutput?.properties?.["application.process.id"]);- if (!Number.isInteger(processId) || processId <= 0) continue;- activeMicPids.add(processId);- }-- this._activeMicPids = activeMicPids;+ const { capturePids, nonMeetingCapturePids } = classifyLinuxCapturePids(sourceOutputs);+ this._activeMicPids = capturePids;+ this._nonMeetingCapturePids = nonMeetingCapturePids;// Raw total, matching the subscribe-event counter: it is the only signal// left if a later reconcile cannot parse pactl's JSON.this._activeSources = sourceOutputs.length;this._setPidScopedCapability(true);// A live listener makes the snapshot reliable unless the excluded-pid- // provider itself failed. It is external and can, so keep the raw total as- // the fallback signal rather than reporting a silent mic.+ // provider itself failed. It is external and can, so fall back to any+ // meeting stream rather than reporting a silent mic.this._onMicStateChanged(- this._externalMicReliable ? this._externalMicActive : this._activeSources > 0+ this._externalMicReliable+ ? this._externalCapturePids.size > 0+ : sourceOutputs.some(isLinuxMeetingPromptSourceOutput));} catch (err) {if (this._isStale(generation) || request !== this._linuxOwnershipRequest) return;@@ -699,7 +720,11 @@ class AudioActivityDetector extends EventEmitter {const externalPids = [...this._activeMicPids].filter((processId) => !excludedProcessIds.has(processId));- this._externalCapturePids = new Set(externalPids);+ // Only meeting evidence arms and re-arms the prompt; auto-end still counts+ // every capture as holding the mic.+ this._externalCapturePids = new Set(+ externalPids.filter((processId) => !this._nonMeetingCapturePids.has(processId))+ );const externalMicActive = externalPids.length > 0;if (!this._pidScopedCapability || !this._isOwnershipSnapshotLive()) {this._setExternalMicSnapshot(false, false, emitChange);@@ -944,21 +969,22 @@ class AudioActivityDetector extends EventEmitter {const sourceOutputs = JSON.parse(stdout);if (!Array.isArray(sourceOutputs)) throw new Error("pactl returned a non-array response");- const capturePids = sourceOutputs- .map((sourceOutput) => Number(sourceOutput?.properties?.["application.process.id"]))- .filter((processId) => Number.isInteger(processId) && processId > 0);+ const { capturePids, nonMeetingCapturePids } = classifyLinuxCapturePids(sourceOutputs);// A stream without application.process.id carries no ownership// information. When nothing in a non-empty listing is attributable, the// unfiltered listings below still answer "is anything capturing" — far// better than reporting silence and never detecting a meeting.- if (sourceOutputs.length > 0 && capturePids.length === 0) {+ if (sourceOutputs.length > 0 && capturePids.size === 0) {throw new Error("no source-output reported an application.process.id");}const excludedProcessIds = this._getExcludedProcessIdSet();- this._activeMicPids = new Set(capturePids);+ this._activeMicPids = capturePids;+ this._nonMeetingCapturePids = nonMeetingCapturePids;this._setPidScopedCapability(true);- return capturePids.some((processId) => !excludedProcessIds.has(processId));+ return [...capturePids].some(+ (processId) => !excludedProcessIds.has(processId) && !nonMeetingCapturePids.has(processId)+ );} catch (err) {this._setPidScopedCapability(false);debugLogger.debug(diff --git a/test/helpers/audioActivityDetector.test.js b/test/helpers/audioActivityDetector.test.jsindex 9f40157f3..e8b910072 100644--- a/test/helpers/audioActivityDetector.test.js+++ b/test/helpers/audioActivityDetector.test.js@@ -786,6 +786,143 @@ test("linux: reconciles source-output ownership at startup and on events", asyncdetector.stop();});+test("linux: production and sink-monitor streams do not drive meeting prompts", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });+ const { detector, children } = createDetector("linux", {+ execResponses: [+ { stdout: "[]" },+ {+ stdout: JSON.stringify([+ {+ properties: {+ "application.process.id": "101",+ "media.role": "production",+ },+ },+ {+ properties: {+ "application.process.id": "102",+ "stream.capture.sink": "true",+ },+ },+ ]),+ },+ ],+ });++ await detector.start();+ t.mock.timers.tick(RECONCILE_SPACING_MS);+ children[0].stdout.emit("data", "Event 'new' on source-output #1\n");+ await flushImmediate();++ assert.equal(detector._sustainedTimer, null);+ assert.deepEqual(detector.getExternalMicState(), {+ reliable: true,+ externalMicActive: true,+ });+ detector.stop();+});++test("linux: browser captures prompt and unattributed streams stay in the fallback count", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });+ const { detector, children } = createDetector("linux", {+ execResponses: [+ { stdout: "[]" },+ {+ stdout: JSON.stringify([+ {+ properties: {+ "application.process.id": "202",+ "application.process.binary": "chromium",+ },+ },+ { properties: {} },+ ]),+ },+ ],+ });++ await detector.start();+ t.mock.timers.tick(RECONCILE_SPACING_MS);+ children[0].stdout.emit("data", "Event 'new' on source-output #1\n");+ await flushImmediate();++ assert.equal(detector._activeSources, 2);+ assert.notEqual(detector._sustainedTimer, null);+ detector.stop();+});++test("linux: a process with a meeting stream prompts beside its own sink-monitor capture", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });+ const { detector, children } = createDetector("linux", {+ execResponses: [+ { stdout: "[]" },+ {+ // A browser call sharing system audio holds a mic stream and a monitor stream.+ stdout: JSON.stringify([+ { properties: { "application.process.id": "202" } },+ { properties: { "application.process.id": "202", "stream.capture.sink": "true" } },+ ]),+ },+ ],+ });++ await detector.start();+ t.mock.timers.tick(RECONCILE_SPACING_MS);+ children[0].stdout.emit("data", "Event 'new' on source-output #1\n");+ await flushImmediate();++ assert.notEqual(detector._sustainedTimer, null);+ detector.stop();+});++test("linux: a failed exclusion provider falls back to meeting streams only", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });+ const production = {+ properties: { "application.process.id": "101", "media.role": "production" },+ };+ const { detector, children } = createDetector("linux", {+ excludedProcessIds: () => {+ throw new Error("process tree unavailable");+ },+ execResponses: [+ { stdout: "[]" },+ { stdout: JSON.stringify([production]) },+ { stdout: JSON.stringify([production, { properties: { "application.process.id": "202" } }]) },+ ],+ });++ await detector.start();+ t.mock.timers.tick(RECONCILE_SPACING_MS);+ children[0].stdout.emit("data", "Event 'new' on source-output #1\n");+ await flushImmediate();+ assert.equal(detector.getExternalMicState().reliable, false);+ assert.equal(detector._sustainedTimer, null);++ t.mock.timers.tick(RECONCILE_SPACING_MS);+ children[0].stdout.emit("data", "Event 'new' on source-output #2\n");+ await flushImmediate();+ assert.notEqual(detector._sustainedTimer, null);+ detector.stop();+});++test("linux: polling uses the same prompt classification", async () => {+ const { detector } = createDetector("linux", {+ execResponses: [+ {+ stdout: JSON.stringify([+ { properties: { "application.process.id": "101", "media.role": "production" } },+ { properties: { "application.process.id": "102", "stream.capture.sink": "true" } },+ ]),+ },+ { stdout: JSON.stringify([{ properties: { "application.process.id": "103" } }]) },+ ],+ });++ assert.equal(await detector._checkLinux(), false);+ assert.equal(await detector._checkLinux(), true);+});+test("linux: a subscribe-event burst runs one leading and one spaced trailing reconcile", async (t) => {t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });const { detector, children, execCalls } = createDetector("linux", {@@ -1333,9 +1470,9 @@ test("win32: our own capture cannot cancel a real meeting already in progress",});const RECONCILE_SPACING = 1000;-const linuxStream = (index, processId) => ({+const linuxStream = (index, processId, properties = {}) => ({index,- properties: { "application.process.id": String(processId) },+ properties: { "application.process.id": String(processId), ...properties },});const linuxStreams = (...processIds) =>JSON.stringify(processIds.map((processId, index) => linuxStream(index + 1, processId)));@@ -1404,6 +1541,46 @@ test("linux: a later capture process re-prompts while the same process does not"detector.stop();});+test("linux: a later call re-prompts while a production capture keeps running", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });+ const OBS = 900;+ const CHROME = 17111;+ const ZOOM = 22222;+ const obs = linuxStream(1, OBS, { "media.role": "production" });+ const { detector, children } = createDetector("linux", {+ excludedProcessIds: () => [700],+ execResponses: [+ { stdout: JSON.stringify([obs]) },+ { stdout: JSON.stringify([obs, linuxStream(2, CHROME)]) },+ { stdout: JSON.stringify([obs]) },+ { stdout: JSON.stringify([obs, linuxStream(3, ZOOM)]) },+ ],+ });+ let detections = 0;+ detector.on("sustained-audio-detected", () => detections++);++ await detector.start();+ t.mock.timers.tick(SUSTAINED_MS);+ assert.equal(detections, 0, "a production capture alone is not a meeting");++ children[0].stdout.emit("data", "Event 'new' on source-output #2\n");+ t.mock.timers.tick(RECONCILE_SPACING);+ await flushImmediate();+ t.mock.timers.tick(SUSTAINED_MS);+ assert.equal(detections, 1);++ children[0].stdout.emit("data", "Event 'remove' on source-output #2\n");+ t.mock.timers.tick(RECONCILE_SPACING);+ await flushImmediate();++ children[0].stdout.emit("data", "Event 'new' on source-output #3\n");+ t.mock.timers.tick(RECONCILE_SPACING);+ await flushImmediate();+ t.mock.timers.tick(SUSTAINED_MS);+ assert.equal(detections, 2, "the capture still running must not block the next call's prompt");+ detector.stop();+});+test("linux: polling reports only external capture as mic activity", async () => {const { detector } = createDetector("linux", {excludedProcessIds: () => [700],