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(translation): guard empty translation chain results (#1258)
Alcahest Malus Dienheim3110a2fa93e0
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex b96816240..28b5c4c32 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -38,7 +38,11 @@ import {resolveSelfHostedTranscriptionModel,} from "./selfHostedTranscription";import { resolveStreamingFallbackTarget } from "./transcriptionFallback";-import { executeTranslationChain, shouldRunTranslateStep } from "./translationChain";+import {+ executeTranslationChain,+ resolveTranslatedText,+ shouldRunTranslateStep,+} from "./translationChain";import { detectAgentName } from "../config/agentDetection";import {resolveDictationRouteKind,@@ -2267,7 +2271,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);log: { level: "error", channel: "transcription" },},});- processedText = chainResult.text;+ processedText = resolveTranslatedText(processedText, chainResult);}} catch (reasonError) {logger.error(@@ -3876,7 +3880,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);log: { level: "error", channel: "streaming" },},});- finalText = chainResult.text;+ finalText = resolveTranslatedText(finalText, chainResult);usedCloudReasoning = chainResult.usedCloudReasoning || usedCloudReasoning;}} catch (reasonError) {diff --git a/src/helpers/translationChain.js b/src/helpers/translationChain.jsindex f8e15ca8b..bf9d48d8b 100644--- a/src/helpers/translationChain.js+++ b/src/helpers/translationChain.js@@ -47,3 +47,9 @@ export async function executeTranslationChain({return { text: out, usedCloudReasoning };}++// Keep the chain result only when it produced text; an empty/missing result+// preserves the input so a dictation is never overwritten with nothing.+export function resolveTranslatedText(previousText, chainResult) {+ return chainResult?.text ? chainResult.text : previousText;+}diff --git a/test/helpers/translationChain.test.js b/test/helpers/translationChain.test.jsindex 632218a3e..78943d487 100644--- a/test/helpers/translationChain.test.js+++ b/test/helpers/translationChain.test.js@@ -274,3 +274,32 @@ test("shouldRunTranslateStep matrix", async () => {assert.equal(shouldRunTranslateStep("", "en"), true);assert.equal(shouldRunTranslateStep(undefined, "it"), true);});++// Guard used at the batch/cloud call site (processedText): an empty chain result+// must leave the transcription intact; a real result replaces it.+test("resolveTranslatedText: empty chain result keeps processedText", async () => {+ const { resolveTranslatedText } = await load();++ assert.equal(resolveTranslatedText("raw dictation", { text: "" }), "raw dictation");+ assert.equal(resolveTranslatedText("raw dictation", { text: null }), "raw dictation");+ assert.equal(resolveTranslatedText("raw dictation", {}), "raw dictation");+});++test("resolveTranslatedText: non-empty chain result replaces processedText", async () => {+ const { resolveTranslatedText } = await load();++ assert.equal(resolveTranslatedText("raw dictation", { text: "translated" }), "translated");+});++// Guard used at the streaming call site (finalText): same preservation semantics.+test("resolveTranslatedText: empty chain result keeps finalText", async () => {+ const { resolveTranslatedText } = await load();++ assert.equal(resolveTranslatedText("streamed text", { text: "" }), "streamed text");+});++test("resolveTranslatedText: non-empty chain result replaces finalText", async () => {+ const { resolveTranslatedText } = await load();++ assert.equal(resolveTranslatedText("streamed text", { text: "traducido" }), "traducido");+});