fix(voice): browser speech recognition on Android no longer repeats phrases
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m40s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-31 13:16:04 +01:00
1 parent 32bb92ecf8
commit 8c2bfe2cee
7 files changed
+63 -8

No files matched your search

+24
View File
@@ -186,3 +186,27 @@ export class VoiceRecorder {
this.analyser = null;
}
}
/**
* Text of one speech recognition session from its results. Desktop browsers deliver consecutive
* pieces ("Test 1 2 3", " und weiter"); Chrome on Android also keeps the growing interim states of
* the same phrase as results of their own ("Test", "Test", "Test 1 2 3"). A result that only
* continues the one before it therefore replaces it instead of being appended.
*/
export function joinSpeechResults(transcripts: string[]): string {
const norm = (s: string) => s.trim().toLowerCase();
let text = '';
let last = '';
for (const t of transcripts) {
if (!t) continue;
if (last && norm(t).startsWith(norm(last))) {
text = text.slice(0, text.length - last.length) + t; // grown version of the same phrase
} else if (last && norm(last).startsWith(norm(t))) {
continue; // an earlier, shorter state of it
} else {
text += t;
}
last = t;
}
return text;
}