@mclean-capital/neura 2.1.4 → 2.1.5

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.
@@ -70105,6 +70105,34 @@ var OnnxWakeDetector = class _OnnxWakeDetector {
70105
70105
  this.accumulator = new Float32Array(0);
70106
70106
  this.replayChunks.length = 0;
70107
70107
  }
70108
+ /**
70109
+ * Clear all buffered audio and inference state without releasing the
70110
+ * ONNX sessions. Used when transitioning from ACTIVE back to PASSIVE
70111
+ * mode: the detector stays alive for the full WebSocket lifetime,
70112
+ * but any audio it buffered from before the active session is stale
70113
+ * and must be discarded so the next wake cycle starts clean.
70114
+ *
70115
+ * Why not `close()` + recreate: creating the three ONNX inference
70116
+ * sessions (mel + embedding + classifier) takes ~50-200ms, during
70117
+ * which the message handler continues routing incoming audio frames
70118
+ * to the (null) detector. Those frames get silently dropped, and
70119
+ * the user's wake word lands in the dead zone — the second wake
70120
+ * fails even though the first worked fine at connection start.
70121
+ *
70122
+ * By keeping the sessions alive and just resetting the transient
70123
+ * state, the transition is synchronous and the next audio frame
70124
+ * is processed immediately.
70125
+ */
70126
+ reset() {
70127
+ if (this.closed) return;
70128
+ this.accumulator = new Float32Array(0);
70129
+ this.ringBuffer.fill(0);
70130
+ this.writePos = 0;
70131
+ this.totalSamplesWritten = 0;
70132
+ this.replayChunks.length = 0;
70133
+ this.frameCounter = 0;
70134
+ this.lastDetectionTime = 0;
70135
+ }
70108
70136
  async tryInference() {
70109
70137
  if (this.closed || this.inferenceInProgress) return;
70110
70138
  if (this.totalSamplesWritten < RING_BUFFER_SAMPLES) return;
@@ -70523,8 +70551,6 @@ function attachWebSocket(httpServer2, services2) {
70523
70551
  if (connectionClosed || session) return;
70524
70552
  log15.info("activating voice session", { wakeTranscript });
70525
70553
  extractionTriggered = false;
70526
- wakeDetector?.close();
70527
- wakeDetector = null;
70528
70554
  let systemPromptPrefix = memoryManager ? await memoryManager.buildSystemPrompt().catch((err) => {
70529
70555
  log15.warn("memory prompt build failed", { err: String(err) });
70530
70556
  return void 0;
@@ -70558,7 +70584,7 @@ function attachWebSocket(httpServer2, services2) {
70558
70584
  triggerExtraction();
70559
70585
  session?.close();
70560
70586
  session = null;
70561
- void startWakeDetector();
70587
+ wakeDetector?.reset();
70562
70588
  }
70563
70589
  async function startWakeDetector() {
70564
70590
  if (connectionClosed) return;