mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
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.
This commit is contained in:
@@ -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' }],
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -24,11 +24,13 @@ const WORD_CHAR = String.raw`[\p{L}\p{N}\p{M}_/'\u2019\-]`
|
||||
const standalone = (fillers: string): string =>
|
||||
String.raw`(?<!${WORD_CHAR}|${WORD_CHAR}\.)(${fillers})(?!${WORD_CHAR}|\.${WORD_CHAR})(?!\s*[?\uFF1F!\uFF01])`
|
||||
// The comma or ellipsis after a filler goes with it.
|
||||
const TRAILING_PAUSE = String.raw`(?:\s*(?:[,\uFF0C\u3001\u2026]|\.{3}))?\s*`
|
||||
const TRAILING_PAUSE = String.raw`(?:\s*(?<pause>[,\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()
|
||||
|
||||
Reference in New Issue
Block a user