Skip to content

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

Merge branch 'main' into windows-improv

Gabriel Steinb26c12fffcf5
diff --cc .github/workflows/build-and-notarize.yml
index cb4e14163,bacb9a120..aed4e9e73
--- a/.github/workflows/build-and-notarize.yml
+++ b/.github/workflows/build-and-notarize.yml
@@@ -33,8 -33,26 +33,26 @@@ jobs
- name: Install dependencies
run: npm ci
-
- # macOS code signing setup - industry standard approach
+
+ # Cache Electron downloads
+ - name: Cache Electron
+ uses: actions/cache@v4
+ with:
+ path: |
+ ${{ runner.os == 'Windows' && '~\AppData\Local\electron\Cache' || '~/.cache/electron' }}
+ ${{ runner.os == 'Windows' && '~\AppData\Local\electron-builder\Cache' || '~/.cache/electron-builder' }}
+ key: ${{ runner.os }}-electron-${{ hashFiles('**/package-lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-electron-
+
+ # Linux packaging dependencies (rpm for Fedora/RHEL packages)
+ - name: Install Linux packaging dependencies
+ if: matrix.os == 'ubuntu-latest'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y rpm
+
- # macOS code signing setup - industry standard approach
++ # macOS code signing setup
- name: Setup macOS Code Signing
if: matrix.os == 'macos-latest' && github.event_name != 'pull_request'
env:
diff --cc src/helpers/whisper.js
index 7e02dc8c4,9be9e0e75..224a55141
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@@ -188,173 -163,71 +189,181 @@@ class WhisperManager
return tempAudioPath;
}
+ validateWavHeader(buffer) {
+ try {
+ if (!buffer || buffer.length < 44) {
+ return false;
+ }
+
+ // Check RIFF header
+ const riff = buffer.toString('ascii', 0, 4);
+ if (riff !== 'RIFF') {
+ return false;
+ }
+
+ // Check WAVE format
+ const wave = buffer.toString('ascii', 8, 12);
+ if (wave !== 'WAVE') {
+ return false;
+ }
+
+ // Check fmt subchunk
+ const fmt = buffer.toString('ascii', 12, 16);
+ if (fmt !== 'fmt ') {
+ return false;
+ }
+
+ debugLogger.log('Valid WAV header detected');
+ return true;
+ } catch (error) {
+ debugLogger.error('WAV header validation error:', error.message);
+ return false;
+ }
+ }
+
- async resolveFfmpegPath() {
+ async getFFmpegPath() {
+ if (this.cachedFFmpegPath) {
+ return this.cachedFFmpegPath;
+ }
+
+ let ffmpegPath;
+
try {
- let ffmpegPath = require("ffmpeg-static");
+ ffmpegPath = require("ffmpeg-static");
debugLogger.logFFmpegDebug('Initial ffmpeg-static path', ffmpegPath);
+ // Normalize path separators for cross-platform compatibility
+ ffmpegPath = path.normalize(ffmpegPath);
+
+ // Add Windows .exe extension if missing
if (process.platform === "win32" && !ffmpegPath.endsWith(".exe")) {
ffmpegPath += ".exe";
}
- // Check if path exists
- if (process.env.NODE_ENV !== "development" && !fs.existsSync(ffmpegPath)) {
+ if (fs.existsSync(ffmpegPath)) {
+ // Validate executable permissions (skip on Windows - uses different permission model)
+ if (process.platform !== "win32") {
+ try {
+ fs.accessSync(ffmpegPath, fs.constants.X_OK);
+ } catch (e) {
+ debugLogger.error('FFmpeg exists but is not executable:', e.message);
+ throw new Error('FFmpeg not executable');
+ }
+ }
+ debugLogger.log('Found bundled FFmpeg at:', ffmpegPath);
- return ffmpegPath;
- }
-
- // Production: Handle ASAR unpacking
- if (process.env.NODE_ENV !== "development") {
++ } else if (process.env.NODE_ENV !== "development") {
const possiblePaths = [
- // Direct replacement
- ffmpegPath.replace(/app\.asar([/\\])/, 'app.asar.unpacked$1'),
- ffmpegPath.replace(/app\.asar/g, 'app.asar.unpacked'),
- // Resources folder
- ffmpegPath.replace("app.asar", "app.asar.unpacked"),
++ ffmpegPath.replace(/app\.asar([/\\])/, "app.asar.unpacked$1"),
++ ffmpegPath.replace(/app\.asar/g, "app.asar.unpacked"),
+ ffmpegPath.replace(/.*app\.asar/, path.join(__dirname, "..", "..", "app.asar.unpacked")),
- path.join(process.resourcesPath, "app.asar.unpacked", "node_modules", "ffmpeg-static", process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg")
- ];
+ process.resourcesPath ? path.join(
+ process.resourcesPath,
+ "app.asar.unpacked",
+ "node_modules",
+ "ffmpeg-static",
+ process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg"
+ ) : null,
- // Alternative resources location
+ process.resourcesPath ? path.join(
+ process.resourcesPath,
+ "app.asar.unpacked",
+ "node_modules",
+ "ffmpeg-static",
+ "bin",
+ process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg"
+ ) : null,
+ ].filter(Boolean);
debugLogger.log('FFmpeg not found at primary path, checking alternatives');
for (const possiblePath of possiblePaths) {
- if (fs.existsSync(possiblePath)) {
- ffmpegPath = possiblePath;
- debugLogger.log('FFmpeg found at:', ffmpegPath);
- break;
+ const normalizedPath = path.normalize(possiblePath);
- if (fs.existsSync(normalizedPath)) {
- // Validate on non-Windows platforms
- if (process.platform !== "win32") {
- try {
- fs.accessSync(normalizedPath, fs.constants.X_OK);
- } catch (e) {
- continue;
- }
++ if (!fs.existsSync(normalizedPath)) {
++ continue;
+ }
++ // Validate on non-Windows platforms
++ if (process.platform !== "win32") {
++ try {
++ fs.accessSync(normalizedPath, fs.constants.X_OK);
++ } catch (e) {
++ continue;
+ }
- debugLogger.log('FFmpeg found at:', normalizedPath);
- return normalizedPath;
+ }
++ ffmpegPath = normalizedPath;
++ debugLogger.log('FFmpeg found at:', normalizedPath);
++ break;
}
}
- debugLogger.log('Bundled FFmpeg not found, trying system FFmpeg');
- throw new Error('Bundled FFmpeg not found');
-
- if (!fs.existsSync(ffmpegPath)) {
- debugLogger.error('Bundled FFmpeg not found at:', ffmpegPath);
- throw new Error(`Bundled FFmpeg not found at ${ffmpegPath}`);
++ if (!ffmpegPath || !fs.existsSync(ffmpegPath)) {
++ debugLogger.log('Bundled FFmpeg not found, trying system FFmpeg');
++ throw new Error('Bundled FFmpeg not found');
+ }
+ } catch (bundledError) {
+ debugLogger.log('Bundled FFmpeg error:', bundledError.message);
- try {
- fs.accessSync(ffmpegPath, fs.constants.X_OK);
- debugLogger.log('FFmpeg is executable');
- } catch (e) {
- debugLogger.error('FFmpeg exists but is not executable:', e.message);
- throw new Error(`FFmpeg exists but is not executable: ${ffmpegPath}`);
- }
+ // Try system FFmpeg with enhanced Windows support
+ const systemCandidates = await this.getSystemFfmpegCandidates();
- } catch (e) {
- debugLogger.log('Bundled FFmpeg not available, trying system FFmpeg');
-
- const systemFFmpeg = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
+ for (const candidate of systemCandidates) {
+ try {
+ await runCommand(candidate, ["--version"], { timeout: TIMEOUTS.QUICK_CHECK });
+ debugLogger.log('Using system FFmpeg:', candidate);
- return candidate;
++ ffmpegPath = candidate;
++ break;
+ } catch (error) {
+ continue;
+ }
+ }
- debugLogger.error('No FFmpeg found (bundled or system)');
- return null;
- try {
- const versionResult = await runCommand(systemFFmpeg, ["--version"], { timeout: TIMEOUTS.QUICK_CHECK });
- ffmpegPath = systemFFmpeg;
- debugLogger.log('Using system FFmpeg');
- } catch (systemError) {
- debugLogger.error('System FFmpeg also unavailable:', systemError.message);
- ffmpegPath = systemFFmpeg;
++ if (!ffmpegPath) {
++ debugLogger.error('No FFmpeg found (bundled or system)');
++ return null;
+ }
}
+
+ this.cachedFFmpegPath = ffmpegPath;
+ return ffmpegPath;
}
+ async getSystemFfmpegCandidates() {
+ const candidates = [];
+
+ if (process.platform === "win32") {
+ // Windows-specific paths
+ candidates.push("ffmpeg.exe", "ffmpeg");
+
+ // Common Windows installation directories
+ const commonDirs = [
+ path.join(process.env.ProgramFiles || "C:\\Program Files", "ffmpeg", "bin"),
+ path.join(process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)", "ffmpeg", "bin"),
+ path.join(process.env.LOCALAPPDATA || "", "Programs", "ffmpeg", "bin"),
+ "C:\\ffmpeg\\bin",
+ ];
+
+ for (const dir of commonDirs) {
+ if (dir) {
+ const ffmpegExe = path.join(dir, "ffmpeg.exe");
+ if (fs.existsSync(ffmpegExe)) {
+ candidates.push(ffmpegExe);
+ }
+ }
+ }
+ } else if (process.platform === "darwin") {
+ // macOS-specific paths
+ candidates.push(
+ "ffmpeg",
+ "/opt/homebrew/bin/ffmpeg",
+ "/usr/local/bin/ffmpeg",
+ "/usr/bin/ffmpeg"
+ );
+ } else {
+ // Linux
+ candidates.push("ffmpeg", "/usr/bin/ffmpeg", "/usr/local/bin/ffmpeg");
+ }
+
+ return candidates;
+ }
+
async runWhisperProcess(tempAudioPath, model, language) {
const pythonCmd = await this.findPythonExecutable();
const whisperScriptPath = this.getWhisperScriptPath();
@@@ -370,19 -242,9 +378,23 @@@
}
args.push("--output-format", "json");
-
return new Promise(async (resolve, reject) => {
- // Get FFmpeg path with robust production/development handling
- let ffmpegPath = await this.resolveFfmpegPath();
-
+ const ffmpegPath = await this.getFFmpegPath();
- const absoluteFFmpegPath = path.resolve(ffmpegPath);
+ if (!ffmpegPath) {
+ reject(new Error('FFmpeg not found. Please ensure FFmpeg is installed or bundled correctly.'));
+ return;
+ }
+
- // Enhanced environment setup - Python script checks multiple env vars
- // Make sure to use absolute paths
- const absoluteFFmpegPath = path.resolve(ffmpegPath);
++ let effectiveFfmpegPath = ffmpegPath;
++ if (effectiveFfmpegPath.includes("app.asar") && !effectiveFfmpegPath.includes("app.asar.unpacked")) {
++ const unpackedPath = effectiveFfmpegPath.replace("app.asar", "app.asar.unpacked");
++ if (fs.existsSync(unpackedPath)) {
++ effectiveFfmpegPath = unpackedPath;
++ debugLogger.log('Using unpacked FFmpeg path:', unpackedPath);
++ }
++ }
++
++ const absoluteFFmpegPath = path.resolve(effectiveFfmpegPath);
const enhancedEnv = {
...process.env,
FFMPEG_PATH: absoluteFFmpegPath,
@@@ -904,22 -660,9 +916,18 @@@
try {
const pythonCmd = await this.findPythonExecutable();
const whisperScriptPath = this.getWhisperScriptPath();
-
- // Use the centralized FFmpeg resolver
- const ffmpegPath = await this.resolveFfmpegPath();
-
+ const ffmpegPath = await this.getFFmpegPath();
+ if (!ffmpegPath) {
+ debugLogger.log('FFmpeg not found by resolver');
+ return {
+ available: false,
+ error: "FFmpeg not found"
+ };
+ }
+
+ debugLogger.log('FFmpeg resolved for availability check:', ffmpegPath);
const result = await new Promise((resolve) => {
- // Set up environment with FFmpeg path
const env = {
...process.env,
FFMPEG_PATH: ffmpegPath || "",