Skip to content

Commit bf7c9b2

Browse files
fix(web): keep download progress errors quiet
1 parent 3126a7e commit bf7c9b2

4 files changed

Lines changed: 109 additions & 31 deletions

File tree

‎apps/web/src/components/settings/VoiceSettingsPanel.browser.test.tsx‎

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,88 @@
1-
import { EnvironmentId } from "@t3tools/contracts";
1+
import { PrimaryConnectionTarget } from "@t3tools/client-runtime/connection";
2+
import { EnvironmentId, type EnvironmentSpeechModel } from "@t3tools/contracts";
23
import { expect, it, vi } from "vite-plus/test";
34
import { userEvent } from "vite-plus/test/browser";
45
import { render } from "../../../test/render";
56
import { __setClientSettingsForTests, getClientSettings } from "../../hooks/useSettings";
7+
import { useVoiceTranscriptionDestination } from "../../speech/useEnvironmentSpeechInput";
68
import { chooseAudioDestination, chooseTranscriptCleanup } from "../../speech/voiceConsent";
9+
import { toastManager } from "../ui/toast";
710
import { SettingsScopeProvider } from "./SettingsScopeContext";
811
import { SpeechLanguageSelect } from "./SpeechLanguageSelect";
912
import { VoiceSettingsPanel } from "./VoiceSettingsPanel";
1013

