Skip to content

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

fix(dictation): skip the dictionary-echo check when the provider never got the dictionary (#1929)

Aditya Painuli4d28a19b7f2e
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 28e53780f..3d600cebc 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -88,6 +88,7 @@ import {
DICTIONARY_ECHO_CODE,
dictionaryEchoError,
matchesDictionaryPrompt,
+ payloadSendsDictionaryBias,
} from "../utils/dictionaryEchoFilter.js";
import { getDictionaryHintWords } from "../utils/snippets";
import { normalizeAgentSelectionContext } from "../utils/agentSelectionContext";
@@ -3346,19 +3347,18 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
throw new Error(`${proxySpec.displayName} transcription is unavailable in this window`);
}
const apiCallStart = performance.now();
- const result = await call(
- proxySpec.buildPayload({
- audioBuffer: await optimizedAudio.arrayBuffer(),
- model,
- language,
- apiSettings,
- dictionaryPrompt: this.getWhisperPrompt(apiSettings),
- keyterms: this.getKeyterms()
- .map((t) => t.trim().slice(0, 50))
- .filter(Boolean)
- .slice(0, 100),
- })
- );
+ const proxyPayload = proxySpec.buildPayload({
+ audioBuffer: await optimizedAudio.arrayBuffer(),
+ model,
+ language,
+ apiSettings,
+ dictionaryPrompt: this.getWhisperPrompt(apiSettings),
+ keyterms: this.getKeyterms()
+ .map((t) => t.trim().slice(0, 50))
+ .filter(Boolean)
+ .slice(0, 100),
+ });
+ const result = await call(proxyPayload);
if (result?.error) {
const err = new Error(result.error);
if (result.code) err.code = result.code;
@@ -3369,7 +3369,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
if (!proxyText?.trim()) {
throw new Error(`No text transcribed - ${proxySpec.displayName} response was empty`);
}
- if (this.isDictionaryEcho(proxyText)) {
+ if (payloadSendsDictionaryBias(proxyPayload) && this.isDictionaryEcho(proxyText)) {
throw dictionaryEchoError();
}
timings.transcriptionProcessingDurationMs = Math.round(performance.now() - apiCallStart);
diff --git a/src/utils/dictionaryEchoFilter.js b/src/utils/dictionaryEchoFilter.js
index afb264624..bb20e2c8f 100644
--- a/src/utils/dictionaryEchoFilter.js
+++ b/src/utils/dictionaryEchoFilter.js
@@ -126,6 +126,18 @@ export function isLikelyDictionaryPromptFragment(text, dictionaryPrompt) {
return analyzeDictionaryPromptFragment(text, dictionaryPrompt).isPromptFragment;
}
+// A provider that never received the dictionary can't echo it back: the echo
+// check only applies when the outgoing payload actually carried dictionary
+// bias (Tinfoil's `prompt`, Mistral's `contextBias`, xAI/Gemini's `keyterms`).
+// Corti's payload has none of these, so the check is skipped there (#1759).
+export function payloadSendsDictionaryBias(payload) {
+ if (!payload || typeof payload !== "object") return false;
+ if (typeof payload.prompt === "string" && payload.prompt.trim()) return true;
+ if (Array.isArray(payload.contextBias) && payload.contextBias.length > 0) return true;
+ if (Array.isArray(payload.keyterms) && payload.keyterms.length > 0) return true;
+ return false;
+}
+
export const DICTIONARY_ECHO_CODE = "DICTIONARY_ECHO";
// Keeps the "No audio detected" message so the existing message comparisons and
diff --git a/test/helpers/audioManagerCloudFallbackPolicy.test.js b/test/helpers/audioManagerCloudFallbackPolicy.test.js
index b900e60a0..4c845e1c3 100644
--- a/test/helpers/audioManagerCloudFallbackPolicy.test.js
+++ b/test/helpers/audioManagerCloudFallbackPolicy.test.js
@@ -500,6 +500,71 @@ test("proxied providers dispatch through the registry", async (t) => {
});
});
+test("proxied providers only run the dictionary-echo check when they sent bias", async (t) => {
+ const { window, setSettings, createManager } = await loadAudioManager(t, {
+ cachePrefix: "openwhispr-proxy-echo-gate-test-",
+ settingsKey: "__proxyEchoGateSettings",
+ });
+ captureFetch(t, rejectFetch("proxied providers must not fetch from the renderer"));
+
+ // [provider, preload channel, whether buildPayload carries dictionary bias]
+ const proxied = [
+ ["tinfoil", "proxyTinfoilTranscription", true],
+ ["mistral", "proxyMistralTranscription", true],
+ ["gemini", "proxyGeminiTranscription", true],
+ ["xai", "proxyXaiTranscription", true],
+ ["corti", "proxyCortiTranscription", false],
+ ];
+ for (const [, channel] of proxied) {
+ window.electronAPI[channel] = async () => ({ text: "Ozempic" });
+ }
+
+ const audioBlob = new Blob([new Uint8Array([1, 2, 3])], { type: "audio/webm" });
+ const settingsFor = (provider) => ({
+ allowLocalFallback: false,
+ cloudTranscriptionProvider: provider,
+ transcriptionMode: "providers",
+ useLocalWhisper: false,
+ });
+ // The matcher's verdict is not under test; forcing it leaves only the gate
+ // (#1759) to decide whether the transcript is discarded.
+ const managerWith = (dictionary) =>
+ createManager({
+ getTranscriptionModel: () => "voxtral-mini-latest",
+ getWhisperPrompt: () => dictionary.join(", ") || null,
+ getKeyterms: () => dictionary,
+ isDictionaryEcho: () => true,
+ });
+
+ await t.test("providers that received the dictionary still discard an echo", async () => {
+ const manager = managerWith(["Ozempic"]);
+ for (const [provider, , sendsBias] of proxied) {
+ if (!sendsBias) continue;
+ setSettings(settingsFor(provider));
+ await assert.rejects(
+ manager.processWithOpenAIAPI(audioBlob),
+ (error) => error.code === "DICTIONARY_ECHO",
+ provider
+ );
+ }
+ });
+
+ await t.test("a provider that never received the dictionary keeps the transcript", async () => {
+ setSettings(settingsFor("corti"));
+ const result = await managerWith(["Ozempic"]).processWithOpenAIAPI(audioBlob);
+ assert.equal(result.rawText, "Ozempic");
+ });
+
+ await t.test("an empty dictionary sends no bias, so no provider can discard", async () => {
+ const manager = managerWith([]);
+ for (const [provider] of proxied) {
+ setSettings(settingsFor(provider));
+ const result = await manager.processWithOpenAIAPI(audioBlob);
+ assert.equal(result.rawText, "Ozempic", provider);
+ }
+ });
+});
+
test("config-error code survives a failed local fallback", async (t) => {
const { window, setSettings, createManager } = await loadAudioManager(t, {
cachePrefix: "openwhispr-fallback-wrap-test-",
diff --git a/test/helpers/dictionaryEchoFilter.test.js b/test/helpers/dictionaryEchoFilter.test.js
index 29c092339..45f81effb 100644
--- a/test/helpers/dictionaryEchoFilter.test.js
+++ b/test/helpers/dictionaryEchoFilter.test.js
@@ -282,3 +282,73 @@ test("a dangling separator does not outweigh non-dictionary words", async () =>
false
);
});
+
+// #1759: the echo check must only run when the outgoing payload actually
+// carried dictionary bias. Payload shapes below mirror what each provider's
+// buildPayload in audioManager.js really produces.
+
+test("payloadSendsDictionaryBias: Corti payload carries no bias field at all", async () => {
+ const { payloadSendsDictionaryBias } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(
+ payloadSendsDictionaryBias({
+ audioBuffer: new ArrayBuffer(4),
+ language: "en",
+ environment: "us",
+ tenant: "clinic",
+ }),
+ false
+ );
+});
+
+test("payloadSendsDictionaryBias: Tinfoil-style prompt string counts as bias", async () => {
+ const { payloadSendsDictionaryBias } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), prompt: "Ozempic, Parakeet" }),
+ true
+ );
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), prompt: " " }),
+ false
+ );
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), prompt: undefined }),
+ false
+ );
+});
+
+test("payloadSendsDictionaryBias: Mistral contextBias tokens count as bias", async () => {
+ const { payloadSendsDictionaryBias } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(
+ payloadSendsDictionaryBias({
+ audioBuffer: new ArrayBuffer(4),
+ model: "voxtral",
+ contextBias: ["Machine", "Learning"],
+ }),
+ true
+ );
+ // empty dictionary: buildPayload omits the field entirely
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), model: "voxtral" }),
+ false
+ );
+});
+
+test("payloadSendsDictionaryBias: xAI/Gemini keyterms count as bias", async () => {
+ const { payloadSendsDictionaryBias } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), keyterms: ["Ozempic"] }),
+ true
+ );
+ assert.equal(payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4) }), false);
+ assert.equal(
+ payloadSendsDictionaryBias({ audioBuffer: new ArrayBuffer(4), keyterms: [] }),
+ false
+ );
+});
+
+test("payloadSendsDictionaryBias: nullish or malformed payloads never enable the check", async () => {
+ const { payloadSendsDictionaryBias } = await import("../../src/utils/dictionaryEchoFilter.js");
+ assert.equal(payloadSendsDictionaryBias(null), false);
+ assert.equal(payloadSendsDictionaryBias(undefined), false);
+ assert.equal(payloadSendsDictionaryBias("prompt"), false);
+});