@convai/web-sdk 2.1.0-beta.1 → 2.1.0-beta.3
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,10 +53,23 @@ export declare class BlendshapeQueue {
|
|
|
53
53
|
private playbackFps;
|
|
54
54
|
private ownerReplacementStoppedSpeaking;
|
|
55
55
|
private missingExpectedFramesSinceMs;
|
|
56
|
+
/** When the indexed timeline first showed a hole in front of waiting frames, ms. */
|
|
57
|
+
private timelineGapSinceMs;
|
|
56
58
|
private readonly now;
|
|
57
59
|
private static readonly TARGET_FPS;
|
|
58
60
|
private static readonly MAX_RETIRED_TIMELINE_ALIASES;
|
|
59
61
|
private static readonly MISSING_INDEXED_FRAME_GRACE_MS;
|
|
62
|
+
/**
|
|
63
|
+
* How long an indexed timeline waits for a missing chunk before playing on
|
|
64
|
+
* from the frames beyond it. A chunk can be lost between the server and
|
|
65
|
+
* the queue (dropped by the transport, or wiped by a local interrupt that
|
|
66
|
+
* raced the turn's first chunks); the frames after it kept arriving but
|
|
67
|
+
* nothing could flush past the hole, and the mouth stayed shut for the rest
|
|
68
|
+
* of a 25 s reply (measured 2026-11-12: 1480 frames waiting behind a
|
|
69
|
+
* six-frame hole). A quarter second is longer than any inter-chunk gap
|
|
70
|
+
* seen in production, so a late chunk still fills its hole in time.
|
|
71
|
+
*/
|
|
72
|
+
private static readonly INDEXED_GAP_SKIP_MS;
|
|
60
73
|
/**
|
|
61
74
|
* Create a new BlendshapeQueue
|
|
62
75
|
* @param mapper - Optional function to map/transform blendshape data as it's added
|
|
@@ -71,6 +84,14 @@ export declare class BlendshapeQueue {
|
|
|
71
84
|
private mapFrame;
|
|
72
85
|
private addTimelineChunk;
|
|
73
86
|
private flushContiguousTimelineFrames;
|
|
87
|
+
/**
|
|
88
|
+
* Play on past a hole in the indexed timeline once it has waited
|
|
89
|
+
* INDEXED_GAP_SKIP_MS: the missing frames count as consumed, so the
|
|
90
|
+
* server's frame accounting (turn stats, end fades) stays on its timeline,
|
|
91
|
+
* and the waiting frames flush. Called from every flush and from the
|
|
92
|
+
* player's reads, since a hole with nothing arriving gets no flush.
|
|
93
|
+
*/
|
|
94
|
+
private recoverTimelineGap;
|
|
74
95
|
private timelineAliases;
|
|
75
96
|
private hasActiveTimelineOwner;
|
|
76
97
|
private responseAlias;
|
|
@@ -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 indexed timeline first showed a hole in front of waiting frames, ms. */
|
|
66
|
+
this.timelineGapSinceMs = null;
|
|
65
67
|
this.mapper = mapper;
|
|
66
68
|
this.now = now;
|
|
67
69
|
}
|
|
@@ -159,6 +161,41 @@ export class BlendshapeQueue {
|
|
|
159
161
|
this.queue.push(frame);
|
|
160
162
|
nextFrameIndex += 1;
|
|
161
163
|
}
|
|
164
|
+
this.recoverTimelineGap();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Play on past a hole in the indexed timeline once it has waited
|
|
168
|
+
* INDEXED_GAP_SKIP_MS: the missing frames count as consumed, so the
|
|
169
|
+
* server's frame accounting (turn stats, end fades) stays on its timeline,
|
|
170
|
+
* and the waiting frames flush. Called from every flush and from the
|
|
171
|
+
* player's reads, since a hole with nothing arriving gets no flush.
|
|
172
|
+
*/
|
|
173
|
+
recoverTimelineGap() {
|
|
174
|
+
if (this.queue.length > 0 || this.pendingTimelineFrames.size === 0) {
|
|
175
|
+
this.timelineGapSinceMs = null;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const next = this.framesConsumed;
|
|
179
|
+
let lowest = Infinity;
|
|
180
|
+
for (const index of this.pendingTimelineFrames.keys()) {
|
|
181
|
+
if (index < lowest)
|
|
182
|
+
lowest = index;
|
|
183
|
+
}
|
|
184
|
+
if (lowest <= next) {
|
|
185
|
+
this.timelineGapSinceMs = null;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const t = this.now();
|
|
189
|
+
if (this.timelineGapSinceMs === null) {
|
|
190
|
+
this.timelineGapSinceMs = t;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (t - this.timelineGapSinceMs < BlendshapeQueue.INDEXED_GAP_SKIP_MS) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.framesConsumed = lowest;
|
|
197
|
+
this.timelineGapSinceMs = null;
|
|
198
|
+
this.flushContiguousTimelineFrames();
|
|
162
199
|
}
|
|
163
200
|
timelineAliases(metadata = {}) {
|
|
164
201
|
const aliases = [];
|
|
@@ -401,6 +438,8 @@ export class BlendshapeQueue {
|
|
|
401
438
|
* @returns The frame at the given index, or null if out of bounds
|
|
402
439
|
*/
|
|
403
440
|
getFrame(index) {
|
|
441
|
+
if (this.queue.length === 0)
|
|
442
|
+
this.recoverTimelineGap();
|
|
404
443
|
if (index < 0 || index >= this.queue.length) {
|
|
405
444
|
return null;
|
|
406
445
|
}
|
|
@@ -470,6 +509,8 @@ export class BlendshapeQueue {
|
|
|
470
509
|
* Check if queue has frames
|
|
471
510
|
*/
|
|
472
511
|
hasFrames() {
|
|
512
|
+
if (this.queue.length === 0)
|
|
513
|
+
this.recoverTimelineGap();
|
|
473
514
|
return this.queue.length > 0;
|
|
474
515
|
}
|
|
475
516
|
/**
|
|
@@ -661,6 +702,7 @@ export class BlendshapeQueue {
|
|
|
661
702
|
this.ownerReplacementStoppedSpeaking = false;
|
|
662
703
|
this.pendingTimelineFrames.clear();
|
|
663
704
|
this.missingExpectedFramesSinceMs = null;
|
|
705
|
+
this.timelineGapSinceMs = null;
|
|
664
706
|
// Ahead-delivered turns may have many seconds of future frames buffered.
|
|
665
707
|
// On interrupt, audio stops immediately, so visuals must hard-stop too.
|
|
666
708
|
this.queue = [];
|
|
@@ -785,3 +827,14 @@ export class BlendshapeQueue {
|
|
|
785
827
|
BlendshapeQueue.TARGET_FPS = 60;
|
|
786
828
|
BlendshapeQueue.MAX_RETIRED_TIMELINE_ALIASES = 48;
|
|
787
829
|
BlendshapeQueue.MISSING_INDEXED_FRAME_GRACE_MS = (24 / BlendshapeQueue.TARGET_FPS) * 1000;
|
|
830
|
+
/**
|
|
831
|
+
* How long an indexed timeline waits for a missing chunk before playing on
|
|
832
|
+
* from the frames beyond it. A chunk can be lost between the server and
|
|
833
|
+
* the queue (dropped by the transport, or wiped by a local interrupt that
|
|
834
|
+
* raced the turn's first chunks); the frames after it kept arriving but
|
|
835
|
+
* nothing could flush past the hole, and the mouth stayed shut for the rest
|
|
836
|
+
* of a 25 s reply (measured 2026-11-12: 1480 frames waiting behind a
|
|
837
|
+
* six-frame hole). A quarter second is longer than any inter-chunk gap
|
|
838
|
+
* seen in production, so a late chunk still fills its hole in time.
|
|
839
|
+
*/
|
|
840
|
+
BlendshapeQueue.INDEXED_GAP_SKIP_MS = 250;
|
|
@@ -714,7 +714,17 @@ export class ConvaiClient extends EventEmitter {
|
|
|
714
714
|
// Voice input path — activate the blendshape queue as soon as the user
|
|
715
715
|
// starts speaking (user-started-speaking) so conversationActive is true
|
|
716
716
|
// immediately, matching the text-input path where it's true on send.
|
|
717
|
-
|
|
717
|
+
//
|
|
718
|
+
// Not for a turn this client already started and the bot has not begun:
|
|
719
|
+
// the server sends user-started-speaking for a text turn too (~0.4 s
|
|
720
|
+
// after the send), and resetting the queue then wiped the turn's own
|
|
721
|
+
// ahead-delivered chunks and left the rest stuck behind the hole, so
|
|
722
|
+
// the mouth stayed shut for the reply (2026-11-12, four of eight text
|
|
723
|
+
// replies). The send already reset the queue; the turn is pending.
|
|
724
|
+
const turnPending = this.blendshapeQueue.isConversationActive() &&
|
|
725
|
+
!this.blendshapeQueue.isBotSpeaking() &&
|
|
726
|
+
!this._state.isSpeaking;
|
|
727
|
+
if (!wasListening && isListening && !turnPending) {
|
|
718
728
|
// Reset blendshape queue if mid-conversation, but don't interrupt the server
|
|
719
729
|
if (this.blendshapeQueue.isConversationActive() ||
|
|
720
730
|
this._state.isSpeaking ||
|
|
@@ -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
|
-
|
|
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
|
+
export declare const SDK_VERSION = "2.1.0-beta.3";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@convai/web-sdk",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.3",
|
|
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",
|