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 ability to cancel recording
Gabriel Stein091b28c2d35f
diff --git a/src/App.jsx b/src/App.jsxindex 5b22d4554..3d14e6421 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -1,5 +1,6 @@import React, { useState, useEffect, useRef } from "react";import "./index.css";+import { X } from "lucide-react";import { useToast } from "./components/ui/Toast";import { LoadingDots } from "./components/ui/LoadingDots";import { useHotkey } from "./hooks/useHotkey";@@ -106,14 +107,13 @@ export default function App() {setWindowInteractivity(false);}, [setWindowInteractivity]);- const { isRecording, isProcessing, toggleListening } = useAudioRecording(+ const { isRecording, isProcessing, toggleListening, cancelRecording } = useAudioRecording(toast,{onToggle: handleDictationToggle,});-const handleClose = () => {window.electronAPI.hideWindow();};@@ -137,6 +137,7 @@ export default function App() {document.addEventListener("mousedown", handleClickOutside);return () => document.removeEventListener("mousedown", handleClickOutside);}, [isCommandMenuOpen]);+useEffect(() => {const handleKeyPress = (e) => {if (e.key === "Escape") {@@ -161,7 +162,6 @@ export default function App() {};const micState = getMicState();- const isListening = isRecording || isProcessing;// Get microphone button properties based on stateconst getMicButtonProps = () => {@@ -204,7 +204,33 @@ export default function App() {<>{/* Fixed bottom-right voice button */}<div className="fixed bottom-6 right-6 z-50">- <div className="relative">+ <div+ className="relative flex items-center gap-2"+ onMouseEnter={() => {+ setIsHovered(true);+ setWindowInteractivity(true);+ }}+ onMouseLeave={() => {+ setIsHovered(false);+ if (!isCommandMenuOpen) {+ setWindowInteractivity(false);+ }+ }}+ >+ {isRecording && isHovered && (+ <Tooltip content="Stop recording">+ <button+ aria-label="Cancel recording"+ onClick={(e) => {+ e.stopPropagation();+ cancelRecording();+ }}+ className="w-7 h-7 rounded-full bg-neutral-800/90 hover:bg-red-500 border border-white/20 hover:border-red-400 flex items-center justify-center transition-all duration-150 shadow-lg backdrop-blur-sm"+ >+ <X size={12} strokeWidth={2.5} color="white" />+ </button>+ </Tooltip>+ )}<Tooltip content={micProps.tooltip}><buttonref={buttonRef}@@ -244,16 +270,6 @@ export default function App() {setIsCommandMenuOpen((prev) => !prev);}}}- onMouseEnter={() => {- setIsHovered(true);- setWindowInteractivity(true);- }}- onMouseLeave={() => {- setIsHovered(false);- if (!isCommandMenuOpen) {- setWindowInteractivity(false);- }- }}onFocus={() => setIsHovered(true)}onBlur={() => setIsHovered(false)}className={micProps.className}diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex a37077821..81d8db9fd 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -70,7 +70,7 @@ class AudioManager {async startRecording() {try {- if (this.isRecording || this.mediaRecorder?.state === "recording") {+ if (this.isRecording || this.isProcessing || this.mediaRecorder?.state === "recording") {return false;}@@ -157,6 +157,37 @@ class AudioManager {return false;}+ cancelRecording() {+ if (this.mediaRecorder && this.mediaRecorder.state === "recording") {+ // Remove the onstop handler to prevent processing+ this.mediaRecorder.onstop = () => {+ // Discard audio - just reset state without processing+ this.isRecording = false;+ this.isProcessing = false;+ this.audioChunks = [];+ this.recordingStartTime = null;+ this.onStateChange?.({ isRecording: false, isProcessing: false });++ // Log cancellation+ this.markLatencyStage(+ "03_recording_cancelled",+ { description: "Recording cancelled by user" },+ { total: true, complete: true }+ );+ };++ this.mediaRecorder.stop();++ // Stop all tracks immediately+ if (this.mediaRecorder.stream) {+ this.mediaRecorder.stream.getTracks().forEach((track) => track.stop());+ }++ return true;+ }+ return false;+ }+async processAudio(audioBlob, metadata = {}) {try {const useLocalWhisper = localStorage.getItem("useLocalWhisper") === "true";@@ -192,6 +223,14 @@ class AudioManager {} finally {this.isProcessing = false;this.onStateChange?.({ isRecording: false, isProcessing: false });+ // Complete session if not already completed by safePaste or error handler+ if (this.latencySession) {+ this.markLatencyStage(+ "09_processing_complete",+ { description: "Audio processing finished (session cleanup)" },+ { total: true, complete: true }+ );+ }}}diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.jsindex 5b562f1fb..9c26a8e65 100644--- a/src/helpers/clipboard.js+++ b/src/helpers/clipboard.js@@ -10,7 +10,6 @@ class ClipboardManager {constructor() {this.accessibilityCache = { value: null, expiresAt: 0 };this.commandAvailabilityCache = new Map();- this.availablePasteToolsCache = new Map();}// Safe logging method - only log in development@@ -285,19 +284,8 @@ class ClipboardManager {{ cmd: "xdotool", args: ["key", pasteKeys] },];- // Filter to only available tools (cached by session type)- const cacheKey = `${isWayland ? "wayland" : "x11"}:${inTerminal ? "term" : "gui"}`;- const cacheEntry = this.availablePasteToolsCache.get(cacheKey);- let available;- if (cacheEntry && Date.now() < cacheEntry.expiresAt) {- available = cacheEntry.tools;- } else {- available = candidates.filter((c) => commandExists(c.cmd));- this.availablePasteToolsCache.set(cacheKey, {- tools: available,- expiresAt: Date.now() + CACHE_TTL_MS,- });- }+ // Filter to only available tools (commandExists is already cached)+ const available = candidates.filter((c) => commandExists(c.cmd));// Attempt paste with a specific toolconst pasteWith = (tool) =>diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.jsindex 51f677e3a..66748ec98 100644--- a/src/hooks/useAudioRecording.js+++ b/src/hooks/useAudioRecording.js@@ -111,6 +111,13 @@ export const useAudioRecording = (toast, options = {}) => {return false;};+ const cancelRecording = () => {+ if (audioManagerRef.current) {+ return audioManagerRef.current.cancelRecording();+ }+ return false;+ };+const toggleListening = () => {if (!isRecording && !isProcessing) {startRecording();@@ -125,6 +132,7 @@ export const useAudioRecording = (toast, options = {}) => {transcript,startRecording,stopRecording,+ cancelRecording,toggleListening,};};