Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(stt): fall back to the x64 whisper helper on Windows on ARM

Christian Schmittel39678af683f7
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2f8ff31a6..937d1df00 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -102,7 +102,14 @@ jobs:
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bash scripts/stage-whisper-stt.sh win32-${{ matrix.arch }}
+ # win32-x64 for BOTH arches, deliberately: build-whisper-stt.yml produces no
+ # arm64 helper (scripts/build-whisper-stt.sh has no win32-arm64 acceleration
+ # case at all), so an arch-parameterised tag would simply fail the arm64 job.
+ # `candidateBinaryPaths` falls back to the win32-x64 directory on Windows on
+ # ARM, where the x64 helper runs under emulation — verified on a Snapdragon X
+ # Elite, Vulkan on the Adreno included. Point this at win32-arm64 the moment a
+ # native helper exists; the resolver already prefers it.
+ run: bash scripts/stage-whisper-stt.sh win32-x64
- name: Build Windows app (x64)
if: matrix.arch == 'x64'
diff --git a/electron/stt/gpuDetector.test.ts b/electron/stt/gpuDetector.test.ts
index 5790032d4..e8a2cd4d0 100644
--- a/electron/stt/gpuDetector.test.ts
+++ b/electron/stt/gpuDetector.test.ts
@@ -51,6 +51,43 @@ describe("gpuDetector", () => {
}
});
+ /**
+ * Windows on ARM ships no whisper build: `build-whisper-stt.yml` produces
+ * `win32-x64` only, and `scripts/build-whisper-stt.sh` has no acceleration case
+ * for `win32-arm64` at all. An arm64 package therefore resolves a tag that will
+ * never contain the helper, and speech-to-text fails with "binary not found" —
+ * observed on a Snapdragon X Elite.
+ *
+ * The x64 helper runs fine there: Windows emulates it per-process, and it is
+ * spawned as its own process rather than loaded into ours. Verified by running
+ * the extracted x64 `whisper-stt-server.exe` on that machine — it starts, loads
+ * its DLLs and parses its arguments. Falling back to it beats shipping an arm64
+ * build with no transcription until a native helper exists.
+ *
+ * The fallback tag matters for more than the .exe: the x64 helper needs the x64
+ * CRT and ggml DLLs beside it, and `win32-arm64/` holds the ARM64 ones. Pointing
+ * at `win32-x64/` keeps the helper next to the libraries it actually links.
+ */
+ it("candidateBinaryPaths falls back to the x64 helper on Windows on ARM", () => {
+ const originalPlatform = process.platform;
+ const originalArch = process.arch;
+ Object.defineProperty(process, "platform", { value: "win32", configurable: true });
+ Object.defineProperty(process, "arch", { value: "arm64", configurable: true });
+ try {
+ const here = "C:/fake/repo";
+ const resolved = candidateBinaryPaths(here).map((p) => p.replace(/\\/g, "/"));
+ const arm = `${here}/electron/native/bin/win32-arm64/whisper-stt-server.exe`;
+ const x64 = `${here}/electron/native/bin/win32-x64/whisper-stt-server.exe`;
+ expect(resolved).toContain(arm);
+ expect(resolved).toContain(x64);
+ // Native first: the moment an arm64 helper exists it must win.
+ expect(resolved.indexOf(arm)).toBeLessThan(resolved.indexOf(x64));
+ } finally {
+ Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true });
+ Object.defineProperty(process, "arch", { value: originalArch, configurable: true });
+ }
+ });
+
it("candidateBinaryPaths prepends env override when set", () => {
process.env.OPENSCREEN_WHISPER_SERVER_EXE = "/custom/path/whisper-stt-server";
const here = "/fake/repo";
diff --git a/electron/stt/gpuDetector.ts b/electron/stt/gpuDetector.ts
index 2ef415f58..f7aba344f 100644
--- a/electron/stt/gpuDetector.ts
+++ b/electron/stt/gpuDetector.ts
@@ -77,27 +77,49 @@ export function binaryNameForBackend(_backend: SttBackend): string {
* checkout that pre-dates the suffix fix still resolves to a valid file.
*/
export function candidateBinaryPaths(here: string = process.cwd()): string[] {
- const tag = `${process.platform}-${process.arch}`;
const name = binaryNameForBackend("whispercpp-cpu");
const envPath = process.env.OPENSCREEN_WHISPER_SERVER_EXE?.trim();
const appPath = readAppPath();
const resourcePath = readResourcesPath();
const names = name.endsWith(".exe") ? [name, name.replace(/\.exe$/, "")] : [name];
- const appPathSegments = appPath
- ? names.map((n) => path.join(appPath, "electron", "native", "bin", tag, n))
- : [];
- const resourceSegments = resourcePath
- ? names.map((n) => path.join(resourcePath, "electron", "native", "bin", tag, n))
- : [];
+ const tags = binaryTags();
+ const under = (base: string) =>
+ tags.flatMap((tag) => names.map((n) => path.join(base, "electron", "native", "bin", tag, n)));
return [
...(envPath ? [envPath] : []),
- ...appPathSegments,
- ...resourceSegments,
- ...names.map((n) => path.join(here, "electron", "native", "bin", tag, n)),
+ ...(appPath ? under(appPath) : []),
+ ...(resourcePath ? under(resourcePath) : []),
+ ...under(here),
...names.map((n) => path.join(here, "electron", "native", "bin", n)),
].filter((p): p is string => Boolean(p));
}
+/**
+ * Arch-tagged directories to search, native first.
+ *
+ * Windows on ARM gets a second tag. There is no arm64 whisper build to find:
+ * `.github/workflows/build-whisper-stt.yml` produces `win32-x64` only, and
+ * `scripts/build-whisper-stt.sh` has no acceleration case for `win32-arm64` — so an
+ * arm64 package resolves a directory that will never hold the helper, and every
+ * transcription fails with "binary not found".
+ *
+ * The x64 helper works there. Windows emulates x64 per-process and this helper is
+ * spawned as its own process rather than loaded into ours, so emulation is contained
+ * to it. Verified on a Snapdragon X Elite: the x64 `whisper-stt-server.exe` starts,
+ * resolves its DLLs and parses its arguments.
+ *
+ * Falling back to the whole `win32-x64` DIRECTORY rather than just the .exe is the
+ * point: the helper links whisper/ggml and the VC runtime from its own directory, and
+ * `win32-arm64/` holds the ARM64 builds of those. Sending an emulated x64 process
+ * there would fail in the loader.
+ *
+ * `win32-arm64` stays first so a native helper wins the moment one exists.
+ */
+function binaryTags(): string[] {
+ const tag = `${process.platform}-${process.arch}`;
+ return process.platform === "win32" && process.arch === "arm64" ? [tag, "win32-x64"] : [tag];
+}
+
/** Resolve `app.getAppPath()` lazily so this module stays importable from
* contexts where Electron's `app` is not yet ready (e.g. unit tests). */
function readAppPath(): string | null {