Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix: checks correct path for llamacpp installation
Gabriel Steinbe01bf04a54a
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 16ed9f2a6..fe5e3474e 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -169,7 +169,12 @@ export default function SettingsPage({};const saveReasoningSettings = useCallback(() => {- updateReasoningSettings({ useReasoningModel, reasoningModel });+ // Update reasoning settings+ updateReasoningSettings({+ useReasoningModel,+ reasoningModel+ });+updateApiKeys({...(localReasoningProvider === "openai" &&openaiApiKey.trim() && { openaiApiKey }),diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 398d4575a..f3c76f958 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -135,15 +135,8 @@ class AudioManager {}static cleanTranscriptionForAPI(text) {- return TextCleanup.cleanTranscription(text, {- removeArtifacts: true,- normalizeSpaces: true,- fixPunctuation: false, // Let reasoning model handle this- removeFillers: false, // Preserve context for reasoning model- removeRepetitions: false, // Let reasoning model decide- capitalizeFirst: false, // Let reasoning model handle- addPeriod: false,- });+ // Minimal cleanup - only normalize spaces for API processing+ return TextCleanup.normalizeSpaces(text);}async processWithLocalWhisper(audioBlob, model = "base") {@@ -176,7 +169,7 @@ class AudioManager {if (result.success && result.text) {- let text = AudioManager.cleanTranscription(result.text);+ const text = await this.processTranscription(result.text, "local");if (text) {return { success: true, text, source: "local" };} else {@@ -363,24 +356,38 @@ class AudioManager {}async processWithReasoningModel(text) {+ const model = localStorage.getItem("reasoningModel") || "gpt-3.5-turbo";+ return await ReasoningService.processText(text, model);+ }++ async isReasoningAvailable() {+ const useReasoning = localStorage.getItem("useReasoningModel") === "true";+ if (!useReasoning) return false;+try {- const model = localStorage.getItem("reasoningModel") || "gpt-3.5-turbo";- console.log(`Processing with reasoning model: ${model}`);-- const result = await ReasoningService.processText(text, model);- console.log(`Reasoning model processing successful`);- return result;- } catch (error) {- console.error(`Reasoning model processing failed: ${error.message}`);-- // If it's a local model error, provide more helpful information- if (error.message.includes("llama.cpp") || error.message.includes("Local reasoning")) {- console.error("Local AI error - make sure llama.cpp is installed and the model is downloaded");+ return await ReasoningService.isAvailable();+ } catch {+ return false;+ }+ }++ async processTranscription(text, source) {+ // Check if reasoning should handle cleanup+ const useReasoning = await this.isReasoningAvailable();++ if (useReasoning) {+ try {+ // Minimal cleanup for reasoning models+ const preparedText = AudioManager.cleanTranscriptionForAPI(text);+ return await this.processWithReasoningModel(preparedText);+ } catch (error) {+ console.error(`Reasoning failed (${source}):`, error.message);+ // Fall back to standard cleanup}-- // Fall back to basic cleaning- return AudioManager.cleanTranscription(text);}++ // Standard cleanup when reasoning is unavailable or fails+ return AudioManager.cleanTranscription(text);}async processWithOpenAIAPI(audioBlob) {@@ -418,24 +425,11 @@ class AudioManager {}const result = await response.json();- const rawText = AudioManager.cleanTranscriptionForAPI(result.text);-- if (rawText) {- // Apply reasoning model if enabled- const useReasoning =- localStorage.getItem("useReasoningModel") === "true";-- if (useReasoning) {- const reasonedText = await this.processWithReasoningModel(rawText);- return {- success: true,- text: reasonedText,- source: "openai-reasoned",- };- } else {- const finalText = AudioManager.cleanTranscription(rawText);- return { success: true, text: finalText, source: "openai" };- }++ if (result.text) {+ const text = await this.processTranscription(result.text, "openai");+ const source = await this.isReasoningAvailable() ? "openai-reasoned" : "openai";+ return { success: true, text, source };} else {throw new Error("No text transcribed");}@@ -465,7 +459,7 @@ class AudioManager {);if (result.success && result.text) {- let text = AudioManager.cleanTranscription(result.text);+ const text = await this.processTranscription(result.text, "local-fallback");if (text) {return { success: true, text, source: "local-fallback" };}diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 38daf4e18..65db31b59 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -393,8 +393,7 @@ class IPCHandlers {ipcMain.handle("llama-cpp-check", async () => {try {const llamaCppInstaller = require("./llamaCppInstaller").default;- const isInstalled = await llamaCppInstaller.isInstalled() ||- await llamaCppInstaller.checkSystemInstallation();+ const isInstalled = await llamaCppInstaller.isInstalled();const version = isInstalled ? await llamaCppInstaller.getVersion() : null;return { isInstalled, version };} catch (error) {diff --git a/src/helpers/llamaCppInstaller.js b/src/helpers/llamaCppInstaller.jsnew file mode 100644index 000000000..0ed938c99--- /dev/null+++ b/src/helpers/llamaCppInstaller.js@@ -0,0 +1,267 @@+const { spawn } = require("child_process");+const { app } = require("electron");+const path = require("path");+const fs = require("fs");+const { promises: fsPromises } = require("fs");+const https = require("https");+const { createWriteStream } = require("fs");+const tar = require("tar");+const os = require("os");++// Only import unzipper in main process+let unzipper;+if (typeof window === 'undefined') {+ unzipper = require("unzipper");+}++class LlamaCppInstaller {+ constructor() {+ this.installDir = path.join(app.getPath("userData"), "llama-cpp");+ this.binPath = null;+ this.platform = process.platform;+ this.arch = process.arch;+ }++ async ensureInstallDir() {+ await fsPromises.mkdir(this.installDir, { recursive: true });+ }++ getBinaryName() {+ // Cross-platform binary name resolution+ switch (this.platform) {+ case "win32":+ return "llama-cli.exe";+ case "darwin":+ case "linux":+ default:+ return "llama-cli";+ }+ }++ getInstalledBinaryPath() {+ return path.join(this.installDir, this.getBinaryName());+ }++ async isInstalled() {+ try {+ // First check for system installation+ const systemInstalled = await this.checkSystemInstallation();+ if (systemInstalled) {+ // Get the system path+ const systemPath = await this.getSystemBinaryPath();+ if (systemPath) {+ this.binPath = systemPath;+ return true;+ }+ }++ // Then check for local installation+ const binaryPath = this.getInstalledBinaryPath();+ await fsPromises.access(binaryPath, fs.constants.X_OK);+ this.binPath = binaryPath;+ return true;+ } catch {+ return false;+ }+ }++ async getSystemBinaryPath() {+ return new Promise((resolve) => {+ // Cross-platform command resolution+ const checkCmd = this.platform === "win32" ? "where" : "which";+ const binaryNames = this.platform === "win32"+ ? ["llama-cli.exe", "llama.exe"]+ : ["llama-cli", "llama", "llama.cpp"];++ // Try each possible binary name+ let found = false;+ let remaining = binaryNames.length;++ for (const name of binaryNames) {+ const proc = spawn(checkCmd, [name], {+ shell: true,+ stdio: "pipe",+ });++ let output = "";+ proc.stdout.on("data", (data) => {+ output += data.toString();+ });++ proc.on("close", (code) => {+ if (!found && code === 0 && output) {+ found = true;+ resolve(output.trim().split('\n')[0]);+ }+ remaining--;+ if (remaining === 0 && !found) {+ resolve(null);+ }+ });++ proc.on("error", () => {+ remaining--;+ if (remaining === 0 && !found) {+ resolve(null);+ }+ });+ }+ });+ }++ async checkSystemInstallation() {+ const systemPath = await this.getSystemBinaryPath();+ return systemPath !== null;+ }++ async getVersion() {+ try {+ const binaryPath = this.binPath || this.getInstalledBinaryPath();++ return new Promise((resolve, reject) => {+ const proc = spawn(binaryPath, ["--version"], {+ shell: false,+ stdio: "pipe",+ });++ let output = "";+ proc.stdout.on("data", (data) => {+ output += data.toString();+ });++ proc.on("close", (code) => {+ if (code === 0) {+ resolve(output.trim());+ } else {+ reject(new Error(`Failed to get version: exit code ${code}`));+ }+ });++ proc.on("error", (err) => {+ reject(err);+ });+ });+ } catch (error) {+ throw new Error(`Failed to get llama.cpp version: ${error.message}`);+ }+ }++ getReleaseUrl() {+ // Map platform and arch to GitHub release asset names+ const platformMap = {+ darwin: {+ x64: "llama-cli-macos-x64",+ arm64: "llama-cli-macos-arm64",+ },+ linux: {+ x64: "llama-cli-linux-x64",+ arm64: "llama-cli-linux-arm64",+ },+ win32: {+ x64: "llama-cli-windows-x64.exe",+ arm64: "llama-cli-windows-arm64.exe",+ },+ };++ const assetName = platformMap[this.platform]?.[this.arch];+ if (!assetName) {+ throw new Error(`Unsupported platform: ${this.platform}-${this.arch}`);+ }++ // Using a specific release for stability+ const releaseTag = "v0.1.0"; // Update this as needed+ return `https://github.com/yourusername/llama-cpp-binaries/releases/download/${releaseTag}/${assetName}`;+ }++ async downloadBinary(url, destPath) {+ return new Promise((resolve, reject) => {+ const file = createWriteStream(destPath);++ https.get(url, (response) => {+ if (response.statusCode === 302 || response.statusCode === 301) {+ // Handle redirect+ https.get(response.headers.location, (redirectResponse) => {+ redirectResponse.pipe(file);+ file.on("finish", () => {+ file.close();+ resolve();+ });+ }).on("error", reject);+ } else if (response.statusCode === 200) {+ response.pipe(file);+ file.on("finish", () => {+ file.close();+ resolve();+ });+ } else {+ reject(new Error(`Failed to download: HTTP ${response.statusCode}`));+ }+ }).on("error", reject);+ });+ }++ async install() {+ try {+ await this.ensureInstallDir();++ // For now, return a message about manual installation+ // since we don't have a real binary distribution yet+ return {+ success: false,+ message: "Please install llama.cpp manually using Homebrew (macOS) or from source. Run: brew install llama.cpp",+ };++ // Future implementation:+ // const url = this.getReleaseUrl();+ // const binaryPath = this.getInstalledBinaryPath();+ //+ // await this.downloadBinary(url, binaryPath);+ //+ // // Make executable on Unix-like systems+ // if (this.platform !== "win32") {+ // await fsPromises.chmod(binaryPath, 0o755);+ // }+ //+ // this.binPath = binaryPath;+ // return { success: true, path: binaryPath };+ } catch (error) {+ return {+ success: false,+ message: `Installation failed: ${error.message}`,+ };+ }+ }++ async uninstall() {+ try {+ const binaryPath = this.getInstalledBinaryPath();+ await fsPromises.unlink(binaryPath);+ this.binPath = null;+ return { success: true };+ } catch (error) {+ return {+ success: false,+ message: `Uninstall failed: ${error.message}`,+ };+ }+ }++ async getBinaryPath() {+ // If we already have a path, use it+ if (this.binPath) {+ return this.binPath;+ }++ // Check for system installation first+ const systemPath = await this.getSystemBinaryPath();+ if (systemPath) {+ this.binPath = systemPath;+ return systemPath;+ }++ // Fall back to local installation+ return this.getInstalledBinaryPath();+ }+}++module.exports = { default: new LlamaCppInstaller() };\ No newline at end of filediff --git a/src/helpers/modelManagerBridge.js b/src/helpers/modelManagerBridge.jsindex b32fe8fd9..33facfafb 100644--- a/src/helpers/modelManagerBridge.js+++ b/src/helpers/modelManagerBridge.js@@ -313,19 +313,17 @@ class ModelManager {}async ensureLlamaCpp() {- // Check if llama.cpp is available+ // Simplify - isInstalled already checks system installationconst llamaCppInstaller = require("./llamaCppInstaller").default;- const isInstalled = await llamaCppInstaller.isInstalled() ||- await llamaCppInstaller.checkSystemInstallation();- if (!isInstalled) {+ if (!await llamaCppInstaller.isInstalled()) {throw new ModelError("llama.cpp is not installed","LLAMACPP_NOT_INSTALLED");}- this.llamaCppPath = await llamaCppInstaller.getLlamaCppPath();+ this.llamaCppPath = await llamaCppInstaller.getBinaryPath();return true;}diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.tsindex 2d8e7a608..b7a47803c 100644--- a/src/hooks/useSettings.ts+++ b/src/hooks/useSettings.ts@@ -156,6 +156,7 @@ export function useSettings() {setUseReasoningModel(settings.useReasoningModel);if (settings.reasoningModel !== undefined)setReasoningModel(settings.reasoningModel);+ // reasoningProvider is computed from reasoningModel, not stored separately},[setUseReasoningModel, setReasoningModel]);diff --git a/src/utils/textCleanup.js b/src/utils/textCleanup.jsindex 78378cbab..1af4053ce 100644--- a/src/utils/textCleanup.js+++ b/src/utils/textCleanup.js@@ -27,7 +27,7 @@ class TextCleanup {// Enhanced filler words - industry standardfillers: [/\b(?:um|uh|er|ah|mm|hmm|mhm)\b\s*/gi, // Hesitation sounds- /\b(?:like|so|well|right|okay|ok|yeah|yep|yup|sure|alright|fine)\b\s*/gi, // Common discourse markers+ /\b(?:like|so|well|right|okay|ok|yeah|yep|yup|sure|alright)\b\s*/gi, // Common discourse markers/\b(?:you know|I mean|I guess|sort of|kind of)\b\s*/gi, // Meaningless phrases and uncertainty markers/\b(?:maybe|perhaps)\b(?=\s)/gi, // Uncertainty markers (when not essential)/\b(?:basically|literally|totally|honestly|obviously|definitely|probably|actually)\b\s*/gi, // Overused intensifiers@@ -343,14 +343,15 @@ class TextCleanup {}/**- * Normalize whitespace and handle punctuation efficiently+ * Normalize whitespace - public method for minimal cleanup* @param {string} text* @returns {string}*/static normalizeSpaces(text) {+ if (!text) return '';return text.replace(/\s+/g, ' ') // Multiple spaces to single space- .replace(/[ ]+(?=[.,!?;:])/g, '') // Remove unnecessary spaces before punctuation+ .replace(/[ ]+(?=[.,!?;:])/g, '') // Remove spaces before punctuation.replace(/\n+/g, ' ') // Newlines to spaces.replace(/\t+/g, ' ') // Tabs to spaces.trim();