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
feat: add new key bindings and debug features
v0f01a317d4e4d
diff --git a/README.md b/README.mdindex c508d5aa4..e137ec537 100644--- a/README.md+++ b/README.md@@ -1,30 +1,68 @@-# OpenScribe+# Whisper Dictation App-*Automatically synced with your [v0.dev](https://v0.dev) deployments*+A desktop dictation application that uses OpenAI's Whisper model to transcribe speech and automatically paste it at your cursor location, similar to Wispr Flow.-[](https://vercel.com/gabriel-steins-projects/v0-open-scribe)-[](https://v0.dev/chat/projects/EdmcpQs4VcT)+## Features-## Overview+- π€ **Voice Recording**: Click or press space to start/stop recording+- π€ **AI Transcription**: Uses OpenAI Whisper for accurate speech-to-text+- β¨οΈ **Auto Paste**: Automatically pastes transcribed text at cursor location+- π₯ **Global Shortcut**: Cmd+Shift+Space to toggle the app from anywhere+- πͺ **Floating Window**: Always-on-top transparent window+- β‘ **Fast & Lightweight**: Built with Electron for cross-platform support-This repository will stay in sync with your deployed chats on [v0.dev](https://v0.dev).-Any changes you make to your deployed app will be automatically pushed to this repository from [v0.dev](https://v0.dev).+## Installation-## Deployment+1. Clone or download this project+2. Install dependencies:+ \`\`\`bash+ npm install+ \`\`\`+3. Set up your OpenAI API key:+ - Get your API key from [OpenAI Platform](https://platform.openai.com/api-keys)+ - Add it to the `.env` file or directly in the code+4. Run the app:+ \`\`\`bash+ npm start+ \`\`\`-Your project is live at:+## Usage-**[https://vercel.com/gabriel-steins-projects/v0-open-scribe](https://vercel.com/gabriel-steins-projects/v0-open-scribe)**+1. **Activate**: Press `Cmd+Shift+Space` (Mac) or `Ctrl+Shift+Space` (Windows/Linux)+2. **Record**: Click the microphone button or press `Space`+3. **Stop**: Click again or press `Space` to stop recording+4. **Auto-paste**: The transcribed text will automatically be pasted at your cursor+5. **Close**: Press `ESC` or click the X button-## Build your app+## System Requirements-Continue building your app on:+- **macOS**: Requires accessibility permissions for text pasting+- **Windows**: May require PowerShell execution policy adjustment+- **Linux**: Requires `xdotool` for text pasting (`sudo apt install xdotool`)-**[https://v0.dev/chat/projects/EdmcpQs4VcT](https://v0.dev/chat/projects/EdmcpQs4VcT)**+## Building-## How It Works+To create a distributable app:-1. Create and modify your project using [v0.dev](https://v0.dev)-2. Deploy your chats from the v0 interface-3. Changes are automatically pushed to this repository-4. Vercel deploys the latest version from this repository+\`\`\`bash+npm run build+\`\`\`++This will create platform-specific installers in the `dist` folder.++## Permissions++The app requires:+- **Microphone access**: For voice recording+- **Accessibility permissions**: For automatic text pasting (macOS)+- **Input simulation**: For keyboard shortcuts (Windows/Linux)++## Troubleshooting++- **No microphone access**: Check system permissions+- **Text not pasting**: Ensure accessibility permissions are granted+- **API errors**: Verify your OpenAI API key is correct and has credits++## License++MIT License - feel free to modify and distribute!diff --git a/index.html b/index.htmlnew file mode 100644index 000000000..c30ea53e7--- /dev/null+++ b/index.html@@ -0,0 +1,257 @@+<!DOCTYPE html>+<html>+<head>+ <meta charset="UTF-8">+ <title>Whisper Dictation</title>+ <script src="https://unpkg.com/react@18/umd/react.development.js"></script>+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>+ <script src="https://cdn.tailwindcss.com"></script>+ <style>+ body {+ margin: 0;+ padding: 0;+ background: transparent;+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;+ }+ .glass-effect {+ backdrop-filter: blur(20px);+ background: rgba(255, 255, 255, 0.1);+ border: 1px solid rgba(255, 255, 255, 0.2);+ }+ </style>+</head>+<body>+ <div id="root"></div>++ <script type="text/babel">+ const { useState, useEffect, useRef } = React;+ const { ipcRenderer } = require('electron');++ // Button Component+ const Button = ({ children, onClick, disabled, variant = "default", size = "default", className = "" }) => {+ const baseClasses = "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background";++ const variants = {+ default: "bg-primary text-primary-foreground hover:bg-primary/90 bg-slate-900 text-white hover:bg-slate-800",+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90 bg-red-500 text-white hover:bg-red-600",+ outline: "border border-input hover:bg-accent hover:text-accent-foreground border-slate-200 hover:bg-slate-100",+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 bg-slate-100 text-slate-900 hover:bg-slate-200",+ ghost: "hover:bg-accent hover:text-accent-foreground hover:bg-slate-100",+ link: "underline-offset-4 hover:underline text-primary text-blue-600"+ };++ const sizes = {+ default: "h-10 py-2 px-4",+ sm: "h-9 px-3 rounded-md",+ lg: "h-11 px-8 rounded-md",+ icon: "h-10 w-10"+ };++ return (+ <button+ className={`${baseClasses} ${variants[variant]} ${sizes[size]} ${className}`}+ onClick={onClick}+ disabled={disabled}+ >+ {children}+ </button>+ );+ };++ // Card Components+ const Card = ({ children, className = "" }) => (+ <div className={`rounded-lg border bg-card text-card-foreground shadow-sm border-slate-200 bg-white ${className}`}>+ {children}+ </div>+ );++ const CardContent = ({ children, className = "" }) => (+ <div className={`p-6 pt-0 ${className}`}>+ {children}+ </div>+ );++ // Main App Component+ const App = () => {+ const [isRecording, setIsRecording] = useState(false);+ const [isProcessing, setIsProcessing] = useState(false);+ const [transcript, setTranscript] = useState('');+ const [error, setError] = useState('');+ const mediaRecorderRef = useRef(null);+ const audioChunksRef = useRef([]);++ const startRecording = async () => {+ try {+ console.log("Starting recording...")+ setError('');+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });+ console.log("Microphone access granted")++ mediaRecorderRef.current = new MediaRecorder(stream);+ audioChunksRef.current = [];++ mediaRecorderRef.current.ondataavailable = (event) => {+ console.log("Audio data chunk received, size:", event.data.size)+ audioChunksRef.current.push(event.data);+ };++ mediaRecorderRef.current.onstop = async () => {+ console.log("Recording stopped, processing audio...")+ const audioBlob = new Blob(audioChunksRef.current, { type: 'audio/wav' });+ await processAudio(audioBlob);+ stream.getTracks().forEach(track => track.stop());+ };++ mediaRecorderRef.current.start();+ setIsRecording(true);+ console.log("Recording started successfully")+ } catch (err) {+ console.error("Recording error:", err)+ setError('Failed to access microphone: ' + err.message);+ }+ };++ const stopRecording = () => {+ if (mediaRecorderRef.current && isRecording) {+ mediaRecorderRef.current.stop();+ setIsRecording(false);+ setIsProcessing(true);+ }+ };++ const processAudio = async (audioBlob) => {+ try {+ console.log("Processing audio blob, size:", audioBlob.size)+ const formData = new FormData();+ formData.append('file', audioBlob, 'audio.wav');+ formData.append('model', 'whisper-1');++ console.log("Sending request to OpenAI Whisper API...")+ const response = await fetch('https://api.openai.com/v1/audio/transcriptions', {+ method: 'POST',+ headers: {+ 'Authorization': `Bearer ${process.env.OPENAI_API_KEY || 'your-api-key-here'}`+ },+ body: formData+ });++ console.log("Response status:", response.status)+ if (!response.ok) {+ const errorText = await response.text()+ console.error("API Error:", errorText)+ throw new Error(`Failed to transcribe audio: ${response.status} ${errorText}`)+ }++ const result = await response.json();+ console.log("Transcription result:", result)+ const text = result.text.trim();++ if (text) {+ setTranscript(text);+ console.log("Transcribed text:", text)+ // Automatically paste the text+ await ipcRenderer.invoke('paste-text', text);+ } else {+ console.log("No text transcribed")+ }+ } catch (err) {+ console.error("Transcription error:", err)+ setError('Transcription failed: ' + err.message);+ } finally {+ setIsProcessing(false);+ }+ };++ const handleClose = () => {+ ipcRenderer.invoke('hide-window');+ };++ const handleKeyPress = (e) => {+ if (e.key === 'Escape') {+ handleClose();+ } else if (e.key === ' ' && !isRecording && !isProcessing) {+ e.preventDefault();+ startRecording();+ } else if (e.key === ' ' && isRecording) {+ e.preventDefault();+ stopRecording();+ }+ };++ useEffect(() => {+ document.addEventListener('keydown', handleKeyPress);+ return () => document.removeEventListener('keydown', handleKeyPress);+ }, [isRecording, isProcessing]);++ return (+ <div className="p-4">+ <Card className="glass-effect border-white/20 bg-white/10 backdrop-blur-xl">+ <CardContent className="p-6">+ <div className="flex flex-col items-center space-y-4">+ <div className="flex items-center justify-between w-full">+ <h2 className="text-lg font-semibold text-white">Whisper Dictation</h2>+ <Button+ variant="ghost"+ size="sm"+ onClick={handleClose}+ className="text-white hover:bg-white/20"+ >+ β+ </Button>+ </div>++ <div className="flex flex-col items-center space-y-3">+ {isProcessing ? (+ <div className="flex flex-col items-center space-y-2">+ <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-white"></div>+ <p className="text-sm text-white/80">Processing...</p>+ </div>+ ) : (+ <Button+ onClick={isRecording ? stopRecording : startRecording}+ className={`w-16 h-16 rounded-full ${+ isRecording+ ? 'bg-red-500 hover:bg-red-600 animate-pulse'+ : 'bg-blue-500 hover:bg-blue-600'+ }`}+ disabled={isProcessing}+ >+ {isRecording ? 'βΉοΈ' : 'π€'}+ </Button>+ )}++ <p className="text-xs text-white/70 text-center">+ {isRecording+ ? 'Recording... Press space or click to stop'+ : 'Press space or click to start recording'+ }+ </p>+ </div>++ {transcript && (+ <div className="w-full p-3 bg-white/20 rounded-md">+ <p className="text-sm text-white">{transcript}</p>+ </div>+ )}++ {error && (+ <div className="w-full p-3 bg-red-500/20 rounded-md">+ <p className="text-sm text-red-200">{error}</p>+ </div>+ )}++ <p className="text-xs text-white/50 text-center">+ Press F13 or Cmd+` to toggle β’ ESC to close+ </p>+ </div>+ </CardContent>+ </Card>+ </div>+ );+ };++ ReactDOM.render(<App />, document.getElementById('root'));+ </script>+</body>+</html>diff --git a/main.js b/main.jsnew file mode 100644index 000000000..63580d259--- /dev/null+++ b/main.js@@ -0,0 +1,110 @@+const { app, BrowserWindow, globalShortcut, ipcMain, clipboard, shell } = require("electron")+const path = require("path")+const { spawn } = require("child_process")++let mainWindow++function createWindow() {+ mainWindow = new BrowserWindow({+ width: 400,+ height: 300,+ webPreferences: {+ nodeIntegration: true,+ contextIsolation: false,+ enableRemoteModule: true,+ },+ frame: false,+ alwaysOnTop: true,+ resizable: false,+ skipTaskbar: true,+ transparent: true,+ show: false,+ })++ mainWindow.loadFile("index.html")++ // Register global shortcut for activation - using Fn+Space equivalent+ globalShortcut.register("Fn", () => {+ console.log("Global shortcut activated!")+ if (mainWindow.isVisible()) {+ mainWindow.hide()+ console.log("Window hidden")+ } else {+ mainWindow.show()+ mainWindow.focus()+ console.log("Window shown")+ }+ })++ // Alternative: Use Cmd+` (backtick) which is easier to reach+ globalShortcut.register("CommandOrControl+`", () => {+ console.log("Alternative shortcut activated!")+ if (mainWindow.isVisible()) {+ mainWindow.hide()+ } else {+ mainWindow.show()+ mainWindow.focus()+ }+ })+}++app.whenReady().then(() => {+ createWindow()+ console.log("π€ Whisper Dictation App started!")+ console.log("π Shortcuts:")+ console.log(" - F13 key to toggle window")+ console.log(" - Cmd+` (backtick) to toggle window")+ console.log(" - Space to start/stop recording")+ console.log(" - ESC to close window")+})++app.on("window-all-closed", () => {+ if (process.platform !== "darwin") {+ app.quit()+ }+})++app.on("activate", () => {+ if (BrowserWindow.getAllWindows().length === 0) {+ createWindow()+ }+})++app.on("will-quit", () => {+ globalShortcut.unregisterAll()+})++// IPC handlers+ipcMain.handle("paste-text", async (event, text) => {+ console.log("Pasting text:", text)+ // Hide the window first+ mainWindow.hide()++ // Wait a bit for the window to hide+ await new Promise((resolve) => setTimeout(resolve, 100))++ // Copy text to clipboard and simulate paste+ clipboard.writeText(text)+ console.log("Text copied to clipboard")++ // Simulate Ctrl+V (or Cmd+V on Mac)+ const { spawn } = require("child_process")+ if (process.platform === "darwin") {+ console.log("Simulating Cmd+V on macOS")+ spawn("osascript", ["-e", 'tell application "System Events" to keystroke "v" using command down'])+ } else if (process.platform === "win32") {+ console.log("Simulating Ctrl+V on Windows")+ spawn("powershell", [+ "-Command",+ 'Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait("^v")',+ ])+ } else {+ console.log("Simulating Ctrl+V on Linux")+ // Linux+ spawn("xdotool", ["key", "ctrl+v"])+ }+})++ipcMain.handle("hide-window", () => {+ mainWindow.hide()+})diff --git a/package.json b/package.jsonnew file mode 100644index 000000000..e89b1e978--- /dev/null+++ b/package.json@@ -0,0 +1,8 @@+{+ "name": "my-v0-project",+ "version": "0.1.0",+ "private": true,+ "scripts": {+ "build": "echo 'no build script'"+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlnew file mode 100644index 000000000..9b60ae178--- /dev/null+++ b/pnpm-lock.yaml@@ -0,0 +1,9 @@+lockfileVersion: '9.0'++settings:+ autoInstallPeers: true+ excludeLinksFromLockfile: false++importers:++ .: {}diff --git a/setup.js b/setup.jsnew file mode 100644index 000000000..b90682e15--- /dev/null+++ b/setup.js@@ -0,0 +1,40 @@+const fs = require("fs")+const path = require("path")++console.log("Setting up Whisper Dictation App...")++// Create .env file template+const envTemplate = `# OpenAI API Key for Whisper+OPENAI_API_KEY=your_openai_api_key_here++# Instructions:+# 1. Get your OpenAI API key from https://platform.openai.com/api-keys+# 2. Replace 'your_openai_api_key_here' with your actual API key+# 3. Save this file+`++if (!fs.existsSync(".env")) {+ fs.writeFileSync(".env", envTemplate)+ console.log("β Created .env file template")+} else {+ console.log("β οΈ .env file already exists")+}++console.log(`+π Setup complete!++Next steps:+1. Add your OpenAI API key to the .env file+2. Install dependencies: npm install+3. Run the app: npm start++Features:+- Global shortcut: Cmd+Shift+Space (Mac) or Ctrl+Shift+Space (Windows/Linux)+- Space bar to start/stop recording+- ESC to close the app+- Automatic text pasting at cursor location++Note: Make sure you have the necessary system permissions for:+- Microphone access+- Accessibility permissions (for text pasting)+`)diff --git a/test-setup.js b/test-setup.jsnew file mode 100644index 000000000..aba447f71--- /dev/null+++ b/test-setup.js@@ -0,0 +1,70 @@+const { exec } = require("child_process")+const fs = require("fs")++console.log("π§ͺ Testing Whisper Dictation App Setup...\n")++// Test 1: Check if required files exist+console.log("1. Checking required files...")+const requiredFiles = ["main.js", "index.html", "package.json"]+requiredFiles.forEach((file) => {+ if (fs.existsSync(file)) {+ console.log(` β ${file} exists`)+ } else {+ console.log(` β ${file} missing`)+ }+})++// Test 2: Check Node.js version+console.log("\n2. Checking Node.js version...")+exec("node --version", (error, stdout) => {+ if (error) {+ console.log(" β Node.js not found")+ } else {+ console.log(` β Node.js version: ${stdout.trim()}`)+ }+})++// Test 3: Check if Electron is installed+console.log("\n3. Checking Electron installation...")+exec("npx electron --version", (error, stdout) => {+ if (error) {+ console.log(" β Electron not installed - run: npm install")+ } else {+ console.log(` β Electron version: ${stdout.trim()}`)+ }+})++// Test 4: Check environment variables+console.log("\n4. Checking environment setup...")+if (process.env.OPENAI_API_KEY) {+ console.log(" β OPENAI_API_KEY is set")+} else {+ console.log(" β οΈ OPENAI_API_KEY not set - add it to your environment or .env file")+}++// Test 5: Platform-specific checks+console.log("\n5. Platform-specific checks...")+console.log(` Platform: ${process.platform}`)++if (process.platform === "darwin") {+ console.log(" π macOS detected:")+ console.log(" - You'll need to grant microphone permissions")+ console.log(" - You'll need to grant accessibility permissions for text pasting")+ console.log(" - Go to System Preferences > Security & Privacy > Privacy")+} else if (process.platform === "win32") {+ console.log(" π Windows detected:")+ console.log(" - You may need to adjust PowerShell execution policy")+ console.log(" - Grant microphone permissions when prompted")+} else {+ console.log(" π Linux detected:")+ console.log(" - Install xdotool: sudo apt install xdotool")+ console.log(" - Grant microphone permissions when prompted")+}++console.log("\nπ To test the app:")+console.log("1. Run: npm start")+console.log("2. Press F13 or Cmd+` to show/hide the window")+console.log("3. Click the microphone or press Space to start recording")+console.log("4. Speak something and press Space again to stop")+console.log("5. Check the console for debug messages")+console.log("\nπ‘ Open Developer Tools in the app with Cmd+Option+I (Mac) or Ctrl+Shift+I (Windows/Linux)")