Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(stt): download models through Chromium's network stack
Marc Diaz3c9bd5db0799
diff --git a/electron/stt/index.test.ts b/electron/stt/index.test.tsindex 02a071a42..46c328bd0 100644--- a/electron/stt/index.test.ts+++ b/electron/stt/index.test.ts@@ -21,6 +21,9 @@ const fakeWhisperServer = {shutdown: vi.fn(),};+const netFetch = vi.hoisted(() => vi.fn(async () => new Response("model")));+vi.mock("electron", () => ({ app: { getPath: () => "/tmp" }, net: { fetch: netFetch } }));+vi.mock("./whisperServer", () => {class FakeWhisperServerManager {start = fakeWhisperServer.start;@@ -482,6 +485,19 @@ describe("SttManager", () => {expect(fakeWhisperServer.start).toHaveBeenCalledOnce();});+ it("downloads the models through Chromium's network stack, which honours the system proxy", async () => {+ const { ensureModels } = await import("./modelManager");+ const mocked = vi.mocked(ensureModels);+ mocked.mockClear();+ netFetch.mockClear();+ await new SttManager().init({ modelsBaseDir: "/tmp/fake-stt-models" });++ const fetcher = mocked.mock.calls[0]?.[0].fetcher;+ expect(fetcher).toBeDefined();+ await fetcher?.(new URL("https://huggingface.co/model.bin"), { method: "GET" });+ expect(netFetch).toHaveBeenCalledWith("https://huggingface.co/model.bin", { method: "GET" });+ });+describe("word aligner", () => {/** Chunks report what `alignerFor("fr")` gave them, as the helper would use it. */function recordAligner() {@@ -524,6 +540,9 @@ describe("SttManager", () => {expect(asked.length).toBeGreaterThan(1);expect(asked.every((x) => x === null)).toBe(true);expect(ensure).toHaveBeenCalledOnce();+ netFetch.mockClear();+ await ensure.mock.calls[0]?.[0].fetcher?.("https://github.com/aligner.gguf");+ expect(netFetch).toHaveBeenCalledWith("https://github.com/aligner.gguf", undefined);land("/fake/fr.gguf");await new Promise((resolve) => setTimeout(resolve, 0));diff --git a/electron/stt/index.ts b/electron/stt/index.tsindex 1272b99fa..347d67ca5 100644--- a/electron/stt/index.ts+++ b/electron/stt/index.ts@@ -1,5 +1,5 @@import path from "node:path";-import { app, type IpcMain } from "electron";+import { app, type IpcMain, net } from "electron";import { planChunks } from "./chunking";import { extractMono16kPcm } from "./extractAudio";import {@@ -59,6 +59,15 @@ const SAMPLE_RATE = 16_000;/** Attempts per chunk before the whole transcription fails. */const CHUNK_ATTEMPTS = 3;+/**+ * Model and aligner downloads go through Chromium's network stack rather than Node's+ * global `fetch`, which ignores the system proxy: where huggingface.co is only reachable+ * through one (mainland China, many corporate networks), the download failed with a bare+ * "fetch failed" while the same URL opened in a browser (#1330).+ */+const fetchThroughChromium: typeof fetch = (input, init) =>+ net.fetch(input instanceof URL ? input.href : input, init);+/*** `AbortError` by name so the renderer's `isAbortError` recognizes it as "the* user asked for this" rather than an engine failure worth a toast.@@ -150,7 +159,12 @@ export class SttManager {const controller = new AbortController();this.alignerDownloads.set(language, controller);console.info(`[stt] downloading the "${language}" word aligner in the background`);- ensureAligner({ baseDir: this.getModelsDir(), language, signal: controller.signal })+ ensureAligner({+ baseDir: this.getModelsDir(),+ language,+ signal: controller.signal,+ fetcher: fetchThroughChromium,+ }).then((file) => {if (file) this.alignersReady.set(language, file);console.info(`[stt] "${language}" word aligner ready`);@@ -243,6 +257,7 @@ export class SttManager {this.emit({ phase: "model", model: "whisper", downloadedBytes: 0, totalBytes: 0 });await ensureModels({baseDir: modelsDir,+ fetcher: fetchThroughChromium,onProgress: (event) => {this.emit({phase: "model",