14+
vi.mock(import("../../speech/useEnvironmentSpeechInput"), { spy: true });
15+
16+
it("recovers from a failed download progress poll without notifying, but reports a failed initial load", async () => {
17+
const target = new PrimaryConnectionTarget({
18+
environmentId: EnvironmentId.make("voice-progress"),
19+
label: "Test environment",
20+
httpBaseUrl: window.location.origin,
21+
wsBaseUrl: "ws://localhost",
22+
});
23+
const prepared = { ...target, target, socketUrl: target.wsBaseUrl, httpAuthorization: null };
24+
const model: EnvironmentSpeechModel = {
25+
id: "tiny",
26+
name: "Tiny",
27+
description: "",
28+
size: 100,
29+
languages: ["en"],
30+
accuracy: 1,
31+
speed: 1,
32+
recommended: false,
33+
supportsStreaming: false,
34+
supportsTranslation: false,
35+
supportsLanguageDetection: false,
36+
active: false,
37+
state: "downloading",
38+
};
39+
const status = {
40+
supported: true,
41+
state: "missing-model",
42+
modelId: model.id,
43+
model: model.name,
44+
size: model.size,
45+
supportsStreaming: false,
46+
supportsTranslation: false,
47+
acceleration: "cpu",
48+
modelUnloadTimeout: "never",
49+
gpuDevices: [],
50+
};
51+
const unavailable = () => new Response(null, { status: 503 });
52+
const readModels = vi
53+
.fn(unavailable)
54+
.mockImplementationOnce(() => Response.json({ models: [model] }))
55+
.mockImplementationOnce(unavailable)
56+
.mockImplementationOnce(() => Response.json({ models: [{ ...model, state: "installed" }] }));
57+
const fetch = globalThis.fetch;
58+
using _network = vi.spyOn(globalThis, "fetch").mockImplementation((input, init) => {
59+
const url = new URL(input instanceof Request ? input.url : input, window.location.href);
60+
if (url.pathname === "/api/voice/status") return Promise.resolve(Response.json(status));
61+
if (url.pathname === "/api/voice/models") return Promise.resolve(readModels());
62+
return fetch(input, init);
63+
});
64+
using notify = vi.spyOn(toastManager, "add").mockReturnValue("test");
65+
await vi.mocked(useVoiceTranscriptionDestination).withImplementation(
66+
() => ({ environmentId: target.environmentId, label: target.label, grantId: "test", prepared }),
67+
async () => {
68+
const panel = (key: string) => (
69+
<SettingsScopeProvider search={{}} onChange={() => {}}>
70+
<VoiceSettingsPanel key={key} />
71+
</SettingsScopeProvider>
72+
);
73+
await using screen = await render(panel("first"));
74+
await expect.element(screen.getByRole("button", { name: "Use model" })).toBeVisible();
75+
expect(notify).not.toHaveBeenCalled();
76+
await screen.rerender(panel("reopened"));
77+
await vi.waitFor(() =>
78+
expect(notify).toHaveBeenCalledWith(
79+
expect.objectContaining({ title: "Could not load transcription models" }),
80+
),
81+
);
82+
},
83+
);
84+
});
85+
1186
it.each([
1287
["speech-models", "voice-transcription-destination"],
1388
["transcription-test", "voice-transcription-destination"],

‎apps/web/src/components/settings/VoiceSettingsPanel.tsx‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -502,30 +502,33 @@ function EnvironmentModelsSection(props: {
502502
}
503503
const epoch = useRef(0);
504504
const refreshRevision = useRef(0);
505-
const refresh = useStableCallback(async (connection: PreparedConnection) => {
506-
const current = epoch.current;
507-
const revision = ++refreshRevision.current;
508-
try {
509-
const [nextStatus, nextModels] = await Promise.all([
510-
runtime.runPromise(getEnvironmentSpeechStatus(connection)),
511-
runtime.runPromise(getEnvironmentSpeechModels(connection)),
512-
]);
513-
if (current !== epoch.current || revision !== refreshRevision.current) return;
514-
onStatus(connection, nextStatus);
515-
setModels(nextModels.models);
516-
} catch (error) {
517-
if (current !== epoch.current || revision !== refreshRevision.current) return;
518-
toastManager.add({
519-
type: "error",
520-
title: "Could not load transcription models",
521-
description: error instanceof Error ? error.message : String(error),
522-
});
523-
}
524-
});
505+
const refresh = useStableCallback(
506+
async (connection: PreparedConnection, mode: "foreground" | "progress") => {
507+
const current = epoch.current;
508+
const revision = ++refreshRevision.current;
509+
try {
510+
const [nextStatus, nextModels] = await Promise.all([
511+
runtime.runPromise(getEnvironmentSpeechStatus(connection)),
512+
runtime.runPromise(getEnvironmentSpeechModels(connection)),
513+
]);
514+
if (current !== epoch.current || revision !== refreshRevision.current) return;
515+
onStatus(connection, nextStatus);
516+
setModels(nextModels.models);
517+
} catch (error) {
518+
if (mode === "progress") return;
519+
if (current !== epoch.current || revision !== refreshRevision.current) return;
520+
toastManager.add({
521+
type: "error",
522+
title: "Could not load transcription models",
523+
description: error instanceof Error ? error.message : String(error),
524+
});
525+
}
526+
},
527+
);
525528
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- loads the environment's model catalog when its connection becomes available
526529
useEffect(() => {
527530
epoch.current += 1;
528-
void refresh(prepared);
531+
void refresh(prepared, "foreground");
529532
return () => {
530533
epoch.current += 1;
531534
};
@@ -539,7 +542,7 @@ function EnvironmentModelsSection(props: {
539542
let cancelled = false;
540543
let timer: number | undefined;
541544
const poll = async () => {
542-
await refresh(prepared);
545+
await refresh(prepared, "progress");
543546
if (!cancelled) timer = window.setTimeout(() => void poll(), 1_000);
544547
};
545548
void poll();
@@ -567,7 +570,7 @@ function EnvironmentModelsSection(props: {
567570
if (current === epoch.current) {
568571
if (downloadId) setRequestedDownload(null);
569572
else setBusy(false);
570-
await refresh(prepared);
573+
await refresh(prepared, "foreground");
571574
}
572575
};
573576
const controlsDisabled = busy || downloading || !canManage;

‎docs/internals/voice-input.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ at a time. Batch uploads carry their options in the body framing defined in
4646
the socket's first command. Model files and the selected model, hardware
4747
placement, and unload timeout are environment state in server settings.
4848

49+
The Silero silence detector is optional. If its download fails, recordings use
50+
raw audio during the retry cooldown so a detector outage cannot block dictation.
51+
Explicitly installing a speech model also retries the detector without waiting.
52+
4953
## Cancellation and resource ownership
5054

5155
Cancellation invalidates a result immediately, but resources stay owned until the

‎docs/user/voice-input.md‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ are down, and **Toggle** always needs a second press. Change the chord itself in
6767
entries apply to every project there. Project spellings win when they overlap
6868
your personal dictionary. Each recording carries up to 100 entries from the
6969
two combined.
70-
- **Silence filtering** skips non-speech audio before recognition and is on by
71-
default. Turn it off to keep raw audio; long recordings can still be split at
72-
pauses. The chosen environment downloads a small Silero helper alongside speech
73-
models, whether installed through setup or Voice settings. If the helper is
74-
unavailable, transcription uses raw audio. Recordings can retry the download
75-
after ten minutes; installing a model retries it immediately. This preference
76-
does not enable audio consent or reduce the audio sent to that environment.
70+
- **Silence filtering** is on by default. Your chosen environment skips non-speech
71+
audio before transcription. Turn it off to keep those sections. Filtering happens
72+
after upload: it does not grant permission to send audio or reduce how much is sent.
7773
- **Remove filler words** drops hesitation sounds from finished transcripts.
7874

7975
Language and these preferences travel with each recording to the chosen

0 commit comments

Comments
 (0)