Skip to content

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

fix(stt): guard empty normalized text and prompt in dictionary echo filter (#1543)

Henry Su5ff05668cc9c
diff --git a/src/utils/dictionaryEchoFilter.js b/src/utils/dictionaryEchoFilter.js
index d0847a3ee..fdc82a650 100644
--- a/src/utils/dictionaryEchoFilter.js
+++ b/src/utils/dictionaryEchoFilter.js
@@ -11,6 +11,8 @@ export function matchesDictionaryPrompt(text, dictionaryPrompt) {
const normalizedText = normalize(text);
const normalizedPrompt = normalize(dictionaryPrompt);
+ if (!normalizedText || !normalizedPrompt) return false;
+
if (normalizedText === normalizedPrompt) return true;
const dictWords = new Set(normalizedPrompt.split(" "));
diff --git a/test/helpers/dictionaryEchoFilter.test.js b/test/helpers/dictionaryEchoFilter.test.js
index 085ba16ff..dd9a0bcf6 100644
--- a/test/helpers/dictionaryEchoFilter.test.js
+++ b/test/helpers/dictionaryEchoFilter.test.js
@@ -116,3 +116,11 @@ test("does not flag completely unrelated text", async () => {
false
);
});
+
+test("returns false when text or prompt normalizes to empty string (punctuation only)", async () => {
+ const { matchesDictionaryPrompt } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(matchesDictionaryPrompt("...", "..."), false);
+ assert.equal(matchesDictionaryPrompt("!!!", ",,,"), false);
+ assert.equal(matchesDictionaryPrompt("???", "OpenWhispr, Parakeet"), false);
+ assert.equal(matchesDictionaryPrompt("OpenWhispr, Parakeet", "!!!"), false);
+});