Skip to content

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

fix: better path resolution + error handling

Gabriel Stein81eafb1cf2f8
diff --git a/package.json b/package.json
index b3105018e..eb59cc6c2 100644
--- a/package.json
+++ b/package.json
@@ -13,20 +13,20 @@
"predev:main": "npm run compile:globe",
"dev:main": "cross-env NODE_ENV=development electron . --dev",
"dev:renderer": "cd src && vite",
- "prebuild": "npm run compile:globe",
+ "prebuild": "npm run compile:globe && npm run download:whisper-cpp",
"build": "cd src && vite build && cd .. && electron-builder",
"postinstall": "electron-builder install-app-deps",
"build:renderer": "cd src && vite build",
- "prebuild:mac": "npm run compile:globe",
+ "prebuild:mac": "npm run compile:globe && npm run download:whisper-cpp",
"build:mac": "npm run build:renderer && electron-builder --mac",
- "prebuild:win": "npm run compile:globe",
+ "prebuild:win": "npm run compile:globe && npm run download:whisper-cpp",
"build:win": "npm run build:renderer && electron-builder --win",
- "prebuild:linux": "npm run compile:globe",
+ "prebuild:linux": "npm run compile:globe && npm run download:whisper-cpp",
"build:linux": "npm run build:renderer && electron-builder --linux",
"setup": "node setup.js",
- "prepack": "npm run compile:globe",
+ "prepack": "npm run compile:globe && npm run download:whisper-cpp",
"pack": "npm run build:renderer && CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --dir",
- "predist": "npm run compile:globe",
+ "predist": "npm run compile:globe && npm run download:whisper-cpp",
"dist": "npm run build:renderer && electron-builder",
"download:whisper-cpp": "node scripts/download-whisper-cpp.js",
"format:js": "eslint . --fix && cd src && eslint . --fix && prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
diff --git a/preload.js b/preload.js
index 5fac2d7d7..54326a486 100644
--- a/preload.js
+++ b/preload.js
@@ -87,6 +87,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
cancelWhisperDownload: () => ipcRenderer.invoke("cancel-whisper-download"),
checkFFmpegAvailability: () =>
ipcRenderer.invoke("check-ffmpeg-availability"),
+ getAudioDiagnostics: () => ipcRenderer.invoke("get-audio-diagnostics"),
// Whisper server functions (faster repeated transcriptions)
whisperServerStart: (modelName) =>
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 415fd90df..900868554 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -297,7 +297,7 @@ class AudioManager {
});
throw new Error("No audio detected");
} else {
- throw new Error(result.error || "Local Whisper transcription failed");
+ throw new Error(result.message || result.error || "Local Whisper transcription failed");
}
} catch (error) {
if (error.message === "No audio detected") {
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index e221f73f7..b7558e8cd 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -172,6 +172,54 @@ class IPCHandlers {
return result;
} catch (error) {
debugLogger.error("Local Whisper transcription error", error);
+ const errorMessage = error.message || "Unknown error";
+
+ // Return specific error types for better user feedback
+ if (errorMessage.includes("FFmpeg not found")) {
+ return {
+ success: false,
+ error: "ffmpeg_not_found",
+ message: "FFmpeg is missing. Please reinstall the app or install FFmpeg manually.",
+ };
+ }
+ if (
+ errorMessage.includes("FFmpeg conversion failed") ||
+ errorMessage.includes("FFmpeg process error")
+ ) {
+ return {
+ success: false,
+ error: "ffmpeg_error",
+ message: "Audio conversion failed. The recording may be corrupted.",
+ };
+ }
+ if (
+ errorMessage.includes("whisper.cpp not found") ||
+ errorMessage.includes("whisper-cpp")
+ ) {
+ return {
+ success: false,
+ error: "whisper_not_found",
+ message: "Whisper binary is missing. Please reinstall the app.",
+ };
+ }
+ if (
+ errorMessage.includes("Audio buffer is empty") ||
+ errorMessage.includes("Audio data too small")
+ ) {
+ return {
+ success: false,
+ error: "no_audio_data",
+ message: "No audio was recorded. Check your microphone settings.",
+ };
+ }
+ if (errorMessage.includes("model") && errorMessage.includes("not downloaded")) {
+ return {
+ success: false,
+ error: "model_not_found",
+ message: errorMessage,
+ };
+ }
+
throw error;
}
});
@@ -180,6 +228,10 @@ class IPCHandlers {
return this.whisperManager.checkWhisperInstallation();
});
+ ipcMain.handle("get-audio-diagnostics", async () => {
+ return this.whisperManager.getDiagnostics();
+ });
+
ipcMain.handle("download-whisper-model", async (event, modelName) => {
try {
const result = await this.whisperManager.downloadWhisperModel(modelName, (progressData) => {
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index a016f52eb..89effb4ba 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -1109,12 +1109,35 @@ class WhisperManager {
ffmpegPath += ".exe";
}
+ debugLogger.debug("FFmpeg static path from module", { ffmpegPath });
+
// Try unpacked ASAR path first (production builds unpack ffmpeg-static)
- const unpackedPath = ffmpegPath.replace(/app\.asar([/\\])/, "app.asar.unpacked$1");
- if (fs.existsSync(unpackedPath)) {
- debugLogger.debug("Found FFmpeg in unpacked ASAR", { path: unpackedPath });
- this.cachedFFmpegPath = unpackedPath;
- return unpackedPath;
+ // Handle both forward slashes and backslashes for cross-platform compatibility
+ const unpackedPath = ffmpegPath.includes("app.asar")
+ ? ffmpegPath.replace(/app\.asar(?=[/\\])/, "app.asar.unpacked")
+ : null;
+
+ if (unpackedPath) {
+ debugLogger.debug("Checking unpacked ASAR path", { unpackedPath });
+ if (fs.existsSync(unpackedPath)) {
+ if (process.platform !== "win32") {
+ try {
+ fs.accessSync(unpackedPath, fs.constants.X_OK);
+ } catch {
+ debugLogger.debug("FFmpeg not executable, attempting chmod", { unpackedPath });
+ try {
+ fs.chmodSync(unpackedPath, 0o755);
+ } catch (chmodErr) {
+ debugLogger.warn("Failed to chmod FFmpeg", { error: chmodErr.message });
+ }
+ }
+ }
+ debugLogger.debug("Found FFmpeg in unpacked ASAR", { path: unpackedPath });
+ this.cachedFFmpegPath = unpackedPath;
+ return unpackedPath;
+ } else {
+ debugLogger.warn("Unpacked ASAR path does not exist", { unpackedPath });
+ }
}
// Try original path (development or if not in ASAR)
@@ -1125,20 +1148,27 @@ class WhisperManager {
debugLogger.debug("Found FFmpeg at bundled path", { path: ffmpegPath });
this.cachedFFmpegPath = ffmpegPath;
return ffmpegPath;
+ } else {
+ debugLogger.warn("Bundled FFmpeg path does not exist", { ffmpegPath });
}
- } catch {
- // Bundled FFmpeg not available
+ } catch (err) {
+ debugLogger.warn("Bundled FFmpeg not available", { error: err.message });
}
// Try system FFmpeg
const systemCandidates =
process.platform === "darwin"
? ["ffmpeg", "/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg"]
- : ["ffmpeg", "/usr/bin/ffmpeg", "/usr/local/bin/ffmpeg"];
+ : process.platform === "win32"
+ ? ["ffmpeg", "C:\\ffmpeg\\bin\\ffmpeg.exe"]
+ : ["ffmpeg", "/usr/bin/ffmpeg", "/usr/local/bin/ffmpeg"];
+
+ debugLogger.debug("Trying system FFmpeg candidates", { candidates: systemCandidates });
for (const candidate of systemCandidates) {
try {
await runCommand(candidate, ["-version"], { timeout: TIMEOUTS.QUICK_CHECK });
+ debugLogger.debug("Found system FFmpeg", { path: candidate });
this.cachedFFmpegPath = candidate;
return candidate;
} catch {
@@ -1146,6 +1176,7 @@ class WhisperManager {
}
}
+ debugLogger.error("FFmpeg not found anywhere");
return null;
}
@@ -1166,6 +1197,70 @@ class WhisperManager {
this.ffmpegAvailabilityCache = { result, expiresAt: now + CACHE_TTL_MS };
return result;
}
+
+ async getDiagnostics() {
+ const diagnostics = {
+ platform: process.platform,
+ arch: process.arch,
+ resourcesPath: process.resourcesPath || null,
+ isPackaged: !!process.resourcesPath && !process.resourcesPath.includes("node_modules"),
+ ffmpeg: { available: false, path: null, error: null },
+ whisperBinary: { available: false, path: null, error: null },
+ whisperServer: { available: false, path: null },
+ modelsDir: this.getModelsDir(),
+ models: [],
+ };
+
+ // Check FFmpeg
+ try {
+ this.cachedFFmpegPath = null; // Clear cache for fresh check
+ const ffmpegPath = await this.getFFmpegPath();
+ if (ffmpegPath) {
+ diagnostics.ffmpeg = { available: true, path: ffmpegPath, error: null };
+ } else {
+ diagnostics.ffmpeg = { available: false, path: null, error: "Not found" };
+ }
+ } catch (err) {
+ diagnostics.ffmpeg = { available: false, path: null, error: err.message };
+ }
+
+ // Check whisper binary
+ try {
+ this.cachedBinaryPath = null; // Clear cache for fresh check
+ const whisperPath = await this.getWhisperBinaryPath();
+ if (whisperPath) {
+ diagnostics.whisperBinary = { available: true, path: whisperPath, error: null };
+ } else {
+ diagnostics.whisperBinary = { available: false, path: null, error: "Not found" };
+ }
+ } catch (err) {
+ diagnostics.whisperBinary = { available: false, path: null, error: err.message };
+ }
+
+ // Check whisper server
+ if (this.serverManager) {
+ const serverPath = this.serverManager.getBinaryPath?.();
+ diagnostics.whisperServer = {
+ available: !!serverPath && fs.existsSync(serverPath),
+ path: serverPath || null,
+ };
+ }
+
+ // Check downloaded models
+ try {
+ const modelsDir = this.getModelsDir();
+ if (fs.existsSync(modelsDir)) {
+ const files = fs.readdirSync(modelsDir);
+ diagnostics.models = files
+ .filter((f) => f.startsWith("ggml-") && f.endsWith(".bin"))
+ .map((f) => f.replace("ggml-", "").replace(".bin", ""));
+ }
+ } catch {
+ // Ignore errors reading models dir
+ }
+
+ return diagnostics;
+ }
}
module.exports = WhisperManager;