@absolutejs/voice 0.0.22-beta.605 → 0.0.22-beta.607
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 +28 -19
- package/dist/testing/index.js +28 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3756,7 +3756,7 @@ var STREAM_CLAUSE_BOUNDARY = /[,;:]\s/g;
|
|
|
3756
3756
|
var MAX_TTS_CHUNK_CHARS = 320;
|
|
3757
3757
|
var STREAM_SENTENCE_END = /[.!?\u2026]['")\]]*$/;
|
|
3758
3758
|
var STREAM_IDLE_FLUSH_MS = 350;
|
|
3759
|
-
var SPECULATIVE_DELAY_MS =
|
|
3759
|
+
var SPECULATIVE_DELAY_MS = 500;
|
|
3760
3760
|
var nextSpeakableBoundary = (buffer) => {
|
|
3761
3761
|
const match = STREAM_SENTENCE_BOUNDARY.exec(buffer);
|
|
3762
3762
|
return match ? match.index + match[0].length : -1;
|
|
@@ -3940,7 +3940,7 @@ var createVoiceSession = (options) => {
|
|
|
3940
3940
|
const complete = Math.max(0, Math.min(1, lastTurnCompleteConfidence));
|
|
3941
3941
|
return Math.round(minSilenceMs + (silenceMs - minSilenceMs) * (1 - complete));
|
|
3942
3942
|
};
|
|
3943
|
-
let
|
|
3943
|
+
let speculation = null;
|
|
3944
3944
|
let speculationAttempted = false;
|
|
3945
3945
|
const sttFallback = options.sttFallback ? {
|
|
3946
3946
|
adapter: options.sttFallback.adapter,
|
|
@@ -4475,11 +4475,11 @@ var createVoiceSession = (options) => {
|
|
|
4475
4475
|
}, delayMs);
|
|
4476
4476
|
};
|
|
4477
4477
|
const clearSpeculation = () => {
|
|
4478
|
-
|
|
4478
|
+
speculation = null;
|
|
4479
4479
|
speculationAttempted = false;
|
|
4480
4480
|
};
|
|
4481
4481
|
const runSpeculation = async () => {
|
|
4482
|
-
if (!options.route.speculate ||
|
|
4482
|
+
if (!options.route.speculate || speculation) {
|
|
4483
4483
|
return;
|
|
4484
4484
|
}
|
|
4485
4485
|
const session = await readSession();
|
|
@@ -4496,20 +4496,17 @@ var createVoiceSession = (options) => {
|
|
|
4496
4496
|
text: pendingText,
|
|
4497
4497
|
transcripts: session.currentTurn.transcripts
|
|
4498
4498
|
};
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
console.info(`[voice][p3] speculate
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
} catch (error) {
|
|
4511
|
-
console.info(`[voice][p3] speculate error: ${error instanceof Error ? error.message : String(error)}`);
|
|
4512
|
-
}
|
|
4499
|
+
const speculate = options.route.speculate;
|
|
4500
|
+
const promise = Promise.resolve(speculate({
|
|
4501
|
+
api,
|
|
4502
|
+
context: options.context,
|
|
4503
|
+
session,
|
|
4504
|
+
turn: provisionalTurn
|
|
4505
|
+
})).then((result) => result && result.text.trim() ? { text: result.text } : null).catch((error) => {
|
|
4506
|
+
console.info(`[voice][p3] speculate error session=${session.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
4507
|
+
return null;
|
|
4508
|
+
});
|
|
4509
|
+
speculation = { pendingText, promise };
|
|
4513
4510
|
};
|
|
4514
4511
|
const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
|
|
4515
4512
|
scheduleTurnCommit(delayMs, "silence", reset);
|
|
@@ -5695,8 +5692,20 @@ var createVoiceSession = (options) => {
|
|
|
5695
5692
|
let committedOutput;
|
|
5696
5693
|
const onTurnStartedAt = Date.now();
|
|
5697
5694
|
logVoiceTiming(session.id, "session.commit-to-onturn", onTurnStartedAt - (turn.committedAt || onTurnStartedAt), { fillerScheduled: fillerTimer !== null });
|
|
5698
|
-
const
|
|
5695
|
+
const pendingSpeculation = speculation;
|
|
5699
5696
|
clearSpeculation();
|
|
5697
|
+
let reusableSpeculation;
|
|
5698
|
+
if (pendingSpeculation && pendingSpeculation.pendingText === turn.text) {
|
|
5699
|
+
const speculated = await pendingSpeculation.promise;
|
|
5700
|
+
if (speculated?.text) {
|
|
5701
|
+
reusableSpeculation = { text: speculated.text };
|
|
5702
|
+
logVoiceTiming(session.id, "p3.adopted-speculation", 0, {
|
|
5703
|
+
chars: speculated.text.length
|
|
5704
|
+
});
|
|
5705
|
+
}
|
|
5706
|
+
} else {
|
|
5707
|
+
pendingSpeculation?.promise;
|
|
5708
|
+
}
|
|
5700
5709
|
try {
|
|
5701
5710
|
const onTurnPromise = options.route.onTurn({
|
|
5702
5711
|
api,
|
package/dist/testing/index.js
CHANGED
|
@@ -5983,7 +5983,7 @@ var STREAM_CLAUSE_BOUNDARY = /[,;:]\s/g;
|
|
|
5983
5983
|
var MAX_TTS_CHUNK_CHARS = 320;
|
|
5984
5984
|
var STREAM_SENTENCE_END = /[.!?\u2026]['")\]]*$/;
|
|
5985
5985
|
var STREAM_IDLE_FLUSH_MS = 350;
|
|
5986
|
-
var SPECULATIVE_DELAY_MS =
|
|
5986
|
+
var SPECULATIVE_DELAY_MS = 500;
|
|
5987
5987
|
var nextSpeakableBoundary = (buffer) => {
|
|
5988
5988
|
const match = STREAM_SENTENCE_BOUNDARY.exec(buffer);
|
|
5989
5989
|
return match ? match.index + match[0].length : -1;
|
|
@@ -6167,7 +6167,7 @@ var createVoiceSession = (options) => {
|
|
|
6167
6167
|
const complete = Math.max(0, Math.min(1, lastTurnCompleteConfidence));
|
|
6168
6168
|
return Math.round(minSilenceMs + (silenceMs - minSilenceMs) * (1 - complete));
|
|
6169
6169
|
};
|
|
6170
|
-
let
|
|
6170
|
+
let speculation = null;
|
|
6171
6171
|
let speculationAttempted = false;
|
|
6172
6172
|
const sttFallback = options.sttFallback ? {
|
|
6173
6173
|
adapter: options.sttFallback.adapter,
|
|
@@ -6702,11 +6702,11 @@ var createVoiceSession = (options) => {
|
|
|
6702
6702
|
}, delayMs);
|
|
6703
6703
|
};
|
|
6704
6704
|
const clearSpeculation = () => {
|
|
6705
|
-
|
|
6705
|
+
speculation = null;
|
|
6706
6706
|
speculationAttempted = false;
|
|
6707
6707
|
};
|
|
6708
6708
|
const runSpeculation = async () => {
|
|
6709
|
-
if (!options.route.speculate ||
|
|
6709
|
+
if (!options.route.speculate || speculation) {
|
|
6710
6710
|
return;
|
|
6711
6711
|
}
|
|
6712
6712
|
const session = await readSession();
|
|
@@ -6723,20 +6723,17 @@ var createVoiceSession = (options) => {
|
|
|
6723
6723
|
text: pendingText,
|
|
6724
6724
|
transcripts: session.currentTurn.transcripts
|
|
6725
6725
|
};
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
console.info(`[voice][p3] speculate
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
} catch (error) {
|
|
6738
|
-
console.info(`[voice][p3] speculate error: ${error instanceof Error ? error.message : String(error)}`);
|
|
6739
|
-
}
|
|
6726
|
+
const speculate = options.route.speculate;
|
|
6727
|
+
const promise = Promise.resolve(speculate({
|
|
6728
|
+
api,
|
|
6729
|
+
context: options.context,
|
|
6730
|
+
session,
|
|
6731
|
+
turn: provisionalTurn
|
|
6732
|
+
})).then((result) => result && result.text.trim() ? { text: result.text } : null).catch((error) => {
|
|
6733
|
+
console.info(`[voice][p3] speculate error session=${session.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
6734
|
+
return null;
|
|
6735
|
+
});
|
|
6736
|
+
speculation = { pendingText, promise };
|
|
6740
6737
|
};
|
|
6741
6738
|
const scheduleSilenceCommit = (delayMs = adaptiveSilenceMs(), reset = true) => {
|
|
6742
6739
|
scheduleTurnCommit(delayMs, "silence", reset);
|
|
@@ -7922,8 +7919,20 @@ var createVoiceSession = (options) => {
|
|
|
7922
7919
|
let committedOutput;
|
|
7923
7920
|
const onTurnStartedAt = Date.now();
|
|
7924
7921
|
logVoiceTiming(session.id, "session.commit-to-onturn", onTurnStartedAt - (turn.committedAt || onTurnStartedAt), { fillerScheduled: fillerTimer !== null });
|
|
7925
|
-
const
|
|
7922
|
+
const pendingSpeculation = speculation;
|
|
7926
7923
|
clearSpeculation();
|
|
7924
|
+
let reusableSpeculation;
|
|
7925
|
+
if (pendingSpeculation && pendingSpeculation.pendingText === turn.text) {
|
|
7926
|
+
const speculated = await pendingSpeculation.promise;
|
|
7927
|
+
if (speculated?.text) {
|
|
7928
|
+
reusableSpeculation = { text: speculated.text };
|
|
7929
|
+
logVoiceTiming(session.id, "p3.adopted-speculation", 0, {
|
|
7930
|
+
chars: speculated.text.length
|
|
7931
|
+
});
|
|
7932
|
+
}
|
|
7933
|
+
} else {
|
|
7934
|
+
pendingSpeculation?.promise;
|
|
7935
|
+
}
|
|
7927
7936
|
try {
|
|
7928
7937
|
const onTurnPromise = options.route.onTurn({
|
|
7929
7938
|
api,
|