// Builds public/rnnoise/rnnoise-worklet.js: one classic AudioWorklet script holding @jitsi/rnnoise-wasm's // rnnoise-sync.js (wasm inlined as base64) and Element Call's RNNoise worklet, so // audioWorklet.addModule makes a single request and no wasm fetch. The studio loads it by URL (src/lib/guestMedia.ts). // The worklet source is src/rnnoise/RNNoiseWorkletModule.ts, adapted from vendor/element-call-rnnoise (AGPL-3.0). // Also copies its source and licences to public/rnnoise/source/ (AGPL-3.0 source offer, spikes/agpl-check.md). // Before P4 this wrote public/vdo/, with inject.js for the VDO.Ninja call. That folder is deleted here, so an old // build output in a checkout never ships. import { cpSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; import { createRequire } from "node:module"; import ts from "typescript"; const require = createRequire(import.meta.url); const root = new URL("..", import.meta.url); const out = new URL("public/rnnoise/rnnoise-worklet.js", root); rmSync(new URL("public/vdo/", root), { recursive: true, force: true }); // Same patch as createWorkletCode() in vendor/element-call-rnnoise/src/audio/RNNoiseProcessor.ts. const rnnoise = readFileSync(require.resolve("@jitsi/rnnoise-wasm/dist/rnnoise-sync.js"), "utf8") .replace(/import\.meta\.url/g, '""') .replace(/export\s+default\s+createRNNWasmModuleSync;?\s*$/m, ""); const workletTs = readFileSync(new URL("src/rnnoise/RNNoiseWorkletModule.ts", root), "utf8"); const worklet = ts .transpileModule(workletTs, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext } }) .outputText.replace(/^import\s+createRNNWasmModuleSync\s+from\s+["'][^"']+["'];?\s*$/m, ""); const banner = `/* * RNNoise AudioWorklet for the podcast studio. Generated by scripts/build-rnnoise-worklet.mjs. Do not edit. * * Contains: * - src/rnnoise/RNNoiseWorkletModule.ts, adapted from element-hq/element-call pull request #3772 (unmerged), * commit 1b7877a385d4102f130ff06e3a87a4c082585389 (the _rnnoise_init() call is removed, see that file). * Copyright 2026 Element Creations Ltd. SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. * Used here under AGPL-3.0-only. Full source: src/rnnoise, vendor/element-call-rnnoise and this build script. * - rnnoise-sync.js from @jitsi/rnnoise-wasm 0.2.1, Apache-2.0, patched for classic worklet scope (script URL and ES export removed). * - RNNoise, BSD-3-Clause (Copyright (c) 2017 Mozilla, 2007-2017 Jean-Marc Valin, 2005-2017 Xiph.Org Foundation, * 2003-2004 Mark Borgerding), compiled to wasm inside it. * See vendor/element-call-rnnoise/LICENSE and THIRD_PARTY_NOTICES. */ `; const code = `${banner}${rnnoise}\n${worklet}`; // The result must be a classic script with the wasm inlined. const checks = [ ["no import.meta", !/import\.meta/.test(code)], ["no top-level import/export", !/^\s*(import|export)\s/m.test(code)], ["one registerProcessor call", (code.match(/registerProcessor\(/g) || []).length === 1], ["inlined wasm", code.includes("data:application/octet-stream;base64,")], ]; const failed = checks.filter(([, ok]) => !ok).map(([name]) => name); if (failed.length) throw new Error("rnnoise-worklet.js check failed: " + failed.join(", ")); mkdirSync(new URL(".", out), { recursive: true }); writeFileSync(out, code); console.log(`rnnoise-worklet.js ${(code.length / 1024).toFixed(0)} KB`); // Source offer. Files get a .txt suffix so the browser shows them as text. const sourceDir = new URL("public/rnnoise/source/", root); rmSync(sourceDir, { recursive: true, force: true }); const files = [ "src/rnnoise/RNNoiseWorkletModule.ts", "src/rnnoise/rnnoise-wasm.d.ts", "scripts/build-rnnoise-worklet.mjs", ]; const walk = (dir) => readdirSync(new URL(dir, root)).flatMap((f) => statSync(new URL(dir + f, root)).isDirectory() ? walk(dir + f + "/") : [dir + f]); files.push(...walk("vendor/element-call-rnnoise/")); for (const f of files) { const to = new URL(f + ".txt", sourceDir); mkdirSync(new URL(".", to), { recursive: true }); cpSync(new URL(f, root), to); } const links = files.map((f) => `
The studio's noise filter is one script, rnnoise-worklet.js (the RNNoise filter), which the studio page loads into its microphone's audio graph. It contains code adapted from Element Call pull request #3772, Copyright 2026 Element Creations Ltd., used under the GNU Affero General Public License version 3 (LICENSE). Third-party parts: RNNoise (BSD-3-Clause) and @jitsi/rnnoise-wasm 0.2.1 (Apache-2.0), see THIRD_PARTY_NOTICES.
Build: npm install, then node scripts/build-rnnoise-worklet.mjs.