@fonoster/autopilot 0.7.54 → 0.7.56
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.
|
@@ -35,7 +35,8 @@ class SileroVadModel {
|
|
|
35
35
|
}
|
|
36
36
|
async init() {
|
|
37
37
|
const modelArrayBuffer = (0, fs_1.readFileSync)(this.pathToModel).buffer;
|
|
38
|
-
|
|
38
|
+
const sessionOption = { interOpNumThreads: 1, intraOpNumThreads: 1 };
|
|
39
|
+
this._session = await this.ort.InferenceSession.create(modelArrayBuffer, sessionOption);
|
|
39
40
|
this._sr = new this.ort.Tensor("int64", [16000n]);
|
|
40
41
|
this._state = getNewState(this.ort);
|
|
41
42
|
}
|
|
@@ -24,16 +24,18 @@ exports.chunkToFloat32Array = chunkToFloat32Array;
|
|
|
24
24
|
//
|
|
25
25
|
// Q. Would it be the same if we just created a new Uint8Array from the chunk?
|
|
26
26
|
function chunkToFloat32Array(chunk) {
|
|
27
|
-
// Check if byteOffset is not aligned
|
|
28
|
-
const alignedByteOffset = chunk.byteOffset % Int16Array.BYTES_PER_ELEMENT === 0;
|
|
29
27
|
let int16Array;
|
|
28
|
+
const alignedByteOffset = chunk.byteOffset % Int16Array.BYTES_PER_ELEMENT === 0;
|
|
30
29
|
if (alignedByteOffset) {
|
|
31
30
|
int16Array = new Int16Array(chunk.buffer, chunk.byteOffset, chunk.byteLength / Int16Array.BYTES_PER_ELEMENT);
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
// Create a new aligned Uint8Array and then an Int16Array from it
|
|
35
33
|
const alignedChunk = new Uint8Array(chunk);
|
|
36
34
|
int16Array = new Int16Array(alignedChunk.buffer, alignedChunk.byteOffset, alignedChunk.byteLength / Int16Array.BYTES_PER_ELEMENT);
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
const floatArray = new Float32Array(int16Array.length);
|
|
37
|
+
for (let i = 0; i < int16Array.length; i++) {
|
|
38
|
+
floatArray[i] = int16Array[i] / 32768.0;
|
|
39
|
+
}
|
|
40
|
+
return floatArray;
|
|
39
41
|
}
|
package/dist/vad/makeVad.js
CHANGED
|
@@ -34,11 +34,28 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeVad = makeVad;
|
|
37
|
-
|
|
37
|
+
/* eslint-disable no-loops/no-loops */
|
|
38
|
+
/*
|
|
39
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
40
|
+
* http://github.com/fonoster/fonoster
|
|
41
|
+
*
|
|
42
|
+
* This file is part of Fonoster
|
|
43
|
+
*
|
|
44
|
+
* Licensed under the MIT License (the "License");
|
|
45
|
+
* you may not use this file except in compliance with
|
|
46
|
+
* the License. You may obtain a copy of the License at
|
|
47
|
+
*
|
|
48
|
+
* https://opensource.org/licenses/MIT
|
|
49
|
+
*
|
|
50
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
51
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
52
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
53
|
+
* See the License for the specific language governing permissions and
|
|
54
|
+
* limitations under the License.
|
|
55
|
+
*/
|
|
38
56
|
const ort = __importStar(require("onnxruntime-node"));
|
|
39
57
|
const chunkToFloat32Array_1 = require("./chunkToFloat32Array");
|
|
40
58
|
const SileroVadModel_1 = require("./SileroVadModel");
|
|
41
|
-
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
42
59
|
const BUFFER_SIZE = 512;
|
|
43
60
|
async function makeVad(params) {
|
|
44
61
|
const { pathToModel, activationThreshold, deactivationThreshold, debounceFrames } = params;
|
|
@@ -56,7 +73,6 @@ async function makeVad(params) {
|
|
|
56
73
|
const audioFrame = buffer.slice(0, BUFFER_SIZE);
|
|
57
74
|
const remainingBuffer = buffer.slice(BUFFER_SIZE);
|
|
58
75
|
const result = await silero.process(new Float32Array(audioFrame));
|
|
59
|
-
logger.silly("last vad result", { ...result });
|
|
60
76
|
if (result.isSpeech > activationThreshold) {
|
|
61
77
|
consecutiveNonSpeechFrames = 0; // Reset non-speech counter
|
|
62
78
|
consecutiveSpeechFrames++;
|
package/dist/vad/types.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ type SpeechProbabilities = {
|
|
|
8
8
|
};
|
|
9
9
|
type ONNXRuntimeAPI = {
|
|
10
10
|
InferenceSession: {
|
|
11
|
-
create(modelArrayBuffer: ArrayBuffer
|
|
11
|
+
create(modelArrayBuffer: ArrayBuffer, sessionOption: {
|
|
12
|
+
interOpNumThreads: number;
|
|
13
|
+
intraOpNumThreads: number;
|
|
14
|
+
}): Promise<unknown>;
|
|
12
15
|
};
|
|
13
16
|
Tensor: {
|
|
14
17
|
new (type: "int64", data: BigInt[]): unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.56",
|
|
4
4
|
"description": "Voice AI for the Fonoster platform",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@aws-sdk/client-s3": "^3.712.0",
|
|
39
|
-
"@fonoster/common": "^0.7.
|
|
40
|
-
"@fonoster/logger": "^0.7.
|
|
41
|
-
"@fonoster/types": "^0.7.
|
|
42
|
-
"@fonoster/voice": "^0.7.
|
|
39
|
+
"@fonoster/common": "^0.7.56",
|
|
40
|
+
"@fonoster/logger": "^0.7.56",
|
|
41
|
+
"@fonoster/types": "^0.7.56",
|
|
42
|
+
"@fonoster/voice": "^0.7.56",
|
|
43
43
|
"@langchain/community": "^0.3.19",
|
|
44
44
|
"@langchain/core": "^0.3.23",
|
|
45
45
|
"@langchain/groq": "^0.1.2",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"typescript": "^5.5.4"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "f918235ae68a49970b45022637347f673ca63941"
|
|
61
61
|
}
|