@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.
@@ -379,7 +379,7 @@ var createVoiceStreamStore = () => {
379
379
  case "final":
380
380
  state = {
381
381
  ...state,
382
- partial: "",
382
+ partial: action.transcript.text,
383
383
  turns: state.turns.map((turn) => turn)
384
384
  };
385
385
  break;
@@ -375,7 +375,7 @@ var createVoiceStreamStore = () => {
375
375
  case "final":
376
376
  state = {
377
377
  ...state,
378
- partial: "",
378
+ partial: action.transcript.text,
379
379
  turns: state.turns.map((turn) => turn)
380
380
  };
381
381
  break;
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.map((transcript) => transcript.text.trim()).filter(Boolean).join(" ").trim();
264
+ const finalText = mergeTranscriptTexts(transcripts);
241
265
  if (finalText) {
242
266
  return finalText;
243
267
  }
244
- return partialText.trim();
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
  });
@@ -379,7 +379,7 @@ var createVoiceStreamStore = () => {
379
379
  case "final":
380
380
  state = {
381
381
  ...state,
382
- partial: "",
382
+ partial: action.transcript.text,
383
383
  turns: state.turns.map((turn) => turn)
384
384
  };
385
385
  break;
@@ -376,7 +376,7 @@ var createVoiceStreamStore = () => {
376
376
  case "final":
377
377
  state = {
378
378
  ...state,
379
- partial: "",
379
+ partial: action.transcript.text,
380
380
  turns: state.turns.map((turn) => turn)
381
381
  };
382
382
  break;
package/dist/vue/index.js CHANGED
@@ -379,7 +379,7 @@ var createVoiceStreamStore = () => {
379
379
  case "final":
380
380
  state = {
381
381
  ...state,
382
- partial: "",
382
+ partial: action.transcript.text,
383
383
  turns: state.turns.map((turn) => turn)
384
384
  };
385
385
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",