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:
@@ -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,
|
||||
|
||||
@@ -50,6 +50,10 @@ export default ({
|
||||
src: "node_modules/onnxruntime-web/dist/*.wasm",
|
||||
dest: "vad",
|
||||
},
|
||||
{
|
||||
src: "node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.mjs",
|
||||
dest: "vad",
|
||||
},
|
||||
],
|
||||
}),
|
||||
react(),
|
||||
@@ -118,6 +122,11 @@ export default ({
|
||||
key: fs.readFileSync("./backend/dev_tls_m.localhost.key"),
|
||||
cert: fs.readFileSync("./backend/dev_tls_m.localhost.crt"),
|
||||
},
|
||||
// Required for SharedArrayBuffer (used by onnxruntime-web threaded WASM)
|
||||
headers: {
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
},
|
||||
},
|
||||
worker: {
|
||||
format: "es",
|
||||
|
||||
Reference in New Issue
Block a user