From 78ccc737f3dfe641f7971892a7dd3cfaaed5f8d2 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:36:27 +0000 Subject: [PATCH] fix(dictation): drop both commas around a filler removed mid-sentence (#40177) "I think we should, uh, ship it" became "I think we should, ship it": the filler's own comma went with it, but the one before it stayed. When a pause follows the filler too, the comma before it now goes as well. --- src/main/speech/stt-service.test.ts | 2 +- src/shared/dictation-filler-words.test.ts | 19 ++++++++----------- src/shared/dictation-filler-words.ts | 7 ++++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/speech/stt-service.test.ts b/src/main/speech/stt-service.test.ts index b0bcdcb323a..39b4ade9f76 100644 --- a/src/main/speech/stt-service.test.ts +++ b/src/main/speech/stt-service.test.ts @@ -260,7 +260,7 @@ describe('SttService', () => { expect(cleaned.mock.calls.slice(1)).toEqual([ [{ type: 'partial', text: 'Ship' }], - [{ type: 'final', text: 'Ship it, today.' }] + [{ type: 'final', text: 'Ship it today.' }] ]) expect(raw.mock.calls.slice(1)).toEqual([ [{ type: 'partial', text: 'Um, ship' }], diff --git a/src/shared/dictation-filler-words.test.ts b/src/shared/dictation-filler-words.test.ts index 491da992928..ccc0abe9ee7 100644 --- a/src/shared/dictation-filler-words.test.ts +++ b/src/shared/dictation-filler-words.test.ts @@ -4,7 +4,7 @@ import { createDictationTextPipeline } from './dictation-text-pipeline' describe('removeFillerWords', () => { it.each([ - ['en', 'Um, I think we should, uh, ship it.', 'I think we should, ship it.'], + ['en', 'Um, I think we should, uh, ship it.', 'I think we should ship it.'], ['en', 'Let me check umm the logs.', 'Let me check the logs.'], ['en', 'Yes. Uh. No.', 'Yes. No.'], ['en', 'We should ship it, hmm', 'We should ship it'], @@ -12,16 +12,13 @@ describe('removeFillerWords', () => { ['en', 'We should ship, um.', 'We should ship.'], ['en', 'um so we ship', 'so we ship'], ['en', 'Um, iPhone builds first.', 'iPhone builds first.'], - [ - 'de', - 'Äh, das ist um fünf Uhr fertig, ähm, glaube ich.', - 'Das ist um fünf Uhr fertig, glaube ich.' - ], + ['de', 'Äh, das ist um fünf Uhr fertig.', 'Das ist um fünf Uhr fertig.'], ['es', 'Ehm, creo que em funciona.', 'Creo que funciona.'], + ['de', 'Das ist, ähm, um fünf Uhr fertig.', 'Das ist um fünf Uhr fertig.'], ['ru', 'Э, ну, давай так.', 'Ну, давай так.'], - ['ja', 'えーと、明日の会議は、うーん、十時です。', '明日の会議は、十時です。'], + ['ja', 'えーと、明日の会議は、うーん、十時です。', '明日の会議は十時です。'], ['ko', '음, 내일 회의는 흠, 열 시예요.', '내일 회의는 열 시예요.'], - ['zh', '嗯,我觉得,呃,这个可以。', '我觉得,这个可以。'], + ['zh', '嗯,我觉得,呃,这个可以。', '我觉得这个可以。'], ['zh', '額,我覺得可以。', '我覺得可以。'], ['en', 'UM I THINK WE SHOULD UH SHIP IT', 'I THINK WE SHOULD SHIP IT'] ])('%s: %s', (language, text, expected) => { @@ -43,8 +40,8 @@ describe('removeFillerWords', () => { }) it('uses only fillers that are no word elsewhere when the language is unknown', () => { - expect(removeFillerWords('Um carro, uh, azul.', undefined)).toBe('Um carro, azul.') - expect(removeFillerWords('Er kommt, hmm, morgen.', undefined)).toBe('Er kommt, morgen.') + expect(removeFillerWords('Um carro, uh, azul.', undefined)).toBe('Um carro azul.') + expect(removeFillerWords('Er kommt, hmm, morgen.', undefined)).toBe('Er kommt morgen.') expect(removeFillerWords('呃,好的。', undefined)).toBe('呃,好的。') }) }) @@ -52,7 +49,7 @@ describe('removeFillerWords', () => { describe('createDictationTextPipeline', () => { it('reads the language from a single-language model before the setting', () => { const clean = createDictationTextPipeline({ language: 'en' }, { dictationLanguage: 'de' }) - expect(clean?.('Äh, um, ship it.')).toBe('Äh, ship it.') + expect(clean?.('Äh, um, ship it.')).toBe('Äh ship it.') }) it('reads the language from the setting for a multilingual model that takes it', () => { diff --git a/src/shared/dictation-filler-words.ts b/src/shared/dictation-filler-words.ts index 13ce8e5acc5..4b901d3a58e 100644 --- a/src/shared/dictation-filler-words.ts +++ b/src/shared/dictation-filler-words.ts @@ -24,11 +24,13 @@ const WORD_CHAR = String.raw`[\p{L}\p{N}\p{M}_/'\u2019\-]` const standalone = (fillers: string): string => String.raw`(?[,\uFF0C\u3001\u2026]|\.{3}))?\s*` const SENTENCE_END_CHARS = '.!?。!?' const SENTENCE_END_RE = new RegExp(`^[${SENTENCE_END_CHARS}]+\\s*`, 'u') // A comma left in front of a removed filler that ended the sentence or the text. const TRAILING_SOFT_PUNCTUATION_RE = /[\s,\uFF0C\u3001]+$/u +// The comma before a filler that a pause also follows, keeping the space after it. +const COMMA_BEFORE_PAUSED_FILLER_RE = /[,\uFF0C\u3001](\s*)$/u const NON_LATIN_LETTER_RE = /(?=\p{L})\P{Script=Latin}/u function fillerPattern(languages: readonly string[] | undefined, text: string): RegExp | null { @@ -87,6 +89,9 @@ export function removeFillerWords(text: string, languages: readonly string[] | u cursor += sentenceEnd[0].length } else if (sentenceEnd) { out = out.replace(TRAILING_SOFT_PUNCTUATION_RE, '') + } else if (match.groups?.pause) { + // "we should, uh, ship" set the filler off on both sides; neither comma belongs to the sentence. + out = out.replace(COMMA_BEFORE_PAUSED_FILLER_RE, '$1') } // Only a capitalised "Um" began a sentence the next word now begins. capitalizeNext ||= atSentenceStart && filler.charAt(0) !== filler.charAt(0).toLowerCase()