Run Parakeet TDT in the inference worker via parakeet.js on the shared onnxruntime-web

Adds parakeet.js 1.4.4 (MIT) as a devDependency bundled into the worker
only; a build plugin keeps its own onnxruntime-web copy out of the bundle.
Includes an opt-in real-model test (PARAKEET_REAL=1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5.5 committed 2026-10-29 22:08:05 +01:00
1 parent c5a57cd33a
commit 708fae5778
10 files changed
+485 -7

No files matched your search

+3
View File
@@ -17,6 +17,7 @@ import { join, relative } from "node:path";
import { injectPrecacheManifest, precachePathsFromOutputs } from "../src/pwa/precache.ts";
import { ensureFonts, FONTS_DIR } from "./fonts.ts";
import { ensureIcons, ICON_SIZES, ICONS_DIR } from "./generate-icons.ts";
import { ortAliasPlugin } from "./ortAlias.ts";
const ROOT = join(import.meta.dir, "..");
const DIST = join(ROOT, "dist");
@@ -50,6 +51,8 @@ const workerBuild = await Bun.build({
target: "browser",
format: "esm",
minify: true,
// One onnxruntime in the bundle (D-WS7a).
plugins: [ortAliasPlugin],
});
const workerScript = await workerBuild.outputs[0]!.text();
await Bun.write(join(DIST, "inference.worker.js"), workerScript);
+23
View File
@@ -0,0 +1,23 @@
/**
* Bun build plugin: parakeet.js's bare `onnxruntime-web` import resolves to
* `src/worker/ortShim.ts` (= Transformers.js's `onnxruntime-web/webgpu`), so
* the inference worker bundles exactly one onnxruntime (D-WS7a). Used by the
* production build (scripts/build.ts) and the dev server's worker bundle
* (src/index.ts). Without it the bundle carries parakeet.js's own 1.24.1
* copy as well — never executed, but ~0.5 MB of dead weight and a CDN
* wasmPaths default.
*/
import type { BunPlugin } from "bun";
import { join } from "node:path";
const SHIM = join(import.meta.dir, "../src/worker/ortShim.ts");
export const ortAliasPlugin: BunPlugin = {
name: "parakeet-ort-alias",
setup(build) {
build.onResolve({ filter: /^onnxruntime-web$/ }, (args) =>
/[\\/]parakeet\.js[\\/]/.test(args.importer) ? { path: SHIM } : undefined,
);
},
};