@fonoster/autopilot 0.9.40 → 0.9.43

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.
@@ -2,8 +2,7 @@ import { AutopilotParams } from "./types";
2
2
  declare class Autopilot {
3
3
  private readonly params;
4
4
  private readonly actor;
5
- private readonly vadWorker;
6
- private vadWorkerReady;
5
+ private vad;
7
6
  constructor(params: AutopilotParams);
8
7
  start(): Promise<void>;
9
8
  stop(): void;
package/dist/Autopilot.js CHANGED
@@ -23,29 +23,15 @@ exports.Autopilot = void 0;
23
23
  * limitations under the License.
24
24
  */
25
25
  const path_1 = __importDefault(require("path"));
26
- const worker_threads_1 = require("worker_threads");
27
26
  const logger_1 = require("@fonoster/logger");
28
27
  const xstate_1 = require("xstate");
29
28
  const machine_1 = require("./machine/machine");
29
+ const vad_1 = require("./vad");
30
30
  const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
31
31
  class Autopilot {
32
32
  constructor(params) {
33
33
  this.params = params;
34
34
  const { voice, languageModel, conversationSettings } = this.params;
35
- const vadWorkerPath = path_1.default.resolve(__dirname, "../dist", "./vadWorker");
36
- this.vadWorker = new worker_threads_1.Worker(vadWorkerPath, {
37
- workerData: conversationSettings.vad
38
- });
39
- this.vadWorkerReady = new Promise((resolve, reject) => {
40
- logger.verbose("waiting for vad worker to be ready");
41
- this.vadWorker.once("message", (message) => {
42
- if (message === "VAD_READY") {
43
- logger.verbose("vad worker is ready");
44
- resolve();
45
- }
46
- });
47
- this.vadWorker.once("error", reject);
48
- });
49
35
  this.actor = (0, xstate_1.createActor)(machine_1.machine, {
50
36
  input: {
51
37
  conversationSettings,
@@ -55,22 +41,23 @@ class Autopilot {
55
41
  });
56
42
  }
57
43
  async start() {
58
- // Wait for all the streams and vad worker to be ready before proceeding starting the actor
59
- await this.vadWorkerReady;
44
+ const vadParams = this.params.conversationSettings.vad;
45
+ const sileroVad = new vad_1.SileroVad({
46
+ pathToModel: vadParams.pathToModel ||
47
+ path_1.default.resolve(__dirname, "..", "silero_vad_v5.onnx"),
48
+ activationThreshold: vadParams.activationThreshold,
49
+ deactivationThreshold: vadParams.deactivationThreshold,
50
+ debounceFrames: vadParams.debounceFrames
51
+ });
52
+ await sileroVad.init();
53
+ this.vad = sileroVad;
60
54
  await this.setupVoiceStream();
61
55
  await this.setupSpeechGathering();
62
56
  this.actor.start();
57
+ logger.verbose("autopilot is ready");
63
58
  this.actor.subscribe((state) => {
64
59
  logger.verbose("actor's new state is", { state: state.value });
65
60
  });
66
- this.vadWorker.on("error", (err) => {
67
- logger.error("vad worker error", err);
68
- });
69
- this.vadWorker.on("exit", (code) => {
70
- if (code !== 0) {
71
- logger.error("vad worker stopped with exit code", { code });
72
- }
73
- });
74
61
  }
75
62
  stop() {
76
63
  logger.verbose("stopping autopilot");
@@ -80,19 +67,23 @@ class Autopilot {
80
67
  const { voice } = this.params;
81
68
  const stream = await voice.stream();
82
69
  stream.onData(this.handleVoicePayload.bind(this));
83
- this.vadWorker.on("message", (event) => {
84
- logger.verbose("received speech event from vad", { event });
85
- if (event === "SPEECH_START") {
86
- this.actor.send({ type: "SPEECH_START" });
87
- }
88
- else if (event === "SPEECH_END") {
89
- this.actor.send({ type: "SPEECH_END" });
90
- }
91
- });
92
70
  }
93
71
  handleVoicePayload(chunk) {
94
72
  try {
95
- this.vadWorker.postMessage(chunk);
73
+ if (!this.vad) {
74
+ logger.error("VAD not initialized");
75
+ return;
76
+ }
77
+ // Process the audio chunk with the VAD directly
78
+ this.vad.processChunk(chunk, (event) => {
79
+ logger.verbose("received speech event from vad", { event });
80
+ if (event === "SPEECH_START") {
81
+ this.actor.send({ type: "SPEECH_START" });
82
+ }
83
+ else if (event === "SPEECH_END") {
84
+ this.actor.send({ type: "SPEECH_END" });
85
+ }
86
+ });
96
87
  }
97
88
  catch (err) {
98
89
  logger.error("an error occurred while processing vad", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/autopilot",
3
- "version": "0.9.40",
3
+ "version": "0.9.43",
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",
@@ -33,11 +33,11 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@aws-sdk/client-s3": "^3.712.0",
36
- "@fonoster/common": "^0.9.35",
37
- "@fonoster/logger": "^0.9.30",
38
- "@fonoster/sdk": "^0.9.37",
39
- "@fonoster/types": "^0.9.30",
40
- "@fonoster/voice": "^0.9.35",
36
+ "@fonoster/common": "^0.9.42",
37
+ "@fonoster/logger": "^0.9.42",
38
+ "@fonoster/sdk": "^0.9.42",
39
+ "@fonoster/types": "^0.9.42",
40
+ "@fonoster/voice": "^0.9.42",
41
41
  "@langchain/community": "^0.3.32",
42
42
  "@langchain/core": "^0.3.40",
43
43
  "@langchain/groq": "^0.1.3",
@@ -56,5 +56,5 @@
56
56
  "xstate": "^5.17.3",
57
57
  "zod": "^3.23.8"
58
58
  },
59
- "gitHead": "b5150ccfba8a96468d4e478796ac8e84fe57ff07"
59
+ "gitHead": "7fa2745908c3ced8a5401a48b26cf26c8fc09c2c"
60
60
  }