Skip to content

Commit 930f636

Browse files
fix(mobile): tighten voice locale regression coverage and fallback guidance
1 parent e6a7145 commit 930f636

5 files changed

Lines changed: 22 additions & 21 deletions

File tree

‎apps/mobile/src/native/voiceTranscription.ios.test.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ describe("getLocalVoiceTranscriber", () => {
9090
signal: new AbortController().signal,
9191
});
9292

93-
expect(mocks.getSetting).toHaveBeenCalledWith("AppleLanguages");
94-
expect(mocks.prepare).toHaveBeenCalledWith("de-DE");
93+
expect(mocks.prepare.mock.calls).toEqual([["de-DE"]]);
9594
expect(prepared.locale).toBe("de_DE");
9695
});
9796

9897
it("falls back to the next language when one is unsupported", async () => {
9998
mocks.getSetting.mockReturnValue(["gsw-CH", "de-CH"]);
100-
mocks.prepare.mockImplementation(async (locale) => {
101-
if (locale === "gsw-CH")
102-
throw Object.assign(new Error(), { code: "AppleTranscriptionUnsupportedLocale" });
103-
return "de_CH";
104-
});
99+
mocks.prepare
100+
.mockRejectedValueOnce(
101+
Object.assign(new Error(), { code: "AppleTranscriptionUnsupportedLocale" }),
102+
)
103+
.mockResolvedValueOnce("de_CH");
105104

106105
const prepared = await getLocalVoiceTranscriber()!.prepare({
107106
signal: new AbortController().signal,

‎apps/mobile/src/native/voiceTranscription.ios.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
type VoiceTranscriptionOptions,
1111
} from "@t3tools/client-runtime/voice-input";
1212

13-
/**
14-
* The app only ships English, so its locale is e.g. "en-DE" on a German iPhone.
15-
* Speech follows the user's preferred languages instead (`AppleLanguages` holds
16-
* the same list as `Locale.preferredLanguages`), falling back to the app locale.
17-
*/
13+
// The English-only app locale can differ from the user's preferred spoken languages.
1814
function getPreferredLocales(): string[] {
1915
const languages = Settings.get("AppleLanguages");
2016
const preferred = Array.isArray(languages)

‎docs/user/composer.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ On supported iPhones with iOS 26 or later, use the composer's microphone to reco
178178
then confirm to transcribe. Text is inserted where your selection was when
179179
recording started, ready for you to review and edit before sending.
180180

181-
Transcription uses the first language in your iPhone's preferred language list
182-
(Settings > General > Language & Region) that Apple's speech model supports,
183-
or English if none is supported.
181+
Transcription tries your iPhone's preferred languages in order
182+
(Settings > General > Language & Region), then the app's language. If Apple's speech
183+
model supports none of them, voice input reports that the language is unavailable.
184184

185185
The first use may download Apple's speech model and needs a network connection.
186186
Later transcription works offline for that language. Recordings can be up to five

‎packages/client-runtime/src/voice-input/controller.test.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ describe("resolveTranscriptCommit", () => {
135135
});
136136

137137
it("adds word spacing for other space-delimited languages", () => {
138-
const atEnd = draft({ text: "Schön", selection: { start: 5, end: 5 } });
139-
expect(resolveTranscriptCommit(atEnd, atEnd, "Grüße", "de-DE")).toMatchObject({
138+
const atStart = draft({ text: "Änderungen", selection: { start: 0, end: 0 } });
139+
expect(resolveTranscriptCommit(atStart, atStart, "Weitere", "de_DE")).toMatchObject({
140140
kind: "commit",
141-
text: "Schön Grüße",
141+
text: "Weitere Änderungen",
142142
});
143143

144144
const combiningMark = draft({ text: "नमस्ते", selection: { start: 6, end: 6 } });
@@ -148,13 +148,20 @@ describe("resolveTranscriptCommit", () => {
148148
});
149149
});
150150

151-
it("does not add English boundary spaces to CJK or selected inline text", () => {
152-
const cjk = draft({ text: "修正キャッシュ", selection: { start: 8, end: 8 } });
151+
it("preserves spaceless languages and selected inline text", () => {
152+
const text = "修正キャッシュ";
153+
const cjk = draft({ text, selection: { start: text.length, end: text.length } });
153154
expect(resolveTranscriptCommit(cjk, cjk, "テストも", "ja-JP")).toMatchObject({
154155
kind: "commit",
155156
text: "修正キャッシュテストも",
156157
});
157158

159+
const thai = draft({ text: "โลก", selection: { start: 0, end: 0 } });
160+
expect(resolveTranscriptCommit(thai, thai, "สวัสดี", "th-TH")).toMatchObject({
161+
kind: "commit",
162+
text: "สวัสดีโลก",
163+
});
164+
158165
const selected = draft({ text: "one $skill two", selection: { start: 4, end: 10 } });
159166
expect(resolveTranscriptCommit(selected, selected, "new", "en-US")).toMatchObject({
160167
kind: "commit",

‎packages/client-runtime/src/voice-input/controller.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ type TranscriptCommitResult =
7070
| { readonly kind: "stale" }
7171
| { readonly kind: "empty" };
7272

73-
/** Languages written without spaces between words. */
7473
const WORD_SPACELESS_LANGUAGES = new Set(["ja", "zh", "yue", "th", "lo", "km", "my"]);
7574

7675
export function resolveTranscriptCommit(

0 commit comments

Comments
 (0)