@absolutejs/voice 0.0.14 → 0.0.15
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 +1 -1
- package/dist/client/index.js +1 -1
- package/dist/index.js +27 -3
- package/dist/react/index.js +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +1 -1
package/dist/angular/index.js
CHANGED
package/dist/client/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -236,12 +236,36 @@ var toVoiceSessionSummary = (session) => ({
|
|
|
236
236
|
|
|
237
237
|
// src/turnDetection.ts
|
|
238
238
|
var DEFAULT_SILENCE_MS = 700;
|
|
239
|
+
var normalizeText = (value) => value.trim().replace(/\s+/g, " ");
|
|
240
|
+
var mergeTranscriptTexts = (transcripts) => {
|
|
241
|
+
const merged = [];
|
|
242
|
+
for (const transcript of transcripts) {
|
|
243
|
+
const nextText = normalizeText(transcript.text);
|
|
244
|
+
if (!nextText) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const previous = merged.at(-1);
|
|
248
|
+
if (!previous) {
|
|
249
|
+
merged.push(nextText);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (nextText === previous || previous.includes(nextText)) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (nextText.includes(previous)) {
|
|
256
|
+
merged[merged.length - 1] = nextText;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
merged.push(nextText);
|
|
260
|
+
}
|
|
261
|
+
return merged.join(" ").trim();
|
|
262
|
+
};
|
|
239
263
|
var buildTurnText = (transcripts, partialText) => {
|
|
240
|
-
const finalText = transcripts
|
|
264
|
+
const finalText = mergeTranscriptTexts(transcripts);
|
|
241
265
|
if (finalText) {
|
|
242
266
|
return finalText;
|
|
243
267
|
}
|
|
244
|
-
return partialText
|
|
268
|
+
return normalizeText(partialText);
|
|
245
269
|
};
|
|
246
270
|
|
|
247
271
|
// src/session.ts
|
|
@@ -338,7 +362,7 @@ var createVoiceSession = (options) => {
|
|
|
338
362
|
const handlePartial = async (transcript) => {
|
|
339
363
|
await writeSession((session) => {
|
|
340
364
|
session.currentTurn.lastAudioAt = Date.now();
|
|
341
|
-
session.currentTurn.partialText = transcript.text;
|
|
365
|
+
session.currentTurn.partialText = buildTurnText(session.currentTurn.transcripts, transcript.text);
|
|
342
366
|
session.lastActivityAt = Date.now();
|
|
343
367
|
session.status = "active";
|
|
344
368
|
});
|
package/dist/react/index.js
CHANGED
package/dist/svelte/index.js
CHANGED
package/dist/vue/index.js
CHANGED