Skip to content

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

feat: WebSocket streaming for BYOK + fix blocking execSync in meeting detection

Gabriel Stein27542f54e5b4
diff --git a/src/helpers/audioActivityDetector.js b/src/helpers/audioActivityDetector.js
index a69835b28..1699dc358 100644
--- a/src/helpers/audioActivityDetector.js
+++ b/src/helpers/audioActivityDetector.js
@@ -1,13 +1,19 @@
-const { execSync, execFileSync } = require("child_process");
+const { exec, execFile } = require("child_process");
+const { promisify } = require("util");
const path = require("path");
const fs = require("fs");
const EventEmitter = require("events");
const debugLogger = require("./debugLogger");
-const CHECK_INTERVAL_MS = 5 * 1000;
-const SUSTAINED_THRESHOLD_CHECKS = 3;
+const execAsync = promisify(exec);
+const execFileAsync = promisify(execFile);
+
+// Windows uses tasklist (process spawn) which is heavier than macOS native binary / Linux pactl,
+// so poll less frequently to avoid input pipeline stalls from repeated process spawning.
+const CHECK_INTERVAL_MS = process.platform === "win32" ? 15 * 1000 : 5 * 1000;
+const SUSTAINED_THRESHOLD_CHECKS = process.platform === "win32" ? 2 : 3;
const COOLDOWN_MS = 30 * 60 * 1000;
-const EXEC_OPTS = { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] };
+const EXEC_OPTS = { timeout: 5000, encoding: "utf8" };
class AudioActivityDetector extends EventEmitter {
constructor() {
@@ -19,6 +25,7 @@ class AudioActivityDetector extends EventEmitter {
this.lastDismissedAt = null;
this._micCheckBinary = null;
this._userRecording = false;
+ this._checking = false;
}
setUserRecording(active) {
@@ -67,47 +74,53 @@ class AudioActivityDetector extends EventEmitter {
this.hasPrompted = false;
}
- _check() {
+ async _check() {
+ if (this._checking) return;
if (this.lastDismissedAt && Date.now() - this.lastDismissedAt < COOLDOWN_MS) return;
if (this.hasPrompted) return;
if (this._userRecording) return;
- const active = this._isMicActive();
- debugLogger.debug(
- "Mic check",
- { active, consecutiveChecks: this.consecutiveChecks },
- "meeting"
- );
+ this._checking = true;
+ try {
+ const active = await 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 },
- "meeting"
- );
- this.emit("sustained-audio-detected", { durationMs, detectedAt: now });
- }
- } else {
- if (this.consecutiveChecks > 0) {
- debugLogger.debug(
- "Mic activity reset",
- { previousChecks: 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 },
+ "meeting"
+ );
+ 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;
}
- this.consecutiveChecks = 0;
- this.audioActiveStart = null;
+ } finally {
+ this._checking = false;
}
}
- _isMicActive() {
+ async _isMicActive() {
switch (process.platform) {
case "darwin":
return this._checkDarwin();
@@ -151,11 +164,14 @@ class AudioActivityDetector extends EventEmitter {
debugLogger.warn("macos-mic-check binary not found, falling back to ioreg", {}, "meeting");
}
- _checkDarwin() {
+ async _checkDarwin() {
if (this._micCheckBinary) {
try {
- const out = execFileSync(this._micCheckBinary, [], { timeout: 3000, encoding: "utf8" });
- return out.trim() === "true";
+ const { stdout } = await execFileAsync(this._micCheckBinary, [], {
+ timeout: 3000,
+ encoding: "utf8",
+ });
+ return stdout.trim() === "true";
} catch (err) {
debugLogger.debug(
"mic-check binary failed, falling back",
@@ -166,36 +182,48 @@ class AudioActivityDetector extends EventEmitter {
}
try {
- const out = execSync("ioreg -l -w 0 | grep '\"IOAudioEngineState\" = 1'", EXEC_OPTS);
- return out.trim().length > 0;
+ const { stdout } = await execAsync(
+ "ioreg -l -w 0 | grep '\"IOAudioEngineState\" = 1'",
+ EXEC_OPTS
+ );
+ return stdout.trim().length > 0;
} catch {
return false;
}
}
- _checkWin32() {
+ async _checkWin32() {
+ // Use tasklist instead of PowerShell to avoid expensive .NET runtime startup
+ // that causes system-wide input stalls (mouse freezes) every poll cycle.
+ // Note: tasklist /FI uses AND logic for multiple filters, so we use a single
+ // unfiltered call and check the output for any matching process name.
try {
- const out = execSync(
- "powershell -NoProfile -Command \"(Get-Process -Name 'CptHost','ms-teams_modulehost','webexmeetingsapp' -ErrorAction SilentlyContinue).Count -gt 0\"",
- EXEC_OPTS
+ const { stdout } = await execAsync("tasklist /NH /FO CSV", EXEC_OPTS);
+ const lower = stdout.toLowerCase();
+ return (
+ lower.includes('"cpthost.exe"') ||
+ lower.includes('"ms-teams_modulehost.exe"') ||
+ lower.includes('"webexmeetingsapp.exe"')
);
- return out.trim() === "True";
} catch {
return false;
}
}
- _checkLinux() {
+ async _checkLinux() {
try {
- const out = execSync("pactl list source-outputs short", EXEC_OPTS);
- return out.trim().length > 0;
+ const { stdout } = await execAsync("pactl list source-outputs short", EXEC_OPTS);
+ return stdout.trim().length > 0;
} catch {
// pactl unavailable, try PipeWire
}
try {
- const out = execSync("pw-cli list-objects | grep -c 'Stream/Input/Audio'", EXEC_OPTS);
- return parseInt(out.trim(), 10) > 0;
+ const { stdout } = await execAsync(
+ "pw-cli list-objects | grep -c 'Stream/Input/Audio'",
+ EXEC_OPTS
+ );
+ return parseInt(stdout.trim(), 10) > 0;
} catch {
return false;
}
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 53f3d571a..09293c12c 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -2211,6 +2211,12 @@ class IPCHandlers {
};
const fetchRealtimeToken = async (event, options) => {
+ if (options.mode === "byok") {
+ const apiKey = this.environmentManager.getOpenAIKey();
+ if (!apiKey) throw new Error("No OpenAI API key configured. Add your key in Settings.");
+ return apiKey;
+ }
+
const apiUrl = getApiUrl();
if (!apiUrl) throw new Error("OpenWhispr API URL not configured");
diff --git a/src/helpers/mediaPlayer.js b/src/helpers/mediaPlayer.js
index f307552e0..a88b1c680 100644
--- a/src/helpers/mediaPlayer.js
+++ b/src/helpers/mediaPlayer.js
@@ -502,11 +502,10 @@ try {
Write-Output 'UNKNOWN'
}`.trim();
- const result = spawnSync(
- "powershell",
- ["-NoProfile", "-NonInteractive", "-Command", script],
- { stdio: "pipe", timeout: 5000 }
- );
+ const result = spawnSync("powershell", ["-NoProfile", "-NonInteractive", "-Command", script], {
+ stdio: "pipe",
+ timeout: 5000,
+ });
if (result.status === 0) {
const output = (result.stdout?.toString() || "").trim();
@@ -570,7 +569,11 @@ try {
this._didPause = false;
const isPlaying = this._isWindowsAudioPlaying();
if (isPlaying === false) {
- debugLogger.debug("No audio playing, skipping media key to avoid starting playback", {}, "media");
+ debugLogger.debug(
+ "No audio playing, skipping media key to avoid starting playback",
+ {},
+ "media"
+ );
return false;
}
if (isPlaying === null) {
diff --git a/src/helpers/meetingProcessDetector.js b/src/helpers/meetingProcessDetector.js
index 7b78f8a5c..d52f4c1b6 100644
--- a/src/helpers/meetingProcessDetector.js
+++ b/src/helpers/meetingProcessDetector.js
@@ -1,98 +1,83 @@
-const { execSync } = require("child_process");
+const { exec } = require("child_process");
+const { promisify } = require("util");
const EventEmitter = require("events");
const debugLogger = require("./debugLogger");
-const POLL_INTERVAL_MS = 20 * 1000;
-const EXEC_OPTS = { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] };
+const execAsync = promisify(exec);
-const MEETING_APPS = {
- darwin: [
- { processKey: "zoom", appName: "Zoom", check: () => hasProcessExact("CptHost") },
- {
- processKey: "teams",
- appName: "Microsoft Teams",
- check: () => hasProcess("MSTeams") && hasActiveAudio("MSTeams"),
- },
- {
- processKey: "facetime",
- appName: "FaceTime",
- check: () => hasProcessExact("FaceTime") && hasActiveAudio("FaceTime"),
- },
- { processKey: "webex", appName: "Webex", check: () => hasProcess("webexmeetingsapp") },
- ],
- win32: [
- {
- processKey: "zoom",
- appName: "Zoom",
- check: () => {
- const out = execSync('tasklist /FI "IMAGENAME eq CptHost.exe" /NH', EXEC_OPTS);
- return out.includes("CptHost");
- },
- },
- {
- processKey: "teams",
- appName: "Microsoft Teams",
- check: () => {
- const out = execSync(
- "powershell -NoProfile -Command \"(Get-Process -Name 'ms-teams_modulehost' -ErrorAction SilentlyContinue).Count -gt 0\"",
- EXEC_OPTS
- );
- return out.trim() === "True";
- },
- },
- {
- processKey: "webex",
- appName: "Webex",
- check: () => {
- const out = execSync('tasklist /FI "IMAGENAME eq webexmeetingsapp.exe" /NH', EXEC_OPTS);
- return out.includes("webexmeetingsapp");
- },
- },
- ],
- linux: [
- { processKey: "zoom", appName: "Zoom", check: () => hasProcess("zoom") },
- { processKey: "teams", appName: "Microsoft Teams", check: () => hasProcess("teams") },
- ],
-};
+const POLL_INTERVAL_MS = 20 * 1000;
+const EXEC_OPTS = { timeout: 3000, encoding: "utf8" };
-function hasProcess(name) {
+async function hasProcess(name) {
try {
if (process.platform === "win32") {
- const out = execSync(`tasklist | findstr /I "${name}"`, EXEC_OPTS);
- return out.trim().length > 0;
+ const { stdout } = await execAsync(`tasklist | findstr /I "${name}"`, EXEC_OPTS);
+ return stdout.trim().length > 0;
}
- execSync(`pgrep -f "${name}"`, EXEC_OPTS);
+ await execAsync(`pgrep -f "${name}"`, EXEC_OPTS);
return true;
} catch {
return false;
}
}
-function hasProcessExact(name) {
+async function hasProcessExact(name) {
try {
- execSync(`pgrep -x "${name}"`, EXEC_OPTS);
+ await execAsync(`pgrep -x "${name}"`, EXEC_OPTS);
return true;
} catch {
return false;
}
}
-function hasActiveAudio(appName) {
+async function hasActiveAudio(appName) {
if (process.platform !== "darwin") return true;
try {
- const out = execSync(`lsof -c "${appName}" 2>/dev/null | grep -i coreaudio`, EXEC_OPTS);
- return out.trim().length > 0;
+ const { stdout } = await execAsync(
+ `lsof -c "${appName}" 2>/dev/null | grep -i coreaudio`,
+ EXEC_OPTS
+ );
+ return stdout.trim().length > 0;
} catch {
return false;
}
}
+const MEETING_APPS = {
+ darwin: [
+ { processKey: "zoom", appName: "Zoom", check: () => hasProcessExact("CptHost") },
+ {
+ processKey: "teams",
+ appName: "Microsoft Teams",
+ check: async () => (await hasProcess("MSTeams")) && (await hasActiveAudio("MSTeams")),
+ },
+ {
+ processKey: "facetime",
+ appName: "FaceTime",
+ check: async () => (await hasProcessExact("FaceTime")) && (await hasActiveAudio("FaceTime")),
+ },
+ { processKey: "webex", appName: "Webex", check: () => hasProcess("webexmeetingsapp") },
+ ],
+ // Windows: uses a single tasklist call in _pollWin32() instead of per-app checks
+ // to minimize process spawning and avoid input pipeline stalls (mouse freezes).
+ win32: [
+ { processKey: "zoom", appName: "Zoom", imageName: "cpthost.exe" },
+ { processKey: "teams", appName: "Microsoft Teams", imageName: "ms-teams_modulehost.exe" },
+ { processKey: "webex", appName: "Webex", imageName: "webexmeetingsapp.exe" },
+ ],
+ linux: [
+ { processKey: "zoom", appName: "Zoom", check: () => hasProcess("zoom") },
+ { processKey: "teams", appName: "Microsoft Teams", check: () => hasProcess("teams") },
+ ],
+};
+
class MeetingProcessDetector extends EventEmitter {
constructor() {
super();
this.pollInterval = null;
this.detectedProcesses = new Map();
this.dismissedProcesses = new Set();
+ this._polling = false;
}
start() {
@@ -139,33 +124,68 @@ class MeetingProcessDetector extends EventEmitter {
return entry ? entry.appName : processKey;
}
- _poll() {
+ async _poll() {
+ if (this._polling) return;
+ this._polling = true;
try {
- const apps = MEETING_APPS[process.platform] || [];
-
- for (const { processKey, appName, check } of apps) {
- let isRunning = false;
- try {
- isRunning = check();
- } catch {
- isRunning = false;
- }
-
- if (isRunning) {
- if (!this.detectedProcesses.has(processKey) && !this.dismissedProcesses.has(processKey)) {
- const detectedAt = Date.now();
- this.detectedProcesses.set(processKey, { detectedAt });
- debugLogger.info("Meeting process detected", { processKey, appName }, "meeting");
- this.emit("meeting-process-detected", { processKey, appName, detectedAt });
- }
- } else if (this.detectedProcesses.has(processKey)) {
- this.detectedProcesses.delete(processKey);
- debugLogger.info("Meeting process ended", { processKey, appName }, "meeting");
- this.emit("meeting-process-ended", { processKey, appName });
- }
+ if (process.platform === "win32") {
+ await this._pollWin32();
+ } else {
+ await this._pollDefault();
}
} catch (err) {
debugLogger.warn("Poll error", { error: err.message }, "meeting");
+ } finally {
+ this._polling = false;
+ }
+ }
+
+ /**
+ * Windows: single tasklist call to check all meeting processes at once,
+ * avoiding multiple process spawns that cause input pipeline stalls.
+ */
+ async _pollWin32() {
+ const apps = MEETING_APPS.win32 || [];
+ let tasklistOutput = "";
+ try {
+ const { stdout } = await execAsync("tasklist /NH /FO CSV", EXEC_OPTS);
+ tasklistOutput = stdout.toLowerCase();
+ } catch {
+ return;
+ }
+
+ for (const { processKey, appName, imageName } of apps) {
+ const isRunning = tasklistOutput.includes(`"${imageName}"`);
+ this._updateDetection(processKey, appName, isRunning);
+ }
+ }
+
+ async _pollDefault() {
+ const apps = MEETING_APPS[process.platform] || [];
+
+ for (const { processKey, appName, check } of apps) {
+ let isRunning = false;
+ try {
+ isRunning = await check();
+ } catch {
+ isRunning = false;
+ }
+ this._updateDetection(processKey, appName, isRunning);
+ }
+ }
+
+ _updateDetection(processKey, appName, isRunning) {
+ if (isRunning) {
+ if (!this.detectedProcesses.has(processKey) && !this.dismissedProcesses.has(processKey)) {
+ const detectedAt = Date.now();
+ this.detectedProcesses.set(processKey, { detectedAt });
+ debugLogger.info("Meeting process detected", { processKey, appName }, "meeting");
+ this.emit("meeting-process-detected", { processKey, appName, detectedAt });
+ }
+ } else if (this.detectedProcesses.has(processKey)) {
+ this.detectedProcesses.delete(processKey);
+ debugLogger.info("Meeting process ended", { processKey, appName }, "meeting");
+ this.emit("meeting-process-ended", { processKey, appName });
}
}
}
diff --git a/src/hooks/useMeetingTranscription.ts b/src/hooks/useMeetingTranscription.ts
index aa69d70a3..872f4fbd8 100644
--- a/src/hooks/useMeetingTranscription.ts
+++ b/src/hooks/useMeetingTranscription.ts
@@ -16,6 +16,17 @@ interface UseMeetingTranscriptionReturn {
const MEETING_AUDIO_BUFFER_SIZE = 800;
const MEETING_STOP_FLUSH_TIMEOUT_MS = 50;
+const REALTIME_MODELS = new Set(["gpt-4o-mini-transcribe", "gpt-4o-transcribe"]);
+
+const getMeetingTranscriptionOptions = () => {
+ const { cloudTranscriptionMode, cloudTranscriptionModel, openaiApiKey } = getSettings();
+ const model = REALTIME_MODELS.has(cloudTranscriptionModel)
+ ? cloudTranscriptionModel
+ : "gpt-4o-mini-transcribe";
+ const mode = cloudTranscriptionMode === "byok" && !!openaiApiKey ? "byok" : "openwhispr";
+ return { provider: "openai-realtime" as const, model, mode };
+};
+
const getMeetingWorkletBlobUrl = (() => {
let blobUrl: string | null = null;
@@ -325,10 +336,9 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
const promise = (async () => {
try {
- const result = await window.electronAPI?.meetingTranscriptionPrepare?.({
- provider: "openai-realtime",
- model: "gpt-4o-mini-transcribe",
- });
+ const result = await window.electronAPI?.meetingTranscriptionPrepare?.(
+ getMeetingTranscriptionOptions()
+ );
if (result?.success) {
isPreparedRef.current = true;
@@ -378,10 +388,7 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
const startTime = performance.now();
const [startResult, stream, micResult] = await Promise.all([
- window.electronAPI?.meetingTranscriptionStart?.({
- provider: "openai-realtime",
- model: "gpt-4o-mini-transcribe",
- }),
+ window.electronAPI?.meetingTranscriptionStart?.(getMeetingTranscriptionOptions()),
getSystemAudioStream(),
getMeetingMicConstraints().then((constraints) =>
navigator.mediaDevices.getUserMedia(constraints).catch((err) => {