@omote/core 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +50 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2132,6 +2132,25 @@ async function isWebGPUAvailable() {
|
|
|
2132
2132
|
return false;
|
|
2133
2133
|
}
|
|
2134
2134
|
}
|
|
2135
|
+
var iosWasmPatched = false;
|
|
2136
|
+
function applyIOSWasmMemoryPatch() {
|
|
2137
|
+
if (iosWasmPatched || !isIOS()) return;
|
|
2138
|
+
iosWasmPatched = true;
|
|
2139
|
+
const OrigMemory = WebAssembly.Memory;
|
|
2140
|
+
const MAX_IOS_PAGES = 16384;
|
|
2141
|
+
logger.info("Applying iOS WASM memory patch (shared\u2192false, max\u21921GB)");
|
|
2142
|
+
WebAssembly.Memory = function IOSPatchedMemory(descriptor) {
|
|
2143
|
+
const patched = { ...descriptor };
|
|
2144
|
+
if (patched.shared) {
|
|
2145
|
+
patched.shared = false;
|
|
2146
|
+
}
|
|
2147
|
+
if (patched.maximum !== void 0 && patched.maximum > MAX_IOS_PAGES) {
|
|
2148
|
+
patched.maximum = MAX_IOS_PAGES;
|
|
2149
|
+
}
|
|
2150
|
+
return new OrigMemory(patched);
|
|
2151
|
+
};
|
|
2152
|
+
WebAssembly.Memory.prototype = OrigMemory.prototype;
|
|
2153
|
+
}
|
|
2135
2154
|
function configureWasm(ort) {
|
|
2136
2155
|
ort.env.wasm.wasmPaths = WASM_CDN_PATH;
|
|
2137
2156
|
const numThreads = getOptimalWasmThreads();
|
|
@@ -2157,6 +2176,7 @@ async function getOnnxRuntime(backend) {
|
|
|
2157
2176
|
return ortInstance;
|
|
2158
2177
|
}
|
|
2159
2178
|
logger.info(`Loading ONNX Runtime with ${backend} backend...`);
|
|
2179
|
+
applyIOSWasmMemoryPatch();
|
|
2160
2180
|
try {
|
|
2161
2181
|
if (backend === "wasm") {
|
|
2162
2182
|
const module = await import("onnxruntime-web");
|
|
@@ -3331,6 +3351,8 @@ var SileroVADInference = class {
|
|
|
3331
3351
|
// Pre-speech buffer for capturing beginning of speech
|
|
3332
3352
|
this.preSpeechBuffer = [];
|
|
3333
3353
|
this.wasSpeaking = false;
|
|
3354
|
+
// Cached sample rate tensor (int64 scalar, never changes per instance)
|
|
3355
|
+
this.srTensor = null;
|
|
3334
3356
|
const sampleRate = config.sampleRate ?? 16e3;
|
|
3335
3357
|
if (sampleRate !== 8e3 && sampleRate !== 16e3) {
|
|
3336
3358
|
throw new Error("Silero VAD only supports 8000 or 16000 Hz sample rates");
|
|
@@ -3461,6 +3483,24 @@ var SileroVADInference = class {
|
|
|
3461
3483
|
this.context = new Float32Array(this.contextSize);
|
|
3462
3484
|
this.preSpeechBuffer = [];
|
|
3463
3485
|
this.wasSpeaking = false;
|
|
3486
|
+
if (!this.srTensor) {
|
|
3487
|
+
try {
|
|
3488
|
+
this.srTensor = new this.ort.Tensor(
|
|
3489
|
+
"int64",
|
|
3490
|
+
new BigInt64Array([BigInt(this.config.sampleRate)]),
|
|
3491
|
+
[]
|
|
3492
|
+
);
|
|
3493
|
+
} catch (e) {
|
|
3494
|
+
logger7.warn("BigInt64Array not available, using bigint array fallback", {
|
|
3495
|
+
error: e instanceof Error ? e.message : String(e)
|
|
3496
|
+
});
|
|
3497
|
+
this.srTensor = new this.ort.Tensor(
|
|
3498
|
+
"int64",
|
|
3499
|
+
[BigInt(this.config.sampleRate)],
|
|
3500
|
+
[]
|
|
3501
|
+
);
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3464
3504
|
}
|
|
3465
3505
|
/**
|
|
3466
3506
|
* Process a single audio chunk
|
|
@@ -3592,7 +3632,7 @@ var SileroVADInference = class {
|
|
|
3592
3632
|
inputBuffer.set(audioChunkCopy, this.contextSize);
|
|
3593
3633
|
const inputBufferCopy = new Float32Array(inputBuffer);
|
|
3594
3634
|
const inputTensor = new this.ort.Tensor("float32", inputBufferCopy, [1, inputSize]);
|
|
3595
|
-
const srTensor =
|
|
3635
|
+
const srTensor = this.srTensor;
|
|
3596
3636
|
const stateCopy = new Float32Array(this.state.data);
|
|
3597
3637
|
const stateTensor = new this.ort.Tensor("float32", stateCopy, this.state.dims);
|
|
3598
3638
|
const feeds = {
|
|
@@ -3681,6 +3721,7 @@ var SileroVADInference = class {
|
|
|
3681
3721
|
this.session = null;
|
|
3682
3722
|
}
|
|
3683
3723
|
this.state = null;
|
|
3724
|
+
this.srTensor = null;
|
|
3684
3725
|
}
|
|
3685
3726
|
};
|
|
3686
3727
|
/**
|
|
@@ -3785,7 +3826,14 @@ async function runInference(audio, state, context) {
|
|
|
3785
3826
|
// Create tensors
|
|
3786
3827
|
const inputTensor = new ort.Tensor('float32', new Float32Array(inputBuffer), [1, inputSize]);
|
|
3787
3828
|
const stateTensor = new ort.Tensor('float32', new Float32Array(state), [2, 1, 128]);
|
|
3788
|
-
|
|
3829
|
+
// Use BigInt64Array constructor (not .from()) for broader compatibility
|
|
3830
|
+
let srTensor;
|
|
3831
|
+
try {
|
|
3832
|
+
srTensor = new ort.Tensor('int64', new BigInt64Array([BigInt(sampleRate)]), []);
|
|
3833
|
+
} catch (e) {
|
|
3834
|
+
// Fallback for environments without BigInt64Array support
|
|
3835
|
+
srTensor = new ort.Tensor('int64', [BigInt(sampleRate)], []);
|
|
3836
|
+
}
|
|
3789
3837
|
|
|
3790
3838
|
const feeds = {
|
|
3791
3839
|
'input': inputTensor,
|