@absolutejs/voice 0.0.22-beta.603 → 0.0.22-beta.605

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.js CHANGED
@@ -3941,9 +3941,7 @@ var createVoiceSession = (options) => {
3941
3941
  return Math.round(minSilenceMs + (silenceMs - minSilenceMs) * (1 - complete));
3942
3942
  };
3943
3943
  let speculativeReply = null;
3944
- let speculativeTimer = null;
3945
3944
  let speculationAttempted = false;
3946
- console.info(`[voice][p3dbg] session ${options.id} route.speculate wired=${Boolean(options.route.speculate)}`);
3947
3945
  const sttFallback = options.sttFallback ? {
3948
3946
  adapter: options.sttFallback.adapter,
3949
3947
  completionTimeoutMs: options.sttFallback.completionTimeoutMs ?? DEFAULT_FALLBACK_COMPLETION_TIMEOUT_MS,
@@ -4477,10 +4475,6 @@ var createVoiceSession = (options) => {
4477
4475
  }, delayMs);
4478
4476
  };
4479
4477
  const clearSpeculation = () => {
4480
- if (speculativeTimer) {
4481
- clearTimeout(speculativeTimer);
4482
- speculativeTimer = null;
4483
- }
4484
4478
  speculativeReply = null;
4485
4479
  speculationAttempted = false;
4486
4480
  };
@@ -4519,14 +4513,6 @@ var createVoiceSession = (options) => {
4519
4513
  };
4520
4514
  const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
4521
4515
  scheduleTurnCommit(delayMs, "silence", reset);
4522
- if (options.route.speculate && reset && !speculationAttempted) {
4523
- speculationAttempted = true;
4524
- console.info(`[voice][p3dbg] armed speculation delay=${SPECULATIVE_DELAY_MS} reason=silence session=${options.id}`);
4525
- speculativeTimer = setTimeout(() => {
4526
- speculativeTimer = null;
4527
- runSpeculation();
4528
- }, SPECULATIVE_DELAY_MS);
4529
- }
4530
4516
  };
4531
4517
  const runScheduledCommit = async (reason) => {
4532
4518
  await api.commitTurn(reason);
@@ -6335,6 +6321,7 @@ var createVoiceSession = (options) => {
6335
6321
  const conditionedAudio = conditionAudioChunk(inboundAudio, options.audioConditioning);
6336
6322
  const audioLevel = measureAudioLevel(conditionedAudio);
6337
6323
  const shouldStoreAudio = speechDetected || audioLevel >= turnDetection.speechThreshold;
6324
+ let silenceElapsedMs;
6338
6325
  await writeSession((currentSession) => {
6339
6326
  currentSession.currentTurn.lastAudioAt = Date.now();
6340
6327
  currentSession.lastActivityAt = Date.now();
@@ -6345,7 +6332,13 @@ var createVoiceSession = (options) => {
6345
6332
  } else if (speechDetected && currentSession.currentTurn.silenceStartedAt === undefined) {
6346
6333
  currentSession.currentTurn.silenceStartedAt = Date.now();
6347
6334
  }
6335
+ const startedAt = currentSession.currentTurn.silenceStartedAt;
6336
+ silenceElapsedMs = startedAt === undefined ? undefined : Date.now() - startedAt;
6348
6337
  });
6338
+ if (options.route.speculate && !speculationAttempted && speechDetected && silenceElapsedMs !== undefined && silenceElapsedMs >= SPECULATIVE_DELAY_MS) {
6339
+ speculationAttempted = true;
6340
+ runSpeculation();
6341
+ }
6349
6342
  if (shouldStoreAudio) {
6350
6343
  pushTurnAudio(conditionedAudio);
6351
6344
  }
@@ -6168,9 +6168,7 @@ var createVoiceSession = (options) => {
6168
6168
  return Math.round(minSilenceMs + (silenceMs - minSilenceMs) * (1 - complete));
6169
6169
  };
6170
6170
  let speculativeReply = null;
6171
- let speculativeTimer = null;
6172
6171
  let speculationAttempted = false;
6173
- console.info(`[voice][p3dbg] session ${options.id} route.speculate wired=${Boolean(options.route.speculate)}`);
6174
6172
  const sttFallback = options.sttFallback ? {
6175
6173
  adapter: options.sttFallback.adapter,
6176
6174
  completionTimeoutMs: options.sttFallback.completionTimeoutMs ?? DEFAULT_FALLBACK_COMPLETION_TIMEOUT_MS,
@@ -6704,10 +6702,6 @@ var createVoiceSession = (options) => {
6704
6702
  }, delayMs);
6705
6703
  };
6706
6704
  const clearSpeculation = () => {
6707
- if (speculativeTimer) {
6708
- clearTimeout(speculativeTimer);
6709
- speculativeTimer = null;
6710
- }
6711
6705
  speculativeReply = null;
6712
6706
  speculationAttempted = false;
6713
6707
  };
@@ -6746,14 +6740,6 @@ var createVoiceSession = (options) => {
6746
6740
  };
6747
6741
  const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
6748
6742
  scheduleTurnCommit(delayMs, "silence", reset);
6749
- if (options.route.speculate && reset && !speculationAttempted) {
6750
- speculationAttempted = true;
6751
- console.info(`[voice][p3dbg] armed speculation delay=${SPECULATIVE_DELAY_MS} reason=silence session=${options.id}`);
6752
- speculativeTimer = setTimeout(() => {
6753
- speculativeTimer = null;
6754
- runSpeculation();
6755
- }, SPECULATIVE_DELAY_MS);
6756
- }
6757
6743
  };
6758
6744
  const runScheduledCommit = async (reason) => {
6759
6745
  await api.commitTurn(reason);
@@ -8562,6 +8548,7 @@ var createVoiceSession = (options) => {
8562
8548
  const conditionedAudio = conditionAudioChunk(inboundAudio, options.audioConditioning);
8563
8549
  const audioLevel = measureAudioLevel(conditionedAudio);
8564
8550
  const shouldStoreAudio = speechDetected || audioLevel >= turnDetection.speechThreshold;
8551
+ let silenceElapsedMs;
8565
8552
  await writeSession((currentSession) => {
8566
8553
  currentSession.currentTurn.lastAudioAt = Date.now();
8567
8554
  currentSession.lastActivityAt = Date.now();
@@ -8572,7 +8559,13 @@ var createVoiceSession = (options) => {
8572
8559
  } else if (speechDetected && currentSession.currentTurn.silenceStartedAt === undefined) {
8573
8560
  currentSession.currentTurn.silenceStartedAt = Date.now();
8574
8561
  }
8562
+ const startedAt = currentSession.currentTurn.silenceStartedAt;
8563
+ silenceElapsedMs = startedAt === undefined ? undefined : Date.now() - startedAt;
8575
8564
  });
8565
+ if (options.route.speculate && !speculationAttempted && speechDetected && silenceElapsedMs !== undefined && silenceElapsedMs >= SPECULATIVE_DELAY_MS) {
8566
+ speculationAttempted = true;
8567
+ runSpeculation();
8568
+ }
8576
8569
  if (shouldStoreAudio) {
8577
8570
  pushTurnAudio(conditionedAudio);
8578
8571
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.603",
3
+ "version": "0.0.22-beta.605",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",