@convai/web-sdk 2.1.0-beta.1 → 2.1.0-beta.2

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.
@@ -53,9 +53,18 @@ export declare class BlendshapeQueue {
53
53
  private playbackFps;
54
54
  private ownerReplacementStoppedSpeaking;
55
55
  private missingExpectedFramesSinceMs;
56
+ /** When the queue ran dry with indexed frames waiting beyond a hole; null otherwise. */
57
+ private holeSinceMs;
56
58
  private readonly now;
57
59
  private static readonly TARGET_FPS;
58
60
  private static readonly MAX_RETIRED_TIMELINE_ALIASES;
61
+ /**
62
+ * How long a dry queue waits for a missing indexed chunk before skipping it, ms. A hole
63
+ * never filled used to hold every later frame in the pending map, freezing the face for
64
+ * the rest of the reply (measured on production, 2026-11-16: 63 frames missing ~6.9 s
65
+ * into a reply, the remaining 18 s without lipsync).
66
+ */
67
+ private static readonly HOLE_GRACE_MS;
59
68
  private static readonly MISSING_INDEXED_FRAME_GRACE_MS;
60
69
  /**
61
70
  * Create a new BlendshapeQueue
@@ -150,6 +159,14 @@ export declare class BlendshapeQueue {
150
159
  * Check if queue has frames
151
160
  */
152
161
  hasFrames(): boolean;
162
+ /**
163
+ * The queue is dry, but indexed frames wait beyond a hole: give the missing chunk
164
+ * HOLE_GRACE_MS to arrive, then count the hole as consumed and play on from the
165
+ * frames beyond it. A consumer that follows `getFramesConsumed()` lands on them at
166
+ * the voice's time for them; a chunk for the hole that arrives later is dropped
167
+ * (its frames are behind `framesConsumed`).
168
+ */
169
+ private skipLateHole;
153
170
  /**
154
171
  * Check if conversation is active
155
172
  */
@@ -62,6 +62,8 @@ export class BlendshapeQueue {
62
62
  this.playbackFps = 60;
63
63
  this.ownerReplacementStoppedSpeaking = false;
64
64
  this.missingExpectedFramesSinceMs = null;
65
+ /** When the queue ran dry with indexed frames waiting beyond a hole; null otherwise. */
66
+ this.holeSinceMs = null;
65
67
  this.mapper = mapper;
66
68
  this.now = now;
67
69
  }
@@ -289,6 +291,7 @@ export class BlendshapeQueue {
289
291
  this.activeTimelineAliases = new Set(ownerAliases);
290
292
  this.queue = [];
291
293
  this.pendingTimelineFrames.clear();
294
+ this.holeSinceMs = null;
292
295
  this.framesConsumed = 0;
293
296
  this.turnStats = null;
294
297
  this.missingExpectedFramesSinceMs = null;
@@ -357,6 +360,7 @@ export class BlendshapeQueue {
357
360
  }
358
361
  this.queue = [];
359
362
  this.pendingTimelineFrames.clear();
363
+ this.holeSinceMs = null;
360
364
  this.framesConsumed = 0;
361
365
  this.missingExpectedFramesSinceMs = null;
362
366
  this.botSpeaking = false;
@@ -470,8 +474,37 @@ export class BlendshapeQueue {
470
474
  * Check if queue has frames
471
475
  */
472
476
  hasFrames() {
477
+ this.skipLateHole();
473
478
  return this.queue.length > 0;
474
479
  }
480
+ /**
481
+ * The queue is dry, but indexed frames wait beyond a hole: give the missing chunk
482
+ * HOLE_GRACE_MS to arrive, then count the hole as consumed and play on from the
483
+ * frames beyond it. A consumer that follows `getFramesConsumed()` lands on them at
484
+ * the voice's time for them; a chunk for the hole that arrives later is dropped
485
+ * (its frames are behind `framesConsumed`).
486
+ */
487
+ skipLateHole() {
488
+ if (this.queue.length > 0 || this.pendingTimelineFrames.size === 0) {
489
+ this.holeSinceMs = null;
490
+ return;
491
+ }
492
+ const t = this.now();
493
+ if (this.holeSinceMs === null) {
494
+ this.holeSinceMs = t;
495
+ return;
496
+ }
497
+ if (t - this.holeSinceMs < BlendshapeQueue.HOLE_GRACE_MS)
498
+ return;
499
+ let next = Infinity;
500
+ for (const k of this.pendingTimelineFrames.keys())
501
+ if (k < next)
502
+ next = k;
503
+ if (next > this.framesConsumed)
504
+ this.framesConsumed = next;
505
+ this.holeSinceMs = null;
506
+ this.flushContiguousTimelineFrames();
507
+ }
475
508
  /**
476
509
  * Check if conversation is active
477
510
  */
@@ -554,6 +587,7 @@ export class BlendshapeQueue {
554
587
  // Clear any leftover frames from previous conversation
555
588
  this.queue = [];
556
589
  this.pendingTimelineFrames.clear();
590
+ this.holeSinceMs = null;
557
591
  this.rememberRetiredTimelineAliases(this.activeTimelineAliases);
558
592
  this.clearTimelineOwner();
559
593
  this.conversationActive = true;
@@ -660,6 +694,7 @@ export class BlendshapeQueue {
660
694
  this.needsNormalization = true; // Signal lipsync player to lerp morphs back to 0
661
695
  this.ownerReplacementStoppedSpeaking = false;
662
696
  this.pendingTimelineFrames.clear();
697
+ this.holeSinceMs = null;
663
698
  this.missingExpectedFramesSinceMs = null;
664
699
  // Ahead-delivered turns may have many seconds of future frames buffered.
665
700
  // On interrupt, audio stops immediately, so visuals must hard-stop too.
@@ -731,6 +766,7 @@ export class BlendshapeQueue {
731
766
  reset() {
732
767
  this.queue = [];
733
768
  this.pendingTimelineFrames.clear();
769
+ this.holeSinceMs = null;
734
770
  this.rememberRetiredTimelineAliases(this.activeTimelineAliases);
735
771
  this.clearTimelineOwner();
736
772
  this.conversationActive = false;
@@ -784,4 +820,11 @@ export class BlendshapeQueue {
784
820
  // Constants
785
821
  BlendshapeQueue.TARGET_FPS = 60;
786
822
  BlendshapeQueue.MAX_RETIRED_TIMELINE_ALIASES = 48;
823
+ /**
824
+ * How long a dry queue waits for a missing indexed chunk before skipping it, ms. A hole
825
+ * never filled used to hold every later frame in the pending map, freezing the face for
826
+ * the rest of the reply (measured on production, 2026-11-16: 63 frames missing ~6.9 s
827
+ * into a reply, the remaining 18 s without lipsync).
828
+ */
829
+ BlendshapeQueue.HOLE_GRACE_MS = 150;
787
830
  BlendshapeQueue.MISSING_INDEXED_FRAME_GRACE_MS = (24 / BlendshapeQueue.TARGET_FPS) * 1000;
@@ -16,6 +16,8 @@
16
16
  import { EventEmitter } from "./EventEmitter.js";
17
17
  import { StreamController } from "./streamController.js";
18
18
  const RTP_RATE = 48000;
19
+ /** Seconds past the worklet's last position report the heard position may be extrapolated. */
20
+ const REPORT_STALE = 0.1;
19
21
  const SILENCE_RMS = 0.008;
20
22
  const SILENCE_WINDOW = 0.03;
21
23
  /** Decode a base64 16-bit little-endian PCM chunk to mono Float32. */
@@ -214,7 +216,12 @@ export class DataAudioPlayer extends EventEmitter {
214
216
  }
215
217
  heardIndex() {
216
218
  const sink = this.sink;
217
- const est = this.playing ? this.read + (this.now() - this.readAt) * sink.sampleRate : this.read;
219
+ // Between the worklet's reports (every ~21 ms) the position is extrapolated, but never
220
+ // further than REPORT_STALE past the last one: a worklet that has stopped reporting is not
221
+ // playing. A suspended AudioContext (no user gesture yet) runs no worklet at all, and counting
222
+ // wall time as heard there "played" a reply nobody heard and ran the lipsync clock ahead.
223
+ const since = Math.min(Math.max(0, this.now() - this.readAt), REPORT_STALE);
224
+ const est = this.playing ? this.read + since * sink.sampleRate : this.read;
218
225
  return Math.min(est, this.written) - (this.playing ? sink.outputLatency() * sink.sampleRate : 0);
219
226
  }
220
227
  replyPlayed() {
@@ -241,9 +248,9 @@ export class DataAudioPlayer extends EventEmitter {
241
248
  const silenceAhead = () => this.lastSilence(searchFrom(), syncedEnd() - Math.round(0.02 * sink.sampleRate)) != null;
242
249
  const cmd = this.controller.tick(t, this.replyPlayed(), silenceAhead);
243
250
  if (cmd === "play") {
251
+ // The worklet's next report says whether it is really playing; asserting it here made a
252
+ // suspended context look like playback.
244
253
  sink.play();
245
- this.playing = true;
246
- this.readAt = t;
247
254
  if (this.controller.snapshot.pauses > 0)
248
255
  this.emit("resumed", {});
249
256
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.1.0-beta.1";
1
+ export declare const SDK_VERSION = "2.1.0-beta.2";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // GENERATED by scripts/sync-version.mjs — do not edit by hand.
2
2
  // Regenerated from package.json on every build.
3
- export const SDK_VERSION = "2.1.0-beta.1";
3
+ export const SDK_VERSION = "2.1.0-beta.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convai/web-sdk",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.2",
4
4
  "description": "Build web apps with lifelike AI characters. The Convai Web SDK gives you real-time voice, lipsync, emotions, and dynamic context — with first-class support for React and vanilla TypeScript.",
5
5
  "private": false,
6
6
  "type": "module",