fix: copy ort .mjs file, add COOP/COEP headers, set numThreads=1

The threaded ORT WASM requires ort-wasm-simd-threaded.mjs to be served
alongside the .wasm files, and needs SharedArrayBuffer (COOP/COEP headers).
Add the .mjs to the static copy targets, add the required headers to the
Vite dev server, and set ort.env.wasm.numThreads=1 as a single-threaded
fallback that avoids the SharedArrayBuffer requirement entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mk
2026-03-23 23:41:51 -03:00
parent edd1e1d34e
commit b25cec3aa0
2 changed files with 15 additions and 0 deletions

View File

@@ -6,6 +6,8 @@ Please see LICENSE in the repository root for full details.
*/
import { MicVAD, getDefaultRealTimeVADOptions } from "@ricky0123/vad-web";
// ort is not re-exported from the index, import from submodule
import { ort } from "@ricky0123/vad-web/dist/real-time-vad";
import { logger } from "matrix-js-sdk/lib/logger";
const log = logger.getChild("[SileroVADGate]");
@@ -52,6 +54,10 @@ export class SileroVADGate {
log.info("initialising MicVAD, baseAssetPath:", VAD_BASE_PATH);
// Avoid requiring SharedArrayBuffer (COOP/COEP headers) by running
// single-threaded. Performance is sufficient for 16kHz speech frames.
ort.env.wasm.numThreads = 1;
this.vad = await MicVAD.new({
...getDefaultRealTimeVADOptions("legacy"),
audioContext,