Skip to content

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

cleanup: better loggin

Gabriel Stein3ebcc926222f
diff --git a/main.js b/main.js
index 983e95df6..5a9b60d58 100644
--- a/main.js
+++ b/main.js
@@ -240,41 +240,66 @@ async function createControlPanelWindow() {
}
// Database setup
-let db;
+let db = null;
function initDatabase() {
- // Use different database files for development vs production
- const dbFileName = process.env.NODE_ENV === 'development'
- ? 'transcriptions-dev.db'
- : 'transcriptions.db';
-
- const dbPath = path.join(app.getPath('userData'), dbFileName);
- // Database initialization
-
- db = new Database(dbPath);
-
- // Create transcriptions table if it doesn't exist
- db.exec(`
- CREATE TABLE IF NOT EXISTS transcriptions (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- text TEXT NOT NULL,
- timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
- )
- `);
-
- // Get count of existing transcriptions
- const countStmt = db.prepare('SELECT COUNT(*) as count FROM transcriptions');
- const { count } = countStmt.get();
-
- console.log(`✅ Database initialized successfully (${count} existing transcriptions)`);
+ try {
+ console.log('🔄 Starting database initialization...');
+
+ // Use different database files for development vs production
+ const dbFileName = process.env.NODE_ENV === 'development'
+ ? 'transcriptions-dev.db'
+ : 'transcriptions.db';
+
+ const dbPath = path.join(app.getPath('userData'), dbFileName);
+ console.log('📁 Database path:', dbPath);
+
+ // Database initialization
+ console.log('🔧 Creating database connection...');
+ db = new Database(dbPath);
+ console.log('✅ Database connection created');
+
+ // Create transcriptions table if it doesn't exist
+ console.log('📋 Creating transcriptions table...');
+ db.exec(`
+ CREATE TABLE IF NOT EXISTS transcriptions (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ text TEXT NOT NULL,
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ )
+ `);
+ console.log('✅ Transcriptions table created/verified');
+
+ // Get count of existing transcriptions
+ console.log('📊 Counting existing transcriptions...');
+ const countStmt = db.prepare('SELECT COUNT(*) as count FROM transcriptions');
+ const { count } = countStmt.get();
+
+ console.log(`✅ Database initialized successfully (${count} existing transcriptions)`);
+ return true;
+ } catch (error) {
+ console.error('❌ Database initialization failed:', error);
+ console.error('Error details:', {
+ message: error.message,
+ stack: error.stack
+ });
+ throw error;
+ }
}
app.whenReady().then(async () => {
// Initialize database
try {
- initDatabase();
+await new Promise((resolve, reject) => {
+ try {
+ initDatabase();
+ resolve();
+ } catch (error) {
+ reject('Failed to initialize database: ' + error);
+ }
+ });
} catch (error) {
console.error('Failed to initialize database:', error);
}
@@ -750,6 +775,9 @@ ipcMain.handle("hide-window", () => {
// Database IPC handlers
ipcMain.handle('db-save-transcription', async (event, text) => {
try {
+ if (!db) {
+ throw new Error('Database not initialized');
+ }
const stmt = db.prepare('INSERT INTO transcriptions (text) VALUES (?)');
const result = stmt.run(text);
@@ -769,6 +797,9 @@ ipcMain.handle('db-save-transcription', async (event, text) => {
ipcMain.handle('db-get-transcriptions', async (event, limit = 50) => {
try {
+ if (!db) {
+ throw new Error('Database not initialized');
+ }
const stmt = db.prepare('SELECT * FROM transcriptions ORDER BY timestamp DESC LIMIT ?');
const transcriptions = stmt.all(limit);
console.log(`📚 Retrieved ${transcriptions.length} transcriptions from ${process.env.NODE_ENV || 'production'} DB (limit: ${limit})`);
@@ -781,6 +812,9 @@ ipcMain.handle('db-get-transcriptions', async (event, limit = 50) => {
ipcMain.handle('db-clear-transcriptions', async (event) => {
try {
+ if (!db) {
+ throw new Error('Database not initialized');
+ }
const stmt = db.prepare('DELETE FROM transcriptions');
const result = stmt.run();
console.log(`🗑️ Cleared ${result.changes} transcriptions from ${process.env.NODE_ENV || 'production'} DB`);
@@ -793,6 +827,9 @@ ipcMain.handle('db-clear-transcriptions', async (event) => {
ipcMain.handle('db-delete-transcription', async (event, id) => {
try {
+ if (!db) {
+ throw new Error('Database not initialized');
+ }
const stmt = db.prepare('DELETE FROM transcriptions WHERE id = ?');
const result = stmt.run(id);
console.log(`🗑️ Deleted transcription ${id}, affected rows: ${result.changes}`);
@@ -875,7 +912,23 @@ ipcMain.handle('transcribe-local-whisper', async (event, audioBlob, options = {}
// Convert Blob to Buffer and write to temp file
console.log('💾 Writing audio to temp file:', tempAudioPath);
- const buffer = Buffer.from(await audioBlob.arrayBuffer());
+
+ // Handle different audio data formats
+ let buffer;
+ if (audioBlob instanceof ArrayBuffer) {
+ buffer = Buffer.from(audioBlob);
+ } else if (audioBlob instanceof Uint8Array) {
+ buffer = Buffer.from(audioBlob);
+ } else if (typeof audioBlob === 'string') {
+ // Base64 encoded audio data
+ buffer = Buffer.from(audioBlob, 'base64');
+ } else if (audioBlob && audioBlob.buffer) {
+ // TypedArray with buffer property
+ buffer = Buffer.from(audioBlob.buffer);
+ } else {
+ throw new Error(`Unsupported audio data type: ${typeof audioBlob}`);
+ }
+
fs.writeFileSync(tempAudioPath, buffer);
// Prepare Whisper command
diff --git a/package.json b/package.json
index 775625f6a..4da7bab8c 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,8 @@
"author": "OpenWispr Team",
"license": "MIT",
"devDependencies": {
+ "@electron/rebuild": "^4.0.1",
+ "@esbuild/darwin-arm64": "^0.25.5",
"@eslint/js": "^9.25.0",
"@tailwindcss/vite": "^4.1.10",
"@types/react": "^19.1.2",
diff --git a/src/App.jsx b/src/App.jsx
index 024d38e63..8e30818fd 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,10 +1,8 @@
import React, { useState, useEffect, useRef } from "react";
import "./index.css";
-import { Button } from "./components/ui/button";
-import { Card, CardContent } from "./components/ui/card";
import { Toast } from "./components/ui/Toast";
import { LoadingDots } from "./components/ui/LoadingDots";
-import { Mic, Settings } from "lucide-react";
+import { Settings } from "lucide-react";
// Sound Wave Icon Component (for idle/hover states)
const SoundWaveIcon = ({ size = 16 }) => {
@@ -170,9 +168,15 @@ export default function App() {
} catch (err) {
console.error("Local Whisper error:", err);
- // Fallback to OpenAI API if local fails
- setError('Local Whisper failed, trying OpenAI API...');
- await processWithOpenAIAPI(audioBlob);
+ // Check if we should attempt fallback to OpenAI API
+ const allowFallback = localStorage.getItem('allowOpenAIFallback') !== 'false';
+
+ if (allowFallback) {
+ setError('Local Whisper failed. Retrying with OpenAI API...');
+ await processWithOpenAIAPI(audioBlob);
+ } else {
+ throw new Error(`Local Whisper failed: ${err.message}`);
+ }
}
};