Skip to content

Commit 39f465a

Browse files
fix(server): a C# dictionary term no longer rewrites standalone letters (#35700)
1 parent 2e741fc commit 39f465a

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/server/src/speech/SpeechService.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,15 @@ it.effect("honors exact aliases and phrase boundaries in batch and streamed text
449449
{ term: "GitHub", aliases: [] },
450450
{ term: "McDonald’s", aliases: [] },
451451
{ term: "King’s Cross", aliases: [] },
452+
{ term: "C#", aliases: [] },
452453
],
453454
};
454455
const spoken =
455456
'a test with a i and ay eye. Robert, Roberts. "the publisher" and the publisher. (git hub), git (hub). ' +
456-
"git hub's API, git hub’s API, git’s hub, mac donald's menu, king's cross.";
457+
"git hub's API, git hub’s API, git’s hub, mac donald's menu, king's cross. vitamin c and plan c.";
457458
const expected =
458459
"a test with AI and AI. Bob, Roberts. O'Reilly and the publisher. (GitHub), git (hub). " +
459-
"GitHub's API, GitHub’s API, git’s hub, McDonald’s menu, King’s Cross.";
460+
"GitHub's API, GitHub’s API, git’s hub, McDonald’s menu, King’s Cross. vitamin c and plan c.";
460461
native.transcribe.mockResolvedValueOnce({ text: spoken });
461462
native.finish.mockResolvedValueOnce(spoken);
462463
expect(yield* speech.transcribe(pcm(), options)).toBe(expected);

‎apps/server/src/speech/customWords.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ export function makeSpeechTextCorrector(
7171

7272
const customWordKeys = (words: readonly string[]): CustomWordKey[] =>
7373
words.flatMap((word) => {
74-
const keys = [matchKey(word)];
75-
if (word.includes("&")) keys.push(matchKey(word.replaceAll("&", " and ")));
74+
const sources = [word];
75+
if (word.includes("&")) sources.push(word.replaceAll("&", " and "));
76+
const keys = sources.flatMap((source) => {
77+
const key = matchKey(source);
78+
// A term that loses its symbols to one letter (C# -> c) would claim every standalone letter.
79+
const lostSymbols = key !== source.replace(/\s+/gu, "").toLocaleLowerCase();
80+
return key.length < 2 && lostSymbols ? [] : [key];
81+
});
7682
return [...new Set(keys)].filter(isAsciiKey).map((key) => ({ word, key }));
7783
});
7884

0 commit comments

Comments
 (0)