From 52e4e599b2410ad2f751bd892c08483dc9b837fa Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 04:20:02 +0000 Subject: [PATCH] fix(dictation): take the filler language from what the engine is told, and drop the comma before a final filler --- src/shared/dictation-filler-words.test.ts | 14 ++++++++++++-- src/shared/dictation-filler-words.ts | 15 +++++++++------ src/shared/dictation-text-pipeline.ts | 21 ++++++++++++++------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/shared/dictation-filler-words.test.ts b/src/shared/dictation-filler-words.test.ts index 9854b5ddb25..2a52e021d84 100644 --- a/src/shared/dictation-filler-words.test.ts +++ b/src/shared/dictation-filler-words.test.ts @@ -9,6 +9,7 @@ describe('removeFillerWords', () => { ['en', 'Yes. Uh. No.', 'Yes. No.'], ['en', 'We should ship it, hmm', 'We should ship it'], ['en', 'we should um.', 'we should.'], + ['en', 'We should ship, um.', 'We should ship.'], ['en', 'um so we ship', 'so we ship'], ['en', 'Um, iPhone builds first.', 'iPhone builds first.'], [ @@ -30,6 +31,7 @@ describe('removeFillerWords', () => { ['en', 'The umbrella is humming, uh-huh.'], ['en', 'Hmm? What did you say?'], ['en', 'Ask UM and HMM about it.'], + ['en', 'Open um.txt and set var_um to 3.'], ['ja', 'ええ、そうです。'], ['ko', '음이 너무 높아요.'], ['zh', '金额不对,那个文件也要改。'] @@ -50,14 +52,22 @@ describe('createDictationTextPipeline', () => { expect(clean?.('Äh, um, ship it.')).toBe('Äh, ship it.') }) - it('reads the language from the setting for a multilingual model', () => { + it('reads the language from the setting for a multilingual model that takes it', () => { const clean = createDictationTextPipeline( - { language: 'multilingual' }, + { language: 'multilingual', dictationLanguages: ['de', 'en'] }, { dictationLanguage: 'de' } ) expect(clean?.('Äh, um fünf Uhr.')).toBe('Um fünf Uhr.') }) + it('ignores a language setting the model ignores', () => { + const clean = createDictationTextPipeline( + { language: 'multilingual' }, + { dictationLanguage: 'en' } + ) + expect(clean?.('Er hat um zehn Uhr angerufen.')).toBe('Er hat um zehn Uhr angerufen.') + }) + it('leaves text untouched when filler removal is off', () => { expect(createDictationTextPipeline({ language: 'en' }, { removeFillerWords: false })).toBeNull() }) diff --git a/src/shared/dictation-filler-words.ts b/src/shared/dictation-filler-words.ts index 8aabb6854d2..b5f21735d9b 100644 --- a/src/shared/dictation-filler-words.ts +++ b/src/shared/dictation-filler-words.ts @@ -17,13 +17,16 @@ FILLERS_BY_LANGUAGE.yue = FILLERS_BY_LANGUAGE.zh // For an unknown language: English fillers that are no word elsewhere ("um" is German and Portuguese, "er" German). const LANGUAGE_NEUTRAL_FILLERS = 'u+h+m*|u+m{2,}|e+r+m+|h+m+|m{3,}' -const WORD_CHAR = String.raw`[\p{L}\p{N}\p{M}'’\-]` -// A filler stands alone: no word character touches it, and "hm?" or "eh!" is a question or a call, so it stays. +const WORD_CHAR = String.raw`[\p{L}\p{N}\p{M}_/'’\-]` +// A filler stands alone: nothing joins it to a word (a dot only does inside a name like "um.txt"), +// and "hm?" or "eh!" is a question or a call, so it stays. const STANDALONE = (fillers: string): string => - String.raw`(? -/** The languages the dictated text is in: a single-language model's own, else the user's setting; undefined when unknown. */ -export function dictatedTextLanguages( - model: Pick | undefined, +type DictationTextModel = Pick + +/** The languages the dictated text is in: a single-language model's own, else the one the engine is told; undefined when unknown. */ +function dictatedTextLanguages( + model: DictationTextModel | undefined, setting: string | undefined ): string[] | undefined { - if (model && model.language !== 'multilingual') { + if (!model) { + return undefined + } + if (model.language !== 'multilingual') { // Bilingual models name both, as in 'zh-en'. return model.language.split('-') } - return setting && setting !== DICTATION_LANGUAGE_AUTO ? [setting] : undefined + // The Voice pane disables a setting the model ignores, so a stale one says nothing about what was spoken. + const language = engineDictationLanguage(model, setting) + return language ? [language] : undefined } /** The passes dictated text goes through before anyone sees it, or null when every pass is off. */ export function createDictationTextPipeline( - model: Pick | undefined, + model: DictationTextModel | undefined, settings: Partial | undefined ): ((text: string) => string) | null { if (settings?.removeFillerWords === false) {