@absolutejs/voice 0.0.22-beta.602 → 0.0.22-beta.604

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,7 +3941,6 @@ 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
3945
  console.info(`[voice][p3dbg] session ${options.id} route.speculate wired=${Boolean(options.route.speculate)}`);
3947
3946
  const sttFallback = options.sttFallback ? {
@@ -4477,10 +4476,6 @@ var createVoiceSession = (options) => {
4477
4476
  }, delayMs);
4478
4477
  };
4479
4478
  const clearSpeculation = () => {
4480
- if (speculativeTimer) {
4481
- clearTimeout(speculativeTimer);
4482
- speculativeTimer = null;
4483
- }
4484
4479
  speculativeReply = null;
4485
4480
  speculationAttempted = false;
4486
4481
  };
@@ -4519,14 +4514,6 @@ var createVoiceSession = (options) => {
4519
4514
  };
4520
4515
  const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
4521
4516
  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
4517
  };
4531
4518
  const runScheduledCommit = async (reason) => {
4532
4519
  await api.commitTurn(reason);
@@ -6335,6 +6322,7 @@ var createVoiceSession = (options) => {
6335
6322
  const conditionedAudio = conditionAudioChunk(inboundAudio, options.audioConditioning);
6336
6323
  const audioLevel = measureAudioLevel(conditionedAudio);
6337
6324
  const shouldStoreAudio = speechDetected || audioLevel >= turnDetection.speechThreshold;
6325
+ let silenceElapsedMs;
6338
6326
  await writeSession((currentSession) => {
6339
6327
  currentSession.currentTurn.lastAudioAt = Date.now();
6340
6328
  currentSession.lastActivityAt = Date.now();
@@ -6345,7 +6333,13 @@ var createVoiceSession = (options) => {
6345
6333
  } else if (speechDetected && currentSession.currentTurn.silenceStartedAt === undefined) {
6346
6334
  currentSession.currentTurn.silenceStartedAt = Date.now();
6347
6335
  }
6336
+ const startedAt = currentSession.currentTurn.silenceStartedAt;
6337
+ silenceElapsedMs = startedAt === undefined ? undefined : Date.now() - startedAt;
6348
6338
  });
6339
+ if (options.route.speculate && !speculationAttempted && speechDetected && silenceElapsedMs !== undefined && silenceElapsedMs >= SPECULATIVE_DELAY_MS) {
6340
+ speculationAttempted = true;
6341
+ runSpeculation();
6342
+ }
6349
6343
  if (shouldStoreAudio) {
6350
6344
  pushTurnAudio(conditionedAudio);
6351
6345
  }
@@ -39538,6 +39532,7 @@ var voice = (config) => {
39538
39532
  onSession: config.onSession,
39539
39533
  onTransfer: config.onTransfer,
39540
39534
  onTurn,
39535
+ speculate: config.speculate,
39541
39536
  onVoicemail: config.onVoicemail,
39542
39537
  onCallEnd: async (input) => {
39543
39538
  let hookError;
@@ -6168,7 +6168,6 @@ 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
6172
  console.info(`[voice][p3dbg] session ${options.id} route.speculate wired=${Boolean(options.route.speculate)}`);
6174
6173
  const sttFallback = options.sttFallback ? {
@@ -6704,10 +6703,6 @@ var createVoiceSession = (options) => {
6704
6703
  }, delayMs);
6705
6704
  };
6706
6705
  const clearSpeculation = () => {
6707
- if (speculativeTimer) {
6708
- clearTimeout(speculativeTimer);
6709
- speculativeTimer = null;
6710
- }
6711
6706
  speculativeReply = null;
6712
6707
  speculationAttempted = false;
6713
6708
  };
@@ -6746,14 +6741,6 @@ var createVoiceSession = (options) => {
6746
6741
  };
6747
6742
  const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
6748
6743
  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
6744
  };
6758
6745
  const runScheduledCommit = async (reason) => {
6759
6746
  await api.commitTurn(reason);
@@ -8562,6 +8549,7 @@ var createVoiceSession = (options) => {
8562
8549
  const conditionedAudio = conditionAudioChunk(inboundAudio, options.audioConditioning);
8563
8550
  const audioLevel = measureAudioLevel(conditionedAudio);
8564
8551
  const shouldStoreAudio = speechDetected || audioLevel >= turnDetection.speechThreshold;
8552
+ let silenceElapsedMs;
8565
8553
  await writeSession((currentSession) => {
8566
8554
  currentSession.currentTurn.lastAudioAt = Date.now();
8567
8555
  currentSession.lastActivityAt = Date.now();
@@ -8572,7 +8560,13 @@ var createVoiceSession = (options) => {
8572
8560
  } else if (speechDetected && currentSession.currentTurn.silenceStartedAt === undefined) {
8573
8561
  currentSession.currentTurn.silenceStartedAt = Date.now();
8574
8562
  }
8563
+ const startedAt = currentSession.currentTurn.silenceStartedAt;
8564
+ silenceElapsedMs = startedAt === undefined ? undefined : Date.now() - startedAt;
8575
8565
  });
8566
+ if (options.route.speculate && !speculationAttempted && speechDetected && silenceElapsedMs !== undefined && silenceElapsedMs >= SPECULATIVE_DELAY_MS) {
8567
+ speculationAttempted = true;
8568
+ runSpeculation();
8569
+ }
8576
8570
  if (shouldStoreAudio) {
8577
8571
  pushTurnAudio(conditionedAudio);
8578
8572
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.602",
3
+ "version": "0.0.22-beta.604",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",