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(stt): surface and keep recordings discarded as a dictionary echo (#1559)
Gabriel Stein785594e5ecca
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 1d9b417ec..549a48f16 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -85,7 +85,11 @@ import { resolvePrompt, appendScreenContextSuffix } from "../config/prompts";import { syncService } from "../services/SyncService.js";import { evaluateFinishedRecording, withSalvageWarning } from "./recordingValidation";import { isEmptyRecording } from "./recordingGuard";-import { matchesDictionaryPrompt } from "../utils/dictionaryEchoFilter.js";+import {+ DICTIONARY_ECHO_CODE,+ dictionaryEchoError,+ matchesDictionaryPrompt,+} from "../utils/dictionaryEchoFilter.js";import { getDictionaryHintWords } from "../utils/snippets";import {buildSelectionEditSystemPrompt,@@ -556,6 +560,8 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);setCallbacks({onStateChange,onError,+ // Optional: the agent overlay has no dictation toast surface.+ onNoAudio = undefined,onTranscriptionComplete,onPartialTranscript,onStreamingCommit,@@ -563,6 +569,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);}) {this.onStateChange = onStateChange;this.onError = onError;+ this.onNoAudio = onNoAudio;this.onTranscriptionComplete = onTranscriptionComplete;this.onPartialTranscript = onPartialTranscript;this.onStreamingCommit = onStreamingCommit;@@ -1710,7 +1717,16 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);"performance");- if (error.message !== "No audio detected") {+ if (error.code === DICTIONARY_ECHO_CODE) {+ // The transcript was discarded as an echo of the dictionary prompt. Only+ // the local engine's genuine-silence path gets a toast from main, so+ // surface the same one here and keep the audio for a manual retry —+ // otherwise the whole utterance disappears with no feedback (#1547).+ this.onNoAudio?.();+ if (this.lastAudioBlob) {+ this.saveFailedTranscription(error.message, error.code, metadata);+ }+ } else if (error.message !== "No audio detected") {this.onError?.({title: error.selectionEditFatal ? "Selection Edit Failed" : "Transcription Error",description: error.selectionEditFatal@@ -1788,7 +1804,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);skipVad: true,});if (!retry?.success || !retry.text?.trim() || this.isDictionaryEcho(retry.text)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}logger.info("Recovered transcript after dictionary-echo detection",@@ -2736,7 +2752,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);const rawText = result.text;if (this.isDictionaryEcho(rawText)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}let processedText = result.text;if (processedText && !this.skipReasoning) {@@ -2926,7 +2942,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);throw new Error("No text transcribed - Tinfoil response was empty");}if (this.isDictionaryEcho(proxyText)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);const reasoningStart = performance.now();@@ -3031,7 +3047,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (proxyText && proxyText.trim().length > 0) {if (this.isDictionaryEcho(proxyText)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);const rawText = proxyText;@@ -3064,7 +3080,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (proxyText && proxyText.trim().length > 0) {if (this.isDictionaryEcho(proxyText)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);const rawText = proxyText;@@ -3095,7 +3111,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (proxyText && proxyText.trim().length > 0) {if (this.isDictionaryEcho(proxyText)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);const rawText = proxyText;@@ -3245,7 +3261,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);// Check for text - handle both empty string and missing fieldif (result.text && result.text.trim().length > 0) {if (this.isDictionaryEcho(result.text)) {- throw new Error("No audio detected");+ throw dictionaryEchoError();}timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);const rawText = result.text;diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.jsindex 74f19e185..668636b45 100644--- a/src/hooks/useAudioRecording.js+++ b/src/hooks/useAudioRecording.js@@ -206,6 +206,17 @@ export const useAudioRecording = (toast, options = {}) => {window.electronAPI?.resumeMediaPlayback?.();}},+ onNoAudio: () => {+ window.electronAPI?.hideDictationPreview?.();+ if (getSettings().pauseMediaOnDictation) {+ window.electronAPI?.resumeMediaPlayback?.();+ }+ toast({+ title: t("hooks.audioRecording.noAudio.title"),+ description: t("hooks.audioRecording.noAudio.description"),+ variant: "default",+ });+ },onPartialTranscript: (text) => {setPartialTranscript(text);},diff --git a/src/utils/dictionaryEchoFilter.js b/src/utils/dictionaryEchoFilter.jsindex fdc82a650..452a12b79 100644--- a/src/utils/dictionaryEchoFilter.js+++ b/src/utils/dictionaryEchoFilter.js@@ -28,3 +28,14 @@ export function matchesDictionaryPrompt(text, dictionaryPrompt) {return textComposition >= 0.9 && dictionaryUsage >= 0.7;}++export const DICTIONARY_ECHO_CODE = "DICTIONARY_ECHO";++// Keeps the "No audio detected" message so the existing message comparisons and+// the main-process no-audio contract still match, while letting the pipeline+// tell a discarded dictionary echo apart from genuine silence (#1547).+export function dictionaryEchoError() {+ const error = new Error("No audio detected");+ error.code = DICTIONARY_ECHO_CODE;+ return error;+}diff --git a/test/helpers/dictionaryEchoRecovery.test.js b/test/helpers/dictionaryEchoRecovery.test.jsnew file mode 100644index 000000000..5005f5944--- /dev/null+++ b/test/helpers/dictionaryEchoRecovery.test.js@@ -0,0 +1,80 @@+const test = require("node:test");+const assert = require("node:assert/strict");++// The pipeline's catch block decides what a discarded dictionary echo costs the+// user. Before #1547 it shared the genuine-silence branch, which suppressed both+// the toast and saveFailedTranscription, so a whole utterance vanished with no+// feedback and no way to retry it.+const runCatch = (error, manager) => {+ if (error.code === "DICTIONARY_ECHO") {+ manager.onNoAudio?.();+ if (manager.lastAudioBlob) {+ manager.saveFailedTranscription(error.message, error.code, {});+ }+ } else if (error.message !== "No audio detected") {+ manager.onError?.({ description: error.message });+ if (manager.lastAudioBlob) {+ manager.saveFailedTranscription(error.message, error.code || null, {});+ }+ }+};++const makeManager = () => {+ const calls = { noAudio: 0, errors: [], saved: [] };+ return {+ calls,+ lastAudioBlob: {},+ onNoAudio: () => calls.noAudio++,+ onError: (payload) => calls.errors.push(payload),+ saveFailedTranscription: (message, code) => calls.saved.push({ message, code }),+ };+};++test("a discarded dictionary echo toasts and keeps the recording", async () => {+ const { DICTIONARY_ECHO_CODE } = await import("../../src/utils/dictionaryEchoFilter.js");+ const manager = makeManager();+ const error = new Error("No audio detected");+ error.code = DICTIONARY_ECHO_CODE;++ runCatch(error, manager);++ assert.equal(manager.calls.noAudio, 1);+ assert.deepEqual(manager.calls.saved, [+ { message: "No audio detected", code: DICTIONARY_ECHO_CODE },+ ]);+ // Not the destructive "Transcription Error" toast — this is a soft outcome.+ assert.deepEqual(manager.calls.errors, []);+});++test("genuine silence stays silent — main already toasts that path", () => {+ const manager = makeManager();++ runCatch(new Error("No audio detected"), manager);++ assert.equal(manager.calls.noAudio, 0);+ assert.deepEqual(manager.calls.saved, []);+ assert.deepEqual(manager.calls.errors, []);+});++test("a real failure still reports an error and saves for retry", () => {+ const manager = makeManager();++ runCatch(new Error("Groq returned 500"), manager);++ assert.equal(manager.calls.noAudio, 0);+ assert.equal(manager.calls.errors.length, 1);+ assert.deepEqual(manager.calls.saved, [{ message: "Groq returned 500", code: null }]);+});++test("every dictionary-echo discard is tagged, on local and remote paths alike", async () => {+ const fs = require("fs");+ const source = fs.readFileSync("src/helpers/audioManager.js", "utf-8");++ // Each isDictionaryEcho guard must throw the tagged error; a plain+ // `new Error("No audio detected")` there would be swallowed again.+ const guards = source.match(/isDictionaryEcho\([\s\S]{0,400}?throw [^;]+;/g) ?? [];+ assert.ok(guards.length >= 7, `expected the known echo guards, found ${guards.length}`);+ for (const guard of guards) {+ assert.match(guard, /throw dictionaryEchoError\(\);/);+ }+});