Skip to content

Commit 372f044

Browse files
fix(voice): do not offer an unverified fallback model during setup
1 parent 1dc1e71 commit 372f044

3 files changed

Lines changed: 95 additions & 63 deletions

File tree

‎apps/web/src/components/chat/VoiceInputSetup.tsx‎

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export function VoiceInputSetup(props: {
6969
: "System default";
7070
const status = props.status?.supported ? props.status : null;
7171
const model = props.model;
72-
const size = model?.size ?? status?.size;
7372
const progress =
7473
model?.downloaded === undefined ? null : Math.round((model.downloaded / model.size) * 100);
7574
const openSettings = (hash: string) => {
@@ -89,51 +88,51 @@ export function VoiceInputSetup(props: {
8988
<WizardPanel>
9089
{props.step === 0 ? (
9190
<section className="space-y-3 text-sm">
92-
<div className="rounded-lg border border-border/70 bg-card/60 p-4">
93-
<div className="flex items-center justify-between gap-2">
94-
<h3 className="font-medium">
95-
{model?.name ?? status?.model ?? "Transcription model"}
96-
</h3>
97-
{model?.recommended && props.language ? (
98-
<span className="text-xs font-medium text-primary">
99-
Recommended for {languageLabel(props.language)}
100-
</span>
101-
) : null}
102-
</div>
103-
<p className="mt-2 text-muted-foreground">
104-
Download the {size === undefined ? 697 : Math.round(size / 1024 / 1024)} MB model
105-
to {environment?.label ?? "your transcription environment"}. Microphone audio is
106-
sent there for transcription, as chosen in Voice settings.
107-
</p>
108-
<p className="mt-2 text-muted-foreground">
109-
Silero (1.2 MB), used for silence filtering and pause detection, downloads
110-
alongside the speech model. An installed copy is reused.
111-
</p>
112-
{props.downloading ? (
113-
<div role="status" className="mt-4 space-y-1 text-muted-foreground">
114-
<div
115-
role="progressbar"
116-
aria-label="Speech model download progress"
117-
aria-valuemin={0}
118-
aria-valuemax={100}
119-
aria-valuenow={progress ?? undefined}
120-
className="h-1 overflow-hidden rounded-full bg-muted"
121-
>
91+
{model ? (
92+
<div className="rounded-lg border border-border/70 bg-card/60 p-4">
93+
<div className="flex items-center justify-between gap-2">
94+
<h3 className="font-medium">{model.name}</h3>
95+
{model?.recommended && props.language ? (
96+
<span className="text-xs font-medium text-primary">
97+
Recommended for {languageLabel(props.language)}
98+
</span>
99+
) : null}
100+
</div>
101+
<p className="mt-2 text-muted-foreground">
102+
Download the {Math.round(model.size / 1024 / 1024)} MB model to{" "}
103+
{environment?.label ?? "your transcription environment"}. Microphone audio is
104+
sent there for transcription, as chosen in Voice settings.
105+
</p>
106+
<p className="mt-2 text-muted-foreground">
107+
Silero (1.2 MB), used for silence filtering and pause detection, downloads
108+
alongside the speech model. An installed copy is reused.
109+
</p>
110+
{props.downloading ? (
111+
<div role="status" className="mt-4 space-y-1 text-muted-foreground">
122112
<div
123-
className="h-full bg-primary transition-[width] duration-200"
124-
style={{ width: `${progress ?? 0}%` }}
125-
/>
113+
role="progressbar"
114+
aria-label="Speech model download progress"
115+
aria-valuemin={0}
116+
aria-valuemax={100}
117+
aria-valuenow={progress ?? undefined}
118+
className="h-1 overflow-hidden rounded-full bg-muted"
119+
>
120+
<div
121+
className="h-full bg-primary transition-[width] duration-200"
122+
style={{ width: `${progress ?? 0}%` }}
123+
/>
124+
</div>
125+
<p className="text-xs">
126+
{model?.state === "verifying"
127+
? "Verifying download…"
128+
: progress === null
129+
? "Starting download…"
130+
: `${progress}% downloaded`}
131+
</p>
126132
</div>
127-
<p className="text-xs">
128-
{model?.state === "verifying"
129-
? "Verifying download…"
130-
: progress === null
131-
? "Starting download…"
132-
: `${progress}% downloaded`}
133-
</p>
134-
</div>
135-
) : null}
136-
</div>
133+
) : null}
134+
</div>
135+
) : null}
137136
{props.error ? (
138137
<p role="alert" className="text-destructive">
139138
{props.error}
@@ -214,25 +213,27 @@ export function VoiceInputSetup(props: {
214213
{props.step === 0 ? (
215214
<>
216215
<Button variant="outline" onClick={() => openSettings("speech-models")}>
217-
Choose another model or language
216+
{model ? "Choose another model or language" : "Choose a model or language"}
218217
</Button>
219218
{props.downloading ? (
220219
<Button variant="outline" disabled={!canManage} onClick={props.onCancelDownload}>
221220
Cancel download
222221
</Button>
223222
) : null}
224-
<Button
225-
disabled={!canManage || props.downloading || !status}
226-
onClick={props.onDownload}
227-
>
228-
{props.downloading
229-
? "Downloading…"
230-
: props.error
231-
? "Retry download"
232-
: canManage
233-
? "Download model"
234-
: "Ask an environment admin to download"}
235-
</Button>
223+
{model ? (
224+
<Button
225+
disabled={!canManage || props.downloading || !status}
226+
onClick={props.onDownload}
227+
>
228+
{props.downloading
229+
? "Downloading…"
230+
: props.error
231+
? "Try again"
232+
: canManage
233+
? "Download model"
234+
: "Ask an environment admin to download"}
235+
</Button>
236+
) : null}
236237
</>
237238
) : (
238239
<>

‎apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const mocks = vi.hoisted(() => ({
3232
modelState: "ready" as "ready" | "missing-model",
3333
statusModelId: "test-model",
3434
models: [] as EnvironmentSpeechModel[],
35+
catalogOffline: false,
3536
download: vi.fn<(modelId: string) => Promise<void>>(),
3637
selected: [] as string[],
3738
selectionFails: false,
@@ -125,7 +126,11 @@ vi.mock("@t3tools/client-runtime/voice-input", async (importOriginal) => ({
125126
if (mocks.selectionFails) throw new Error("selection failed");
126127
return { models: mocks.models };
127128
}),
128-
getEnvironmentSpeechModels: () => Effect.sync(() => ({ models: mocks.models })),
129+
getEnvironmentSpeechModels: () =>
130+
Effect.sync(() => {
131+
if (mocks.catalogOffline) throw new Error("Catalog offline");
132+
return { models: mocks.models };
133+
}),
129134
postProcessEnvironmentTranscript: (
130135
prepared: PreparedConnection,
131136
transcript: string,
@@ -193,6 +198,7 @@ function setup(options: { readonly destination?: string | null } = {}) {
193198
mocks.modelState = "ready";
194199
mocks.statusModelId = "test-model";
195200
mocks.models = [];
201+
mocks.catalogOffline = false;
196202
mocks.download.mockReset();
197203
mocks.selected = [];
198204
mocks.selectionFails = false;
@@ -331,6 +337,8 @@ it("retries a failed transcription on the same chosen environment", async () =>
331337
it("reopens setup after reconnecting during a download and ignores its stale completion", async () => {
332338
setup({ destination: "env-a" });
333339
mocks.modelState = "missing-model";
340+
mocks.settings = { speechLanguage: "en" };
341+
mocks.models = [catalogModel(mocks.statusModelId, ["en"], true)];
334342
let finishDownload!: () => void;
335343
mocks.download.mockReturnValue(
336344
new Promise<void>((resolve) => {
@@ -413,6 +421,24 @@ it.each([
413421
},
414422
);
415423

424+
it.each([true, false])(
425+
"never downloads the English default when no German recommendation is available (catalog offline: %s)",
426+
async (offline) => {
427+
setup({ destination: "env-a" });
428+
mocks.settings = { speechLanguage: "de" };
429+
mocks.modelState = "missing-model";
430+
mocks.statusModelId = "english";
431+
mocks.models = [catalogModel("english", ["en"], true)];
432+
mocks.catalogOffline = offline;
433+
await using _screen = await render(<Probe />);
434+
await act(() => mocks.voice.start());
435+
expect(mocks.voice.setup.open).toBe(true);
436+
await act(() => mocks.voice.setup.download());
437+
expect(mocks.download).not.toHaveBeenCalled();
438+
expect(mocks.voice.setup.error).toBeTruthy();
439+
},
440+
);
441+
416442
it.each([
417443
["selects the offered model once its download installed it", "installed", ["german"], null],
418444
[

‎apps/web/src/speech/useEnvironmentSpeechInput.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export function useEnvironmentSpeechInput(input: HookInput) {
365365
};
366366
}, [prepared]);
367367
const currentStatus = status?.prepared === prepared ? status.value : null;
368-
const setupModelId = setup.model?.id ?? (currentStatus?.supported ? currentStatus.modelId : null);
368+
const setupModelId = setup.model?.id;
369369

370370
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- polls download progress while the setup dialog owns an active model download
371371
useEffect(() => {
@@ -379,7 +379,7 @@ export function useEnvironmentSpeechInput(input: HookInput) {
379379
.then((result) => {
380380
if (disposed) return;
381381
const model = result.models.find((candidate) => candidate.id === setupModelId) ?? null;
382-
setSetup((current) => ({ ...current, model }));
382+
if (model) setSetup((current) => ({ ...current, model }));
383383
})
384384
.catch(() => undefined)
385385
.finally(() => {
@@ -450,12 +450,12 @@ export function useEnvironmentSpeechInput(input: HookInput) {
450450
if (!stillCurrent()) return;
451451
setStatus({ prepared, value: latestStatus });
452452
if (latestStatus.supported && latestStatus.state === "missing-model") {
453-
const { models } = await runEnvironmentSpeech(getEnvironmentSpeechModels(prepared)).catch(
454-
() => ({ models: [] }),
453+
const catalog = await runEnvironmentSpeech(getEnvironmentSpeechModels(prepared)).catch(
454+
() => null,
455455
);
456456
if (!stillCurrent()) return;
457457
setQueuedStart(null);
458-
const choice = chooseSetupSpeechModel(models, {
458+
const choice = chooseSetupSpeechModel(catalog?.models ?? [], {
459459
selectedModelId: latestStatus.modelId,
460460
intent: latestRef.current.clientSettings.speechLanguage,
461461
preferred: preferredSpeechLanguages(),
@@ -465,6 +465,11 @@ export function useEnvironmentSpeechInput(input: HookInput) {
465465
open: true,
466466
model: choice?.model ?? null,
467467
language: choice?.language ?? null,
468+
error: choice
469+
? null
470+
: catalog
471+
? "No model matches your language. Choose a model or change the language in Voice settings."
472+
: "Could not load transcription models. Check the connection and try again in Voice settings.",
468473
});
469474
return;
470475
}

0 commit comments

Comments
 (0)