@absolutejs/voice 0.0.22-beta.584 → 0.0.22-beta.585
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/angular/index.js +126 -0
- package/dist/client/htmxBootstrap.js +11 -0
- package/dist/client/index.js +126 -0
- package/dist/core/turnDetection.d.ts +1 -0
- package/dist/core/types.d.ts +4 -0
- package/dist/embed/index.js +11 -0
- package/dist/embed/voice-widget.js +8 -8
- package/dist/index.js +177 -119
- package/dist/react/index.js +126 -0
- package/dist/svelte/index.js +126 -0
- package/dist/testing/index.js +57 -2
- package/dist/vue/index.js +126 -0
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -86,6 +86,7 @@ var __require = import.meta.require;
|
|
|
86
86
|
// src/core/turnDetection.ts
|
|
87
87
|
var DEFAULT_SILENCE_MS = 700;
|
|
88
88
|
var DEFAULT_SPEECH_THRESHOLD = 0.015;
|
|
89
|
+
var DEFAULT_SEMANTIC_VETO_RECHECK_MS = 1200;
|
|
89
90
|
var toUint8Array = (audio) => {
|
|
90
91
|
if (audio instanceof ArrayBuffer) {
|
|
91
92
|
return new Uint8Array(audio);
|
|
@@ -3133,18 +3134,24 @@ var resolveAudioConditioningConfig = (config) => {
|
|
|
3133
3134
|
var TURN_PROFILE_DEFAULTS = {
|
|
3134
3135
|
balanced: {
|
|
3135
3136
|
qualityProfile: "general",
|
|
3137
|
+
semanticVetoMaxMs: 0,
|
|
3138
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
3136
3139
|
silenceMs: 1400,
|
|
3137
3140
|
speechThreshold: 0.012,
|
|
3138
3141
|
transcriptStabilityMs: 1000
|
|
3139
3142
|
},
|
|
3140
3143
|
fast: {
|
|
3141
3144
|
qualityProfile: "general",
|
|
3145
|
+
semanticVetoMaxMs: 0,
|
|
3146
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
3142
3147
|
silenceMs: 700,
|
|
3143
3148
|
speechThreshold: 0.015,
|
|
3144
3149
|
transcriptStabilityMs: 450
|
|
3145
3150
|
},
|
|
3146
3151
|
"long-form": {
|
|
3147
3152
|
qualityProfile: "general",
|
|
3153
|
+
semanticVetoMaxMs: 0,
|
|
3154
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
3148
3155
|
silenceMs: 2200,
|
|
3149
3156
|
speechThreshold: 0.01,
|
|
3150
3157
|
transcriptStabilityMs: 1500
|
|
@@ -3178,6 +3185,8 @@ var resolveTurnDetectionConfig = (config) => {
|
|
|
3178
3185
|
return {
|
|
3179
3186
|
profile,
|
|
3180
3187
|
qualityProfile,
|
|
3188
|
+
semanticVetoMaxMs: config?.semanticVetoMaxMs ?? preset.semanticVetoMaxMs,
|
|
3189
|
+
semanticVetoRecheckMs: config?.semanticVetoRecheckMs ?? preset.semanticVetoRecheckMs,
|
|
3181
3190
|
silenceMs: config?.silenceMs ?? quality.silenceMs ?? preset.silenceMs,
|
|
3182
3191
|
speechThreshold: config?.speechThreshold ?? quality.speechThreshold ?? preset.speechThreshold,
|
|
3183
3192
|
transcriptStabilityMs: config?.transcriptStabilityMs ?? quality.transcriptStabilityMs ?? preset.transcriptStabilityMs
|
|
@@ -6105,8 +6114,11 @@ var createVoiceSession = (options) => {
|
|
|
6105
6114
|
const turnDetection = {
|
|
6106
6115
|
silenceMs: options.turnDetection.silenceMs ?? DEFAULT_SILENCE_MS,
|
|
6107
6116
|
speechThreshold: options.turnDetection.speechThreshold ?? DEFAULT_SPEECH_THRESHOLD,
|
|
6108
|
-
transcriptStabilityMs: options.turnDetection.transcriptStabilityMs ?? DEFAULT_TRANSCRIPT_STABILITY_MS
|
|
6117
|
+
transcriptStabilityMs: options.turnDetection.transcriptStabilityMs ?? DEFAULT_TRANSCRIPT_STABILITY_MS,
|
|
6118
|
+
semanticVetoMaxMs: options.turnDetection.semanticVetoMaxMs ?? 0,
|
|
6119
|
+
semanticVetoRecheckMs: options.turnDetection.semanticVetoRecheckMs ?? DEFAULT_SEMANTIC_VETO_RECHECK_MS
|
|
6109
6120
|
};
|
|
6121
|
+
let semanticVetoElapsedMs = 0;
|
|
6110
6122
|
const sttFallback = options.sttFallback ? {
|
|
6111
6123
|
adapter: options.sttFallback.adapter,
|
|
6112
6124
|
completionTimeoutMs: options.sttFallback.completionTimeoutMs ?? DEFAULT_FALLBACK_COMPLETION_TIMEOUT_MS,
|
|
@@ -6621,10 +6633,51 @@ var createVoiceSession = (options) => {
|
|
|
6621
6633
|
silenceTimer = setTimeout(() => {
|
|
6622
6634
|
silenceTimer = null;
|
|
6623
6635
|
pendingCommitReason = null;
|
|
6624
|
-
|
|
6636
|
+
runScheduledCommit(reason);
|
|
6625
6637
|
}, delayMs);
|
|
6626
6638
|
};
|
|
6627
6639
|
const scheduleSilenceCommit = (delayMs = turnDetection.silenceMs, reset = true) => scheduleTurnCommit(delayMs, "silence", reset);
|
|
6640
|
+
const shouldDeferSilenceCommit = async (reason) => {
|
|
6641
|
+
if (reason !== "silence" || turnDetection.semanticVetoMaxMs <= 0 || !options.semanticTurnDetector || semanticVetoElapsedMs >= turnDetection.semanticVetoMaxMs) {
|
|
6642
|
+
return false;
|
|
6643
|
+
}
|
|
6644
|
+
const session = await readSession();
|
|
6645
|
+
const { partialText, transcripts } = session.currentTurn;
|
|
6646
|
+
const userText = buildTurnText(transcripts, partialText, {
|
|
6647
|
+
partialEndedAtMs: session.currentTurn.partialEndedAt,
|
|
6648
|
+
partialStartedAtMs: session.currentTurn.partialStartedAt
|
|
6649
|
+
});
|
|
6650
|
+
if (!userText) {
|
|
6651
|
+
return false;
|
|
6652
|
+
}
|
|
6653
|
+
const silenceMs = session.currentTurn.silenceStartedAt !== undefined ? Date.now() - session.currentTurn.silenceStartedAt : turnDetection.silenceMs;
|
|
6654
|
+
let endOfTurn = true;
|
|
6655
|
+
try {
|
|
6656
|
+
const verdict = await Promise.resolve(options.semanticTurnDetector.evaluate({
|
|
6657
|
+
lastFinalTranscript: transcripts.at(-1),
|
|
6658
|
+
partialText,
|
|
6659
|
+
silenceMs,
|
|
6660
|
+
transcripts
|
|
6661
|
+
}));
|
|
6662
|
+
endOfTurn = verdict.endOfTurn;
|
|
6663
|
+
} catch {
|
|
6664
|
+
return false;
|
|
6665
|
+
}
|
|
6666
|
+
if (endOfTurn !== false) {
|
|
6667
|
+
return false;
|
|
6668
|
+
}
|
|
6669
|
+
const remaining = turnDetection.semanticVetoMaxMs - semanticVetoElapsedMs;
|
|
6670
|
+
const extendMs = Math.max(1, Math.min(turnDetection.semanticVetoRecheckMs, remaining));
|
|
6671
|
+
semanticVetoElapsedMs += extendMs;
|
|
6672
|
+
scheduleTurnCommit(extendMs, reason);
|
|
6673
|
+
return true;
|
|
6674
|
+
};
|
|
6675
|
+
const runScheduledCommit = async (reason) => {
|
|
6676
|
+
if (await shouldDeferSilenceCommit(reason)) {
|
|
6677
|
+
return;
|
|
6678
|
+
}
|
|
6679
|
+
await api.commitTurn(reason);
|
|
6680
|
+
};
|
|
6628
6681
|
const requestTurnCommit = async (reason) => {
|
|
6629
6682
|
const session = await readSession();
|
|
6630
6683
|
const text = buildTurnText(session.currentTurn.transcripts, session.currentTurn.partialText, {
|
|
@@ -7336,6 +7389,7 @@ var createVoiceSession = (options) => {
|
|
|
7336
7389
|
session2.lastActivityAt = Date.now();
|
|
7337
7390
|
session2.status = "active";
|
|
7338
7391
|
});
|
|
7392
|
+
semanticVetoElapsedMs = 0;
|
|
7339
7393
|
if (silenceTimer && pendingCommitReason === "vendor") {
|
|
7340
7394
|
scheduleTurnCommit(getVendorCommitDelayMs(), "vendor");
|
|
7341
7395
|
}
|
|
@@ -8039,6 +8093,7 @@ var createVoiceSession = (options) => {
|
|
|
8039
8093
|
};
|
|
8040
8094
|
const commitTurnInternal = async (reason = "manual") => {
|
|
8041
8095
|
clearSilenceTimer();
|
|
8096
|
+
semanticVetoElapsedMs = 0;
|
|
8042
8097
|
backchannelDriver?.reset();
|
|
8043
8098
|
amdLastTurnCommitAt = Date.now();
|
|
8044
8099
|
const session = await readSession();
|
package/dist/vue/index.js
CHANGED
|
@@ -11660,22 +11660,146 @@ var resolveAudioConditioningConfig = (config) => {
|
|
|
11660
11660
|
};
|
|
11661
11661
|
};
|
|
11662
11662
|
|
|
11663
|
+
// src/core/turnDetection.ts
|
|
11664
|
+
var DEFAULT_SILENCE_MS = 700;
|
|
11665
|
+
var DEFAULT_SPEECH_THRESHOLD = 0.015;
|
|
11666
|
+
var DEFAULT_SEMANTIC_VETO_RECHECK_MS = 1200;
|
|
11667
|
+
var toUint8Array = (audio) => {
|
|
11668
|
+
if (audio instanceof ArrayBuffer) {
|
|
11669
|
+
return new Uint8Array(audio);
|
|
11670
|
+
}
|
|
11671
|
+
return new Uint8Array(audio.buffer, audio.byteOffset, audio.byteLength);
|
|
11672
|
+
};
|
|
11673
|
+
var measureAudioLevel = (audio) => {
|
|
11674
|
+
const bytes = toUint8Array(audio);
|
|
11675
|
+
if (bytes.byteLength < 2) {
|
|
11676
|
+
return 0;
|
|
11677
|
+
}
|
|
11678
|
+
const samples = new Int16Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 2));
|
|
11679
|
+
if (samples.length === 0) {
|
|
11680
|
+
return 0;
|
|
11681
|
+
}
|
|
11682
|
+
let sumSquares = 0;
|
|
11683
|
+
for (const sample of samples) {
|
|
11684
|
+
const normalized = sample / 32768;
|
|
11685
|
+
sumSquares += normalized * normalized;
|
|
11686
|
+
}
|
|
11687
|
+
return Math.sqrt(sumSquares / samples.length);
|
|
11688
|
+
};
|
|
11689
|
+
var normalizeText = (value) => value.trim().replace(/\s+/g, " ");
|
|
11690
|
+
var countWords = (value) => value.length > 0 ? value.split(" ").length : 0;
|
|
11691
|
+
var selectPreferredTranscriptText = (currentText, nextText) => {
|
|
11692
|
+
const current = normalizeText(currentText);
|
|
11693
|
+
const next = normalizeText(nextText);
|
|
11694
|
+
if (!current) {
|
|
11695
|
+
return next;
|
|
11696
|
+
}
|
|
11697
|
+
if (!next) {
|
|
11698
|
+
return current;
|
|
11699
|
+
}
|
|
11700
|
+
if (current === next || current.includes(next)) {
|
|
11701
|
+
return current;
|
|
11702
|
+
}
|
|
11703
|
+
if (next.includes(current)) {
|
|
11704
|
+
return next;
|
|
11705
|
+
}
|
|
11706
|
+
if (countWords(next) > countWords(current)) {
|
|
11707
|
+
return next;
|
|
11708
|
+
}
|
|
11709
|
+
if (countWords(next) === countWords(current) && next.length > current.length) {
|
|
11710
|
+
return next;
|
|
11711
|
+
}
|
|
11712
|
+
return current;
|
|
11713
|
+
};
|
|
11714
|
+
var mergeSequentialTranscriptText = (currentText, nextText) => {
|
|
11715
|
+
const current = normalizeText(currentText);
|
|
11716
|
+
const next = normalizeText(nextText);
|
|
11717
|
+
if (!current) {
|
|
11718
|
+
return next;
|
|
11719
|
+
}
|
|
11720
|
+
if (!next) {
|
|
11721
|
+
return current;
|
|
11722
|
+
}
|
|
11723
|
+
const currentWords = current.split(" ");
|
|
11724
|
+
const nextWords = next.split(" ");
|
|
11725
|
+
const maxOverlap = Math.min(currentWords.length, nextWords.length);
|
|
11726
|
+
for (let overlap = maxOverlap;overlap > 0; overlap -= 1) {
|
|
11727
|
+
const currentSuffix = currentWords.slice(-overlap).join(" ");
|
|
11728
|
+
const nextPrefix = nextWords.slice(0, overlap).join(" ");
|
|
11729
|
+
if (currentSuffix === nextPrefix) {
|
|
11730
|
+
return [...currentWords, ...nextWords.slice(overlap)].join(" ");
|
|
11731
|
+
}
|
|
11732
|
+
}
|
|
11733
|
+
return `${current} ${next}`.trim();
|
|
11734
|
+
};
|
|
11735
|
+
var countCommonPrefixWords = (currentText, nextText) => {
|
|
11736
|
+
const currentWords = normalizeText(currentText).split(" ").filter(Boolean);
|
|
11737
|
+
const nextWords = normalizeText(nextText).split(" ").filter(Boolean);
|
|
11738
|
+
const maxWords = Math.min(currentWords.length, nextWords.length);
|
|
11739
|
+
let count = 0;
|
|
11740
|
+
for (let index = 0;index < maxWords; index += 1) {
|
|
11741
|
+
if (currentWords[index] !== nextWords[index]) {
|
|
11742
|
+
break;
|
|
11743
|
+
}
|
|
11744
|
+
count += 1;
|
|
11745
|
+
}
|
|
11746
|
+
return count;
|
|
11747
|
+
};
|
|
11748
|
+
var mergeTranscriptTexts = (transcripts) => {
|
|
11749
|
+
const merged = [];
|
|
11750
|
+
for (const transcript of transcripts) {
|
|
11751
|
+
const nextText = normalizeText(transcript.text);
|
|
11752
|
+
if (!nextText) {
|
|
11753
|
+
continue;
|
|
11754
|
+
}
|
|
11755
|
+
const previous = merged.at(-1);
|
|
11756
|
+
if (!previous) {
|
|
11757
|
+
merged.push(nextText);
|
|
11758
|
+
continue;
|
|
11759
|
+
}
|
|
11760
|
+
if (nextText === previous || previous.includes(nextText)) {
|
|
11761
|
+
continue;
|
|
11762
|
+
}
|
|
11763
|
+
if (nextText.includes(previous)) {
|
|
11764
|
+
merged[merged.length - 1] = nextText;
|
|
11765
|
+
continue;
|
|
11766
|
+
}
|
|
11767
|
+
merged.push(nextText);
|
|
11768
|
+
}
|
|
11769
|
+
return merged.join(" ").trim();
|
|
11770
|
+
};
|
|
11771
|
+
var buildTurnText = (transcripts, partialText, options = {}) => {
|
|
11772
|
+
const finalText = mergeTranscriptTexts(transcripts);
|
|
11773
|
+
const nextPartial = normalizeText(partialText);
|
|
11774
|
+
const lastFinalEndedAtMs = [...transcripts].reverse().find((transcript) => typeof transcript.endedAtMs === "number")?.endedAtMs;
|
|
11775
|
+
if (finalText && nextPartial && typeof lastFinalEndedAtMs === "number" && typeof options.partialStartedAtMs === "number" && options.partialStartedAtMs - lastFinalEndedAtMs >= 250 && countCommonPrefixWords(finalText, nextPartial) === 0) {
|
|
11776
|
+
return mergeSequentialTranscriptText(finalText, nextPartial);
|
|
11777
|
+
}
|
|
11778
|
+
return selectPreferredTranscriptText(finalText, nextPartial);
|
|
11779
|
+
};
|
|
11780
|
+
|
|
11663
11781
|
// src/core/turnProfiles.ts
|
|
11664
11782
|
var TURN_PROFILE_DEFAULTS = {
|
|
11665
11783
|
balanced: {
|
|
11666
11784
|
qualityProfile: "general",
|
|
11785
|
+
semanticVetoMaxMs: 0,
|
|
11786
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
11667
11787
|
silenceMs: 1400,
|
|
11668
11788
|
speechThreshold: 0.012,
|
|
11669
11789
|
transcriptStabilityMs: 1000
|
|
11670
11790
|
},
|
|
11671
11791
|
fast: {
|
|
11672
11792
|
qualityProfile: "general",
|
|
11793
|
+
semanticVetoMaxMs: 0,
|
|
11794
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
11673
11795
|
silenceMs: 700,
|
|
11674
11796
|
speechThreshold: 0.015,
|
|
11675
11797
|
transcriptStabilityMs: 450
|
|
11676
11798
|
},
|
|
11677
11799
|
"long-form": {
|
|
11678
11800
|
qualityProfile: "general",
|
|
11801
|
+
semanticVetoMaxMs: 0,
|
|
11802
|
+
semanticVetoRecheckMs: DEFAULT_SEMANTIC_VETO_RECHECK_MS,
|
|
11679
11803
|
silenceMs: 2200,
|
|
11680
11804
|
speechThreshold: 0.01,
|
|
11681
11805
|
transcriptStabilityMs: 1500
|
|
@@ -11709,6 +11833,8 @@ var resolveTurnDetectionConfig = (config) => {
|
|
|
11709
11833
|
return {
|
|
11710
11834
|
profile,
|
|
11711
11835
|
qualityProfile,
|
|
11836
|
+
semanticVetoMaxMs: config?.semanticVetoMaxMs ?? preset.semanticVetoMaxMs,
|
|
11837
|
+
semanticVetoRecheckMs: config?.semanticVetoRecheckMs ?? preset.semanticVetoRecheckMs,
|
|
11712
11838
|
silenceMs: config?.silenceMs ?? quality.silenceMs ?? preset.silenceMs,
|
|
11713
11839
|
speechThreshold: config?.speechThreshold ?? quality.speechThreshold ?? preset.speechThreshold,
|
|
11714
11840
|
transcriptStabilityMs: config?.transcriptStabilityMs ?? quality.transcriptStabilityMs ?? preset.transcriptStabilityMs
|