@fonoster/autopilot 0.7.53 → 0.7.55
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/Autopilot.d.ts +3 -3
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +2 -1
- package/dist/vad/SileroVad.d.ts +3 -3
- package/dist/vad/SileroVadModel.d.ts +7 -8
- package/dist/vad/SileroVadModel.js +11 -11
- package/dist/vad/chunkToFloat32Array.js +6 -4
- package/dist/vad/makeVad.d.ts +1 -1
- package/dist/vad/makeVad.js +2 -7
- package/dist/vad/types.d.ts +3 -3
- package/dist/vadWorker.js +5 -1
- package/package.json +6 -6
- package/silero_vad.onnx +0 -0
package/dist/Autopilot.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AutopilotParams } from "./types";
|
|
2
2
|
declare class Autopilot {
|
|
3
|
-
private params;
|
|
4
|
-
private actor;
|
|
5
|
-
private vadWorker;
|
|
3
|
+
private readonly params;
|
|
4
|
+
private readonly actor;
|
|
5
|
+
private readonly vadWorker;
|
|
6
6
|
constructor(params: AutopilotParams);
|
|
7
7
|
start(): void;
|
|
8
8
|
stop(): void;
|
package/dist/envs.d.ts
CHANGED
package/dist/envs.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UNSTRUCTURED_API_URL = exports.UNSTRUCTURED_API_KEY = exports.SKIP_IDENTITY = exports.NODE_ENV = exports.KNOWLEDGE_BASE_ENABLED = exports.AWS_S3_SECRET_ACCESS_KEY = exports.AWS_S3_REGION = exports.AWS_S3_ENDPOINT = exports.AWS_S3_ACCESS_KEY_ID = void 0;
|
|
6
|
+
exports.SILERO_VAD_MODEL_PATH = exports.UNSTRUCTURED_API_URL = exports.UNSTRUCTURED_API_KEY = exports.SKIP_IDENTITY = exports.NODE_ENV = exports.KNOWLEDGE_BASE_ENABLED = exports.AWS_S3_SECRET_ACCESS_KEY = exports.AWS_S3_REGION = exports.AWS_S3_ENDPOINT = exports.AWS_S3_ACCESS_KEY_ID = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
9
9
|
* http://github.com/fonoster/fonoster
|
|
@@ -38,6 +38,7 @@ exports.NODE_ENV = e.NODE_ENV || "production";
|
|
|
38
38
|
exports.SKIP_IDENTITY = e.SKIP_IDENTITY === "true";
|
|
39
39
|
exports.UNSTRUCTURED_API_KEY = e.UNSTRUCTURED_API_KEY;
|
|
40
40
|
exports.UNSTRUCTURED_API_URL = e.UNSTRUCTURED_API_URL ?? "https://api.unstructuredapp.io/general/v0/general";
|
|
41
|
+
exports.SILERO_VAD_MODEL_PATH = e.SILERO_VAD_MODEL_PATH ?? (0, path_1.join)(__dirname, "..", "silero_vad.onnx");
|
|
41
42
|
if (exports.KNOWLEDGE_BASE_ENABLED) {
|
|
42
43
|
(0, common_1.assertEnvsAreSet)([
|
|
43
44
|
"AWS_S3_ACCESS_KEY_ID",
|
package/dist/vad/SileroVad.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Vad } from "./types";
|
|
2
2
|
declare class SileroVad implements Vad {
|
|
3
3
|
private vad;
|
|
4
|
-
private params;
|
|
4
|
+
private readonly params;
|
|
5
5
|
constructor(params: {
|
|
6
|
-
pathToModel
|
|
6
|
+
pathToModel: string;
|
|
7
7
|
activationThreshold: number;
|
|
8
8
|
deactivationThreshold: number;
|
|
9
9
|
debounceFrames: number;
|
|
10
10
|
});
|
|
11
|
-
pathToModel
|
|
11
|
+
pathToModel: string;
|
|
12
12
|
activationThreshold: number;
|
|
13
13
|
deactivationThreshold: number;
|
|
14
14
|
debounceFrames: number;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ONNXRuntimeAPI, SpeechProbabilities } from "./types";
|
|
2
2
|
declare class SileroVadModel {
|
|
3
|
-
private ort;
|
|
4
|
-
private pathToModel;
|
|
5
|
-
_session
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
_sr: unknown;
|
|
3
|
+
private readonly ort;
|
|
4
|
+
private readonly pathToModel;
|
|
5
|
+
private _session;
|
|
6
|
+
private _state;
|
|
7
|
+
private _sr;
|
|
9
8
|
constructor(ort: ONNXRuntimeAPI, pathToModel: string);
|
|
10
|
-
static new: (ort: ONNXRuntimeAPI, pathToModel: string) => Promise<SileroVadModel>;
|
|
9
|
+
static readonly new: (ort: ONNXRuntimeAPI, pathToModel: string) => Promise<SileroVadModel>;
|
|
11
10
|
init(): Promise<void>;
|
|
11
|
+
resetState: () => void;
|
|
12
12
|
process(audioFrame: Float32Array): Promise<SpeechProbabilities>;
|
|
13
|
-
resetState(): void;
|
|
14
13
|
}
|
|
15
14
|
export { SileroVadModel };
|
|
@@ -21,16 +21,23 @@ exports.SileroVadModel = void 0;
|
|
|
21
21
|
* limitations under the License.
|
|
22
22
|
*/
|
|
23
23
|
const fs_1 = require("fs");
|
|
24
|
+
function getNewState(ortInstance) {
|
|
25
|
+
const zeroes = Array(2 * 128).fill(0);
|
|
26
|
+
return new ortInstance.Tensor("float32", zeroes, [2, 1, 128]);
|
|
27
|
+
}
|
|
24
28
|
class SileroVadModel {
|
|
25
29
|
constructor(ort, pathToModel) {
|
|
26
30
|
this.ort = ort;
|
|
27
31
|
this.pathToModel = pathToModel;
|
|
32
|
+
this.resetState = () => {
|
|
33
|
+
this._state = getNewState(this.ort);
|
|
34
|
+
};
|
|
28
35
|
}
|
|
29
36
|
async init() {
|
|
30
37
|
const modelArrayBuffer = (0, fs_1.readFileSync)(this.pathToModel).buffer;
|
|
31
38
|
this._session = await this.ort.InferenceSession.create(modelArrayBuffer);
|
|
32
39
|
this._sr = new this.ort.Tensor("int64", [16000n]);
|
|
33
|
-
this.
|
|
40
|
+
this._state = getNewState(this.ort);
|
|
34
41
|
}
|
|
35
42
|
async process(audioFrame) {
|
|
36
43
|
const t = new this.ort.Tensor("float32", audioFrame, [
|
|
@@ -39,22 +46,15 @@ class SileroVadModel {
|
|
|
39
46
|
]);
|
|
40
47
|
const inputs = {
|
|
41
48
|
input: t,
|
|
42
|
-
|
|
43
|
-
c: this._c,
|
|
49
|
+
state: this._state,
|
|
44
50
|
sr: this._sr
|
|
45
51
|
};
|
|
46
52
|
const out = await this._session.run(inputs);
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
const [isSpeech] = out.output.data;
|
|
53
|
+
this._state = out["stateN"];
|
|
54
|
+
const [isSpeech] = out["output"].data;
|
|
50
55
|
const notSpeech = 1 - isSpeech;
|
|
51
56
|
return { notSpeech, isSpeech };
|
|
52
57
|
}
|
|
53
|
-
resetState() {
|
|
54
|
-
const zeroes = Array(2 * 64).fill(0);
|
|
55
|
-
this._h = new this.ort.Tensor("float32", zeroes, [2, 1, 64]);
|
|
56
|
-
this._c = new this.ort.Tensor("float32", zeroes, [2, 1, 64]);
|
|
57
|
-
}
|
|
58
58
|
}
|
|
59
59
|
exports.SileroVadModel = SileroVadModel;
|
|
60
60
|
_a = SileroVadModel;
|
|
@@ -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.d.ts
CHANGED
package/dist/vad/makeVad.js
CHANGED
|
@@ -53,17 +53,13 @@ exports.makeVad = makeVad;
|
|
|
53
53
|
* See the License for the specific language governing permissions and
|
|
54
54
|
* limitations under the License.
|
|
55
55
|
*/
|
|
56
|
-
const path_1 = require("path");
|
|
57
|
-
const logger_1 = require("@fonoster/logger");
|
|
58
56
|
const ort = __importStar(require("onnxruntime-node"));
|
|
59
57
|
const chunkToFloat32Array_1 = require("./chunkToFloat32Array");
|
|
60
58
|
const SileroVadModel_1 = require("./SileroVadModel");
|
|
61
|
-
const
|
|
62
|
-
const BUFFER_SIZE = 16000;
|
|
59
|
+
const BUFFER_SIZE = 512;
|
|
63
60
|
async function makeVad(params) {
|
|
64
61
|
const { pathToModel, activationThreshold, deactivationThreshold, debounceFrames } = params;
|
|
65
|
-
const
|
|
66
|
-
const silero = await SileroVadModel_1.SileroVadModel.new(ort, effectivePath);
|
|
62
|
+
const silero = await SileroVadModel_1.SileroVadModel.new(ort, pathToModel);
|
|
67
63
|
let audioBuffer = [];
|
|
68
64
|
let isSpeechActive = false;
|
|
69
65
|
let consecutiveSpeechFrames = 0;
|
|
@@ -77,7 +73,6 @@ async function makeVad(params) {
|
|
|
77
73
|
const audioFrame = buffer.slice(0, BUFFER_SIZE);
|
|
78
74
|
const remainingBuffer = buffer.slice(BUFFER_SIZE);
|
|
79
75
|
const result = await silero.process(new Float32Array(audioFrame));
|
|
80
|
-
logger.silly("last vad result", { ...result });
|
|
81
76
|
if (result.isSpeech > activationThreshold) {
|
|
82
77
|
consecutiveNonSpeechFrames = 0; // Reset non-speech counter
|
|
83
78
|
consecutiveSpeechFrames++;
|
package/dist/vad/types.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ type ONNXRuntimeAPI = {
|
|
|
11
11
|
create(modelArrayBuffer: ArrayBuffer): Promise<unknown>;
|
|
12
12
|
};
|
|
13
13
|
Tensor: {
|
|
14
|
-
new (type: "int64",
|
|
15
|
-
new (type: "
|
|
16
|
-
new (type: "float32", data: Float32Array, dims: [1,
|
|
14
|
+
new (type: "int64", data: BigInt[]): unknown;
|
|
15
|
+
new (type: "int64", data: BigInt[], dims: [1]): unknown;
|
|
16
|
+
new (type: "float32", data: Float32Array | number[], dims: [2, 1, 128]): unknown;
|
|
17
17
|
new (type: "float32", data: Float32Array, dims: [1, number]): unknown;
|
|
18
18
|
};
|
|
19
19
|
};
|
package/dist/vadWorker.js
CHANGED
|
@@ -20,7 +20,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
*/
|
|
21
21
|
const worker_threads_1 = require("worker_threads");
|
|
22
22
|
const SileroVad_1 = require("./vad/SileroVad");
|
|
23
|
-
const
|
|
23
|
+
const envs_1 = require("./envs");
|
|
24
|
+
const vad = new SileroVad_1.SileroVad({
|
|
25
|
+
...worker_threads_1.workerData,
|
|
26
|
+
pathToModel: envs_1.SILERO_VAD_MODEL_PATH
|
|
27
|
+
});
|
|
24
28
|
vad.init().then(() => {
|
|
25
29
|
worker_threads_1.parentPort?.on("message", (chunk) => {
|
|
26
30
|
vad.processChunk(chunk, (voiceActivity) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.55",
|
|
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.55",
|
|
40
|
+
"@fonoster/logger": "^0.7.55",
|
|
41
|
+
"@fonoster/types": "^0.7.55",
|
|
42
|
+
"@fonoster/voice": "^0.7.55",
|
|
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": "9e6953d9c5fdd753d3742ef3da84b44d56c4c4ed"
|
|
61
61
|
}
|
package/silero_vad.onnx
CHANGED
|
Binary file
|