Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: replace broken ioreg mic detection with CoreAudio binary

Gabriel Stein2caf34fe8734
diff --git a/electron-builder.json b/electron-builder.json
index 130827c52..8dc17b5c0 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -87,6 +87,7 @@
"src/assets/**/*",
"resources/bin/macos-globe-listener",
"resources/bin/macos-fast-paste",
+ "resources/bin/macos-mic-check",
"resources/bin/linux-fast-paste",
{
"from": "resources/bin/",
diff --git a/resources/bin/macos-mic-check b/resources/bin/macos-mic-check
new file mode 100755
index 000000000..8f06c85da
Binary files /dev/null and b/resources/bin/macos-mic-check differ
diff --git a/resources/macos-mic-check.swift b/resources/macos-mic-check.swift
new file mode 100644
index 000000000..213bd8422
--- /dev/null
+++ b/resources/macos-mic-check.swift
@@ -0,0 +1,27 @@
+import CoreAudio
+import Foundation
+
+var systemObject = AudioObjectID(kAudioObjectSystemObject)
+var address = AudioObjectPropertyAddress(
+ mSelector: kAudioHardwarePropertyDefaultInputDevice,
+ mScope: kAudioObjectPropertyScopeGlobal,
+ mElement: kAudioObjectPropertyElementMain
+)
+var deviceID = AudioDeviceID()
+var size = UInt32(MemoryLayout<AudioDeviceID>.size)
+
+let status = AudioObjectGetPropertyData(systemObject, &address, 0, nil, &size, &deviceID)
+guard status == noErr else { print("false"); exit(0) }
+
+var isRunning: UInt32 = 0
+var runningAddress = AudioObjectPropertyAddress(
+ mSelector: kAudioDevicePropertyDeviceIsRunningSomewhere,
+ mScope: kAudioObjectPropertyScopeInput,
+ mElement: kAudioObjectPropertyElementMain
+)
+var runningSize = UInt32(MemoryLayout<UInt32>.size)
+
+let runStatus = AudioObjectGetPropertyData(deviceID, &runningAddress, 0, nil, &runningSize, &isRunning)
+guard runStatus == noErr else { print("false"); exit(0) }
+
+print(isRunning > 0 ? "true" : "false")
diff --git a/src/helpers/audioActivityDetector.js b/src/helpers/audioActivityDetector.js
index 20ef463d8..9b4c1991c 100644
--- a/src/helpers/audioActivityDetector.js
+++ b/src/helpers/audioActivityDetector.js
@@ -1,8 +1,10 @@
-const { execSync } = require("child_process");
+const { execSync, execFileSync } = require("child_process");
+const path = require("path");
+const fs = require("fs");
const EventEmitter = require("events");
const debugLogger = require("./debugLogger");
-const CHECK_INTERVAL_MS = 10 * 1000;
+const CHECK_INTERVAL_MS = 5 * 1000;
const SUSTAINED_THRESHOLD_CHECKS = 3;
const COOLDOWN_MS = 30 * 60 * 1000;
const EXEC_OPTS = { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] };
@@ -15,11 +17,18 @@ class AudioActivityDetector extends EventEmitter {
this.audioActiveStart = null;
this.hasPrompted = false;
this.lastDismissedAt = null;
+ this._micCheckBinary = null;
}
start() {
if (this.checkInterval) return;
- debugLogger.info("Starting audio activity detector", {}, "meeting");
+ if (process.platform === "darwin") this._resolveMicCheckBinary();
+ debugLogger.info(
+ "Audio activity detector started",
+ { intervalMs: CHECK_INTERVAL_MS, threshold: SUSTAINED_THRESHOLD_CHECKS },
+ "meeting"
+ );
+ this._check();
this.checkInterval = setInterval(() => this._check(), CHECK_INTERVAL_MS);
}
@@ -29,12 +38,17 @@ class AudioActivityDetector extends EventEmitter {
this.checkInterval = null;
}
this._reset();
- debugLogger.info("Stopped audio activity detector", {}, "meeting");
+ debugLogger.info("Audio activity detector stopped", {}, "meeting");
}
dismiss() {
this.lastDismissedAt = Date.now();
this._reset();
+ debugLogger.info(
+ "Audio detection dismissed, cooldown started",
+ { cooldownMs: COOLDOWN_MS },
+ "meeting"
+ );
}
_reset() {
@@ -47,27 +61,36 @@ class AudioActivityDetector extends EventEmitter {
if (this.lastDismissedAt && Date.now() - this.lastDismissedAt < COOLDOWN_MS) return;
if (this.hasPrompted) return;
- if (this._isMicActive()) {
+ const active = this._isMicActive();
+ debugLogger.debug(
+ "Mic check",
+ { active, consecutiveChecks: this.consecutiveChecks },
+ "meeting"
+ );
+
+ if (active) {
this.consecutiveChecks++;
if (!this.audioActiveStart) this.audioActiveStart = Date.now();
if (this.consecutiveChecks >= SUSTAINED_THRESHOLD_CHECKS) {
this.hasPrompted = true;
const now = Date.now();
+ const durationMs = now - this.audioActiveStart;
debugLogger.info(
"Sustained audio activity detected",
- {
- consecutiveChecks: this.consecutiveChecks,
- durationMs: now - this.audioActiveStart,
- },
+ { consecutiveChecks: this.consecutiveChecks, durationMs },
"meeting"
);
- this.emit("sustained-audio-detected", {
- durationMs: now - this.audioActiveStart,
- detectedAt: now,
- });
+ this.emit("sustained-audio-detected", { durationMs, detectedAt: now });
}
} else {
+ if (this.consecutiveChecks > 0) {
+ debugLogger.debug(
+ "Mic activity reset",
+ { previousChecks: this.consecutiveChecks },
+ "meeting"
+ );
+ }
this.consecutiveChecks = 0;
this.audioActiveStart = null;
}
@@ -86,7 +109,51 @@ class AudioActivityDetector extends EventEmitter {
}
}
+ _resolveMicCheckBinary() {
+ const binaryName = "macos-mic-check";
+ const candidates = [
+ path.join(__dirname, "..", "..", "resources", "bin", binaryName),
+ path.join(__dirname, "..", "..", "resources", binaryName),
+ ];
+
+ if (process.resourcesPath) {
+ candidates.push(
+ path.join(process.resourcesPath, binaryName),
+ path.join(process.resourcesPath, "bin", binaryName),
+ path.join(process.resourcesPath, "resources", "bin", binaryName),
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", "bin", binaryName)
+ );
+ }
+
+ for (const candidate of candidates) {
+ try {
+ if (fs.existsSync(candidate)) {
+ fs.accessSync(candidate, fs.constants.X_OK);
+ this._micCheckBinary = candidate;
+ debugLogger.info("Resolved mic-check binary", { path: candidate }, "meeting");
+ return;
+ }
+ } catch {
+ // continue
+ }
+ }
+ debugLogger.warn("macos-mic-check binary not found, falling back to ioreg", {}, "meeting");
+ }
+
_checkDarwin() {
+ if (this._micCheckBinary) {
+ try {
+ const out = execFileSync(this._micCheckBinary, [], { timeout: 3000, encoding: "utf8" });
+ return out.trim() === "true";
+ } catch (err) {
+ debugLogger.debug(
+ "mic-check binary failed, falling back",
+ { error: err.message },
+ "meeting"
+ );
+ }
+ }
+
try {
const out = execSync("ioreg -l -w 0 | grep '\"IOAudioEngineState\" = 1'", EXEC_OPTS);
return out.trim().length > 0;
diff --git a/src/helpers/meetingDetectionEngine.js b/src/helpers/meetingDetectionEngine.js
index 94d21d9b4..e75d88379 100644
--- a/src/helpers/meetingDetectionEngine.js
+++ b/src/helpers/meetingDetectionEngine.js
@@ -28,19 +28,28 @@ class MeetingDetectionEngine {
}
_handleDetection(source, key, data) {
- if (source === "process" && !this.preferences.processDetection) return;
- if (source === "audio" && !this.preferences.audioDetection) return;
-
const detectionId = `${source}:${key}`;
- if (this.activeDetections.has(detectionId)) return;
+ if (source === "process" && !this.preferences.processDetection) {
+ debugLogger.debug("Process detection disabled, ignoring", { detectionId }, "meeting");
+ return;
+ }
+ if (source === "audio" && !this.preferences.audioDetection) {
+ debugLogger.debug("Audio detection disabled, ignoring", { detectionId }, "meeting");
+ return;
+ }
+
+ if (this.activeDetections.has(detectionId)) {
+ debugLogger.debug("Detection already active, skipping", { detectionId }, "meeting");
+ return;
+ }
const calendarState = this.googleCalendarManager?.getActiveMeetingState?.();
if (calendarState) {
if (calendarState.activeMeeting !== null || calendarState.activeEvents?.length > 0) {
- debugLogger.debug(
+ debugLogger.info(
"Suppressing detection — active calendar meeting exists",
- { detectionId },
+ { detectionId, activeMeeting: calendarState.activeMeeting?.summary },
"meeting"
);
return;
@@ -56,6 +65,11 @@ class MeetingDetectionEngine {
});
}
+ debugLogger.info(
+ "Meeting detection triggered",
+ { detectionId, source, imminentEvent: imminentEvent?.summary ?? null },
+ "meeting"
+ );
this.activeDetections.set(detectionId, { source, key, data, dismissed: false });
this._showPrompt(detectionId, source, key, data, imminentEvent);
}
@@ -74,9 +88,13 @@ class MeetingDetectionEngine {
body = "It sounds like you're in a meeting. Want to take notes?";
}
+ debugLogger.info("Showing notification", { detectionId, title }, "meeting");
+
const notif = new Notification({ title, body });
notif.on("click", () => {
+ debugLogger.info("Notification clicked — starting recording", { detectionId }, "meeting");
+
let event;
if (imminentEvent) {
event = imminentEvent;
@@ -104,6 +122,7 @@ class MeetingDetectionEngine {
});
notif.on("close", () => {
+ debugLogger.debug("Notification closed", { detectionId }, "meeting");
this._dismiss(source, key);
const detection = this.activeDetections.get(detectionId);
if (detection) detection.dismissed = true;
@@ -120,6 +139,7 @@ class MeetingDetectionEngine {
}
handleUserResponse(detectionId, action) {
+ debugLogger.info("User response to detection", { detectionId, action }, "meeting");
if (action === "dismiss") {
const detection = this.activeDetections.get(detectionId);
if (detection) {
@@ -138,6 +158,7 @@ class MeetingDetectionEngine {
}
setPreferences(prefs) {
+ debugLogger.info("Updating detection preferences", prefs, "meeting");
Object.assign(this.preferences, prefs);
if (this.preferences.processDetection) {
@@ -158,11 +179,13 @@ class MeetingDetectionEngine {
}
start() {
+ debugLogger.info("Meeting detection engine started", this.preferences, "meeting");
if (this.preferences.processDetection) this.meetingProcessDetector.start();
if (this.preferences.audioDetection) this.audioActivityDetector.start();
}
stop() {
+ debugLogger.info("Meeting detection engine stopped", {}, "meeting");
this.meetingProcessDetector.stop();
this.audioActivityDetector.stop();
this.activeDetections.clear();
diff --git a/src/helpers/meetingProcessDetector.js b/src/helpers/meetingProcessDetector.js
index 0720d9bf0..7b78f8a5c 100644
--- a/src/helpers/meetingProcessDetector.js
+++ b/src/helpers/meetingProcessDetector.js
@@ -97,7 +97,16 @@ class MeetingProcessDetector extends EventEmitter {
start() {
if (this.pollInterval) return;
- debugLogger.info("Starting meeting process detector", {}, "meeting");
+ const apps = MEETING_APPS[process.platform] || [];
+ debugLogger.info(
+ "Process detector started",
+ {
+ platform: process.platform,
+ appsMonitored: apps.map((a) => a.appName),
+ intervalMs: POLL_INTERVAL_MS,
+ },
+ "meeting"
+ );
this._poll();
this.pollInterval = setInterval(() => this._poll(), POLL_INTERVAL_MS);
}
@@ -113,6 +122,7 @@ class MeetingProcessDetector extends EventEmitter {
dismiss(processKey) {
this.dismissedProcesses.add(processKey);
+ debugLogger.info("Process detection dismissed", { processKey }, "meeting");
}
getDetectedProcesses() {