@estuary-ai/sdk 0.1.29 → 0.1.30
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/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9319,7 +9319,7 @@ var CharacterClient = class {
|
|
|
9319
9319
|
};
|
|
9320
9320
|
|
|
9321
9321
|
// src/audio/audio-player.ts
|
|
9322
|
-
var AudioPlayer = class {
|
|
9322
|
+
var AudioPlayer = class _AudioPlayer {
|
|
9323
9323
|
sampleRate;
|
|
9324
9324
|
onEvent;
|
|
9325
9325
|
audioContext = null;
|
|
@@ -9331,6 +9331,8 @@ var AudioPlayer = class {
|
|
|
9331
9331
|
isPlaying = false;
|
|
9332
9332
|
_isCleared = false;
|
|
9333
9333
|
_interruptedMessageId = null;
|
|
9334
|
+
_drainTimer = null;
|
|
9335
|
+
static DRAIN_DELAY_MS = 300;
|
|
9334
9336
|
constructor(sampleRate, onEvent) {
|
|
9335
9337
|
this.sampleRate = sampleRate;
|
|
9336
9338
|
this.onEvent = onEvent;
|
|
@@ -9353,6 +9355,7 @@ var AudioPlayer = class {
|
|
|
9353
9355
|
this._interruptedMessageId = null;
|
|
9354
9356
|
}
|
|
9355
9357
|
this._isCleared = false;
|
|
9358
|
+
this.cancelDrain();
|
|
9356
9359
|
const ctx = this.getAudioContext();
|
|
9357
9360
|
if (!ctx) return;
|
|
9358
9361
|
const pcm16 = base64ToInt16Array(voice.audio);
|
|
@@ -9366,6 +9369,7 @@ var AudioPlayer = class {
|
|
|
9366
9369
|
}
|
|
9367
9370
|
clear() {
|
|
9368
9371
|
this._isCleared = true;
|
|
9372
|
+
this.cancelDrain();
|
|
9369
9373
|
this.queue.length = 0;
|
|
9370
9374
|
if (this.currentSource) {
|
|
9371
9375
|
try {
|
|
@@ -9391,6 +9395,7 @@ var AudioPlayer = class {
|
|
|
9391
9395
|
this.currentMessageId = null;
|
|
9392
9396
|
}
|
|
9393
9397
|
dispose() {
|
|
9398
|
+
this.cancelDrain();
|
|
9394
9399
|
this.clear();
|
|
9395
9400
|
if (this.audioElement) {
|
|
9396
9401
|
this.audioElement.pause();
|
|
@@ -9408,6 +9413,25 @@ var AudioPlayer = class {
|
|
|
9408
9413
|
this.audioContext = null;
|
|
9409
9414
|
}
|
|
9410
9415
|
}
|
|
9416
|
+
/** Schedule a deferred 'complete' event. Cancelled if new chunks arrive. */
|
|
9417
|
+
scheduleDrain() {
|
|
9418
|
+
if (this._drainTimer !== null) return;
|
|
9419
|
+
this._drainTimer = setTimeout(() => {
|
|
9420
|
+
this._drainTimer = null;
|
|
9421
|
+
if (this._isCleared) return;
|
|
9422
|
+
if (this.queue.length === 0 && this.isPlaying && this.currentMessageId) {
|
|
9423
|
+
this.onEvent({ type: "complete", messageId: this.currentMessageId });
|
|
9424
|
+
this.isPlaying = false;
|
|
9425
|
+
this.currentMessageId = null;
|
|
9426
|
+
}
|
|
9427
|
+
}, _AudioPlayer.DRAIN_DELAY_MS);
|
|
9428
|
+
}
|
|
9429
|
+
cancelDrain() {
|
|
9430
|
+
if (this._drainTimer !== null) {
|
|
9431
|
+
clearTimeout(this._drainTimer);
|
|
9432
|
+
this._drainTimer = null;
|
|
9433
|
+
}
|
|
9434
|
+
}
|
|
9411
9435
|
getAudioContext() {
|
|
9412
9436
|
if (this.audioContext) return this.audioContext;
|
|
9413
9437
|
if (typeof AudioContext === "undefined" && typeof globalThis.webkitAudioContext === "undefined") {
|
|
@@ -9434,10 +9458,8 @@ var AudioPlayer = class {
|
|
|
9434
9458
|
const ctx = this.getAudioContext();
|
|
9435
9459
|
if (!ctx || this.queue.length === 0) {
|
|
9436
9460
|
if (this.isPlaying && this.currentMessageId) {
|
|
9437
|
-
this.
|
|
9461
|
+
this.scheduleDrain();
|
|
9438
9462
|
}
|
|
9439
|
-
this.isPlaying = false;
|
|
9440
|
-
this.currentMessageId = null;
|
|
9441
9463
|
return;
|
|
9442
9464
|
}
|
|
9443
9465
|
const { buffer, messageId } = this.queue.shift();
|