@omote/core 0.2.1 → 0.2.2
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 +30 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3331,6 +3331,8 @@ var SileroVADInference = class {
|
|
|
3331
3331
|
// Pre-speech buffer for capturing beginning of speech
|
|
3332
3332
|
this.preSpeechBuffer = [];
|
|
3333
3333
|
this.wasSpeaking = false;
|
|
3334
|
+
// Cached sample rate tensor (int64 scalar, never changes per instance)
|
|
3335
|
+
this.srTensor = null;
|
|
3334
3336
|
const sampleRate = config.sampleRate ?? 16e3;
|
|
3335
3337
|
if (sampleRate !== 8e3 && sampleRate !== 16e3) {
|
|
3336
3338
|
throw new Error("Silero VAD only supports 8000 or 16000 Hz sample rates");
|
|
@@ -3461,6 +3463,24 @@ var SileroVADInference = class {
|
|
|
3461
3463
|
this.context = new Float32Array(this.contextSize);
|
|
3462
3464
|
this.preSpeechBuffer = [];
|
|
3463
3465
|
this.wasSpeaking = false;
|
|
3466
|
+
if (!this.srTensor) {
|
|
3467
|
+
try {
|
|
3468
|
+
this.srTensor = new this.ort.Tensor(
|
|
3469
|
+
"int64",
|
|
3470
|
+
new BigInt64Array([BigInt(this.config.sampleRate)]),
|
|
3471
|
+
[]
|
|
3472
|
+
);
|
|
3473
|
+
} catch (e) {
|
|
3474
|
+
logger7.warn("BigInt64Array not available, using bigint array fallback", {
|
|
3475
|
+
error: e instanceof Error ? e.message : String(e)
|
|
3476
|
+
});
|
|
3477
|
+
this.srTensor = new this.ort.Tensor(
|
|
3478
|
+
"int64",
|
|
3479
|
+
[BigInt(this.config.sampleRate)],
|
|
3480
|
+
[]
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3464
3484
|
}
|
|
3465
3485
|
/**
|
|
3466
3486
|
* Process a single audio chunk
|
|
@@ -3592,7 +3612,7 @@ var SileroVADInference = class {
|
|
|
3592
3612
|
inputBuffer.set(audioChunkCopy, this.contextSize);
|
|
3593
3613
|
const inputBufferCopy = new Float32Array(inputBuffer);
|
|
3594
3614
|
const inputTensor = new this.ort.Tensor("float32", inputBufferCopy, [1, inputSize]);
|
|
3595
|
-
const srTensor =
|
|
3615
|
+
const srTensor = this.srTensor;
|
|
3596
3616
|
const stateCopy = new Float32Array(this.state.data);
|
|
3597
3617
|
const stateTensor = new this.ort.Tensor("float32", stateCopy, this.state.dims);
|
|
3598
3618
|
const feeds = {
|
|
@@ -3681,6 +3701,7 @@ var SileroVADInference = class {
|
|
|
3681
3701
|
this.session = null;
|
|
3682
3702
|
}
|
|
3683
3703
|
this.state = null;
|
|
3704
|
+
this.srTensor = null;
|
|
3684
3705
|
}
|
|
3685
3706
|
};
|
|
3686
3707
|
/**
|
|
@@ -3785,7 +3806,14 @@ async function runInference(audio, state, context) {
|
|
|
3785
3806
|
// Create tensors
|
|
3786
3807
|
const inputTensor = new ort.Tensor('float32', new Float32Array(inputBuffer), [1, inputSize]);
|
|
3787
3808
|
const stateTensor = new ort.Tensor('float32', new Float32Array(state), [2, 1, 128]);
|
|
3788
|
-
|
|
3809
|
+
// Use BigInt64Array constructor (not .from()) for broader compatibility
|
|
3810
|
+
let srTensor;
|
|
3811
|
+
try {
|
|
3812
|
+
srTensor = new ort.Tensor('int64', new BigInt64Array([BigInt(sampleRate)]), []);
|
|
3813
|
+
} catch (e) {
|
|
3814
|
+
// Fallback for environments without BigInt64Array support
|
|
3815
|
+
srTensor = new ort.Tensor('int64', [BigInt(sampleRate)], []);
|
|
3816
|
+
}
|
|
3789
3817
|
|
|
3790
3818
|
const feeds = {
|
|
3791
3819
|
'input': inputTensor,
|