Skip to content

Commit 174b9c4

Browse files
fix(server): require exact dictation matches for short terms
1 parent 814d034 commit 174b9c4

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ it.effect("honors exact aliases and phrase boundaries in batch and streamed text
178178
const options = {
179179
...DEFAULT_SPEECH_TRANSCRIPTION_OPTIONS,
180180
speechCustomWords: [
181+
{ term: "AI", aliases: ["ay eye"] },
181182
{ term: "Bob", aliases: ["Robert"] },
182183
{ term: "Roberts", aliases: [] },
183184
{ term: "O'Reilly", aliases: ['"the publisher"'] },
@@ -187,10 +188,10 @@ it.effect("honors exact aliases and phrase boundaries in batch and streamed text
187188
],
188189
};
189190
const spoken =
190-
'Robert, Roberts. "the publisher" and the publisher. (git hub), git (hub). ' +
191+
'a test with a i and ay eye. Robert, Roberts. "the publisher" and the publisher. (git hub), git (hub). ' +
191192
"git hub's API, git hub’s API, git’s hub, mac donald's menu, king's cross.";
192193
const expected =
193-
"Bob, Roberts. O'Reilly and the publisher. (GitHub), git (hub). " +
194+
"a test with AI and AI. Bob, Roberts. O'Reilly and the publisher. (GitHub), git (hub). " +
194195
"GitHub's API, GitHub’s API, git’s hub, McDonald’s menu, King’s Cross.";
195196
native.transcribe.mockResolvedValueOnce({ text: spoken });
196197
native.finish.mockResolvedValueOnce(spoken);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function makeSpeechTextCorrector(
9090
if (inner > 0 && inner > innerPossessives(custom.word)) continue;
9191
const keepSuffix = suffix !== "" && !possessive.test(custom.word);
9292
const candidate = keepSuffix ? stem : key;
93+
if (Math.min(candidate.length, custom.key.length) < 4 && candidate !== custom.key) continue;
9394
const longest = Math.max(candidate.length, custom.key.length);
9495
if (Math.abs(candidate.length - custom.key.length) > Math.max(longest * 0.25, 2)) continue;
9596
const distance = editDistance(candidate, custom.key) / longest;

0 commit comments

Comments
 (0)