Skip to content

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

fix: Windows 11 compatibility - use os.pathsep for PATH separator, platform-appropriate cache dirs, and cross-platform process termination

Gabriel Steine4ccca64a1e8
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index 9c26a8e65..915d09ff7 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -1,5 +1,6 @@
const { clipboard } = require("electron");
const { spawn, spawnSync } = require("child_process");
+const { killProcess } = require("../utils/process");
// Cache TTL constants - these mirror CACHE_CONFIG.AVAILABILITY_CHECK_TTL in src/config/constants.ts
const CACHE_TTL_MS = 30000;
@@ -117,7 +118,7 @@ class ClipboardManager {
const timeoutId = setTimeout(() => {
hasTimedOut = true;
- pasteProcess.kill("SIGKILL");
+ killProcess(pasteProcess, 'SIGKILL');
pasteProcess.removeAllListeners();
const errorMsg =
"Paste operation timed out. Text is copied to clipboard - please paste manually with Cmd+V.";
@@ -295,11 +296,7 @@ class ClipboardManager {
let timedOut = false;
const timeoutId = setTimeout(() => {
timedOut = true;
- try {
- proc.kill("SIGKILL");
- } catch {
- // Ignore kill errors
- }
+ killProcess(proc, 'SIGKILL');
}, 1000);
proc.on("close", (code) => {
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index 58350562e..fbb8a7861 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -6,7 +6,7 @@ const os = require("os");
const path = require("path");
const crypto = require("crypto");
const PythonInstaller = require("./pythonInstaller");
-const { runCommand, TIMEOUTS } = require("../utils/process");
+const { runCommand, killProcess, TIMEOUTS } = require("../utils/process");
const debugLogger = require("./debugLogger");
// Cache TTL - mirrors CACHE_CONFIG.AVAILABILITY_CHECK_TTL in src/config/constants.ts
@@ -631,7 +631,7 @@ class WhisperManager {
// Set timeout for longer recordings
const timeout = setTimeout(() => {
if (!isResolved) {
- whisperProcess.kill("SIGTERM");
+ killProcess(whisperProcess, 'SIGTERM');
reject(new Error("Whisper transcription timed out (20 minutes)"));
}
}, TIMEOUTS.TRANSCRIPTION);
@@ -1381,10 +1381,10 @@ class WhisperManager {
});
const timeout = setTimeout(() => {
- downloadProcess.kill("SIGTERM");
+ killProcess(downloadProcess, 'SIGTERM');
setTimeout(() => {
if (!downloadProcess.killed) {
- downloadProcess.kill("SIGKILL");
+ killProcess(downloadProcess, 'SIGKILL');
}
}, 5000);
reject(new Error("Model download timed out (10 minutes)"));
@@ -1433,13 +1433,13 @@ class WhisperManager {
async cancelDownload() {
if (this.currentDownloadProcess) {
try {
- this.currentDownloadProcess.kill("SIGTERM");
+ killProcess(this.currentDownloadProcess, 'SIGTERM');
setTimeout(() => {
if (
this.currentDownloadProcess &&
!this.currentDownloadProcess.killed
) {
- this.currentDownloadProcess.kill("SIGKILL");
+ killProcess(this.currentDownloadProcess, 'SIGKILL');
}
}, 3000);
return { success: true, message: "Download cancelled" };
diff --git a/src/utils/process.js b/src/utils/process.js
index 6599f3439..39f679ff9 100644
--- a/src/utils/process.js
+++ b/src/utils/process.js
@@ -1,5 +1,32 @@
const { spawn } = require("child_process");
+/**
+ * Cross-platform process termination
+ * Windows doesn't support SIGTERM/SIGKILL signals the same way Unix does
+ * @param {ChildProcess} proc - The process to kill
+ * @param {string} signal - Signal name ('SIGTERM' or 'SIGKILL')
+ */
+function killProcess(proc, signal = 'SIGTERM') {
+ if (!proc || proc.exitCode !== null) return;
+
+ try {
+ if (process.platform === 'win32') {
+ // On Windows, just call kill() without a signal - it terminates the process
+ // For SIGKILL equivalent, we use taskkill /F for forceful termination
+ if (signal === 'SIGKILL') {
+ spawn('taskkill', ['/pid', proc.pid.toString(), '/f', '/t'], { detached: true });
+ } else {
+ proc.kill();
+ }
+ } else {
+ // On Unix-like systems, use the signal as intended
+ proc.kill(signal);
+ }
+ } catch (e) {
+ // Process may already be dead
+ }
+}
+
// Timeout constants
const TIMEOUTS = {
QUICK_CHECK: 5000, // 5 seconds for quick checks
@@ -49,14 +76,14 @@ async function runCommand(cmd, args = [], options = {}) {
validateCommand(cmd, args, shell);
return new Promise((resolve, reject) => {
- let process;
+ let childProc;
let stdout = "";
let stderr = "";
let completed = false;
let timer;
try {
- process = spawn(cmd, args, { shell });
+ childProc = spawn(cmd, args, { shell });
} catch (error) {
reject(error);
return;
@@ -67,19 +94,13 @@ async function runCommand(cmd, args = [], options = {}) {
clearTimeout(timer);
timer = null;
}
- if (process && !completed) {
+ if (childProc && !completed) {
completed = true;
- try {
- process.kill("SIGTERM");
- // Force kill after 5 seconds if still running
- setTimeout(() => {
- if (process.exitCode === null) {
- process.kill("SIGKILL");
- }
- }, 5000);
- } catch (e) {
- // Process already dead
- }
+ killProcess(childProc, 'SIGTERM');
+ // Force kill after 5 seconds if still running
+ setTimeout(() => {
+ killProcess(childProc, 'SIGKILL');
+ }, 5000);
}
};
@@ -88,19 +109,19 @@ async function runCommand(cmd, args = [], options = {}) {
reject(new Error(`Command timed out after ${timeout}ms`));
}, timeout);
- process.stdout.on("data", (data) => {
+ childProc.stdout.on("data", (data) => {
stdout += data.toString();
});
- process.stderr.on("data", (data) => {
+ childProc.stderr.on("data", (data) => {
stderr += data.toString();
});
- process.on("close", (code) => {
+ childProc.on("close", (code) => {
if (completed) return; // Already handled
completed = true;
clearTimeout(timer);
-
+
if (code === 0) {
resolve({ success: true, output: stdout });
} else {
@@ -108,7 +129,7 @@ async function runCommand(cmd, args = [], options = {}) {
}
});
- process.on("error", (error) => {
+ childProc.on("error", (error) => {
if (completed) return; // Already handled
completed = true;
cleanup();
@@ -119,5 +140,6 @@ async function runCommand(cmd, args = [], options = {}) {
module.exports = {
runCommand,
+ killProcess,
TIMEOUTS,
};
\ No newline at end of file
diff --git a/whisper_bridge.py b/whisper_bridge.py
index 3c00537de..e2d9205fe 100755
--- a/whisper_bridge.py
+++ b/whisper_bridge.py
@@ -16,6 +16,20 @@ import time
import requests
import gc
+def get_whisper_cache_dir():
+ """Get platform-appropriate cache directory for Whisper models"""
+ if sys.platform == "win32":
+ # Windows: use %LOCALAPPDATA%\whisper or fallback to %USERPROFILE%\.cache\whisper
+ local_app_data = os.environ.get("LOCALAPPDATA")
+ if local_app_data:
+ return os.path.join(local_app_data, "whisper")
+ # Fallback to user profile
+ user_profile = os.environ.get("USERPROFILE", os.path.expanduser("~"))
+ return os.path.join(user_profile, ".cache", "whisper")
+ else:
+ # macOS/Linux: use ~/.cache/whisper
+ return get_whisper_cache_dir()
+
def get_ffmpeg_path():
"""Get path to bundled FFmpeg executable with proper production support"""
# Check environment variables first
@@ -100,7 +114,7 @@ if ffmpeg_path:
ffmpeg_dir = os.path.dirname(os.path.abspath(ffmpeg_path))
current_path = os.environ.get("PATH", "")
if ffmpeg_dir not in current_path:
- os.environ["PATH"] = f"{ffmpeg_dir}:{current_path}"
+ os.environ["PATH"] = f"{ffmpeg_dir}{os.pathsep}{current_path}"
# For Whisper library, we need to ensure 'ffmpeg' command works
# Create a symlink if needed (for macOS/Linux)
@@ -160,7 +174,7 @@ def get_expected_model_size(model_name):
def monitor_download_progress(model_name, expected_size, stop_event):
"""Monitor download progress by watching file size growth"""
- cache_dir = os.path.expanduser("~/.cache/whisper")
+ cache_dir = get_whisper_cache_dir()
model_url = whisper._MODELS[model_name]
model_file = os.path.join(cache_dir, os.path.basename(model_url))
@@ -229,7 +243,7 @@ def download_model(model_name="base"):
try:
# Check if model is already downloaded
- cache_dir = os.path.expanduser("~/.cache/whisper")
+ cache_dir = get_whisper_cache_dir()
model_url = whisper._MODELS[model_name]
model_file = os.path.join(cache_dir, os.path.basename(model_url))
@@ -309,7 +323,7 @@ def download_model(model_name="base"):
def check_model_status(model_name="base"):
"""Check if a model is already downloaded"""
try:
- cache_dir = os.path.expanduser("~/.cache/whisper")
+ cache_dir = get_whisper_cache_dir()
model_url = whisper._MODELS[model_name]
model_file = os.path.join(cache_dir, os.path.basename(model_url))
@@ -347,14 +361,14 @@ def list_models():
return {
"models": model_info,
- "cache_dir": os.path.expanduser("~/.cache/whisper"),
+ "cache_dir": get_whisper_cache_dir(),
"success": True
}
def delete_model(model_name="base"):
"""Delete a downloaded Whisper model"""
try:
- cache_dir = os.path.expanduser("~/.cache/whisper")
+ cache_dir = get_whisper_cache_dir()
model_url = whisper._MODELS[model_name]
model_file = os.path.join(cache_dir, os.path.basename(model_url))