From 4a1f4557910d23aaa6b461a36b938304730794e8 Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Wed, 11 Nov 2026 01:09:18 +0200 Subject: [PATCH] fix(speech): removing filler words no longer joins paragraphs Co-Authored-By: GPT-6.1 Sol --- apps/server/src/speech/SpeechService.test.ts | 18 ++++++++++++++++++ apps/server/src/speech/fillerWords.ts | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/server/src/speech/SpeechService.test.ts b/apps/server/src/speech/SpeechService.test.ts index 41db47f0376a4..4d05d39786240 100644 --- a/apps/server/src/speech/SpeechService.test.ts +++ b/apps/server/src/speech/SpeechService.test.ts @@ -531,6 +531,24 @@ it.effect("unloads after the chosen idle period and reloads on the next recordin ); it.effect.each([ + { + cue: undefined, + remove: true, + text: "First paragraph.\n\nSecond paragraph.", + expected: "First paragraph.\n\nSecond paragraph.", + }, + { + cue: undefined, + remove: true, + text: "First um\n\nuh Second.", + expected: "First\n\nSecond.", + }, + { + cue: undefined, + remove: true, + text: "First um\r\n\r\nuh Second.", + expected: "First\r\n\r\nSecond.", + }, { cue: "um", remove: true, text: "Make it red, um, blue.", expected: "Make it red, um, blue." }, { cue: "uh no", diff --git a/apps/server/src/speech/fillerWords.ts b/apps/server/src/speech/fillerWords.ts index 5061341833c06..e939e275fbc0e 100644 --- a/apps/server/src/speech/fillerWords.ts +++ b/apps/server/src/speech/fillerWords.ts @@ -38,5 +38,8 @@ export function removeSpeechFillerWords( "giu", ); const filtered = text.replace(pattern, (_match, cue: string | undefined) => cue ?? ""); - return filtered.replace(/\s{2,}/g, " ").trim(); + return filtered + .replace(/[^\S\r\n]{2,}/g, " ") + .replace(/[^\S\r\n]*([\r\n])[^\S\r\n]*/g, "$1") + .trim(); }