The best way to control Claude Code, Codex and more from any computer or phone
fix(server): dictionary spellings apply next to Chinese and Japanese text (#31780)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Zedong Peng committed
Nov 15, 2026 at 11:25 UTC
031ee2dd2b8097f6eb8a8f79cf133356623ef1c7
2 files changed
+15
-6
apps/server/src/speech/SpeechService.test.ts
+6
-2
@@ -450,14 +450,18 @@ it.effect("honors exact aliases and phrase boundaries in batch and streamed text
450
{ term: "McDonald’s", aliases: [] },
451
{ term: "King’s Cross", aliases: [] },
452
{ term: "C#", aliases: [] },
453
+ { term: "React", aliases: ["瑞安特"] },
454
+ { term: "Kubernetes", aliases: [] },
455
],
456
};
457
const spoken =
458
'a test with a i and ay eye. Robert, Roberts. "the publisher" and the publisher. (git hub), git (hub). ' +
457
- "git hub's API, git hub’s API, git’s hub, mac donald's menu, king's cross. vitamin c and plan c.";
459
+ "git hub's API, git hub’s API, git’s hub, mac donald's menu, king's cross. vitamin c and plan c. " +
460
+ "我用github和瑞安特,部署到kubernetis上。Robert用git hub。githubで管理する。";
461
const expected =
462
"a test with AI and AI. Bob, Roberts. O'Reilly and the publisher. (GitHub), git (hub). " +
460
- "GitHub's API, GitHub’s API, git’s hub, McDonald’s menu, King’s Cross. vitamin c and plan c.";
463
+ "GitHub's API, GitHub’s API, git’s hub, McDonald’s menu, King’s Cross. vitamin c and plan c. " +
464
+ "我用GitHub和React,部署到Kubernetes上。Bob用GitHub。GitHubで管理する。";
465
native.transcribe.mockResolvedValueOnce({ text: spoken });
466
native.finish.mockResolvedValueOnce(spoken);
467
expect(yield* speech.transcribe(pcm(), options)).toBe(expected);
apps/server/src/speech/customWords.ts
+9
-4
@@ -1,5 +1,11 @@
1
import type { SpeechCustomWords } from "@t3tools/contracts";
2
3
+// These scripts are written without spaces, so a neighbor in one of them still ends a word.
4
+const UNSPACED_SCRIPTS = "\\p{scx=Han}\\p{scx=Hiragana}\\p{scx=Katakana}";
5
+const LETTER = `[[\\p{L}\\p{M}\\p{N}]--[${UNSPACED_SCRIPTS}]]`;
6
+const WORD_CHARACTER = `[[\\p{L}\\p{M}\\p{N}\\p{Pc}]--[${UNSPACED_SCRIPTS}]]`;
7
+const TOKEN = new RegExp(`${LETTER}(?:[^\\s${UNSPACED_SCRIPTS}]*${LETTER})?`, "gv");
8
+
9
/** Fuzzy-matches preferred terms and rewrites aliases to their preferred spelling. */
10
export function makeSpeechTextCorrector(
11
words: readonly string[],
@@ -112,7 +118,7 @@ export function makeSpeechTextCorrector(
118
const apply = (text: string): string => {
119
if (keys.length === 0) return text;
120
// Leave surrounding punctuation in the source; only horizontal whitespace can join words.
115
- const tokens = [...text.matchAll(/[\p{L}\p{M}\p{N}](?:\S*[\p{L}\p{M}\p{N}])?/gu)]
121
+ const tokens = [...text.matchAll(TOKEN)]
122
.filter(([word]) => /^[\p{L}\p{M}\p{N}'’-]+$/u.test(word))
123
.map((match) => ({
124
value: match[0],
@@ -168,10 +174,9 @@ export function makeSpeechTextCorrector(
174
const lookup = new Map(
175
spellings.map(({ spelling, term }) => [spelling.toLocaleLowerCase(), term]),
176
);
171
- const word = "[\\p{L}\\p{M}\\p{N}\\p{Pc}]";
177
const pattern = new RegExp(
173
- `(?<!${word})(?:${spellings.map(({ spelling }) => escapePattern(spelling)).join("|")})(?!${word})`,
174
- "giu",
178
+ `(?<!${WORD_CHARACTER})(?:${spellings.map(({ spelling }) => escapePattern(spelling)).join("|")})(?!${WORD_CHARACTER})`,
179
+ "giv",
180
);
181
return (text: string) => {
182
let output = "";