@vapi-ai/web 1.0.94 → 1.0.96
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/player.d.ts +2 -0
- package/dist/player.js +9 -4
- package/package.json +1 -1
- package/player.ts +13 -4
package/dist/player.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import async from "async";
|
|
2
3
|
import EventEmitter from "events";
|
|
3
4
|
export declare class ContinuousPlayer extends EventEmitter {
|
|
4
5
|
private mediaSource;
|
|
@@ -6,6 +7,7 @@ export declare class ContinuousPlayer extends EventEmitter {
|
|
|
6
7
|
private audio;
|
|
7
8
|
private operationsQueue;
|
|
8
9
|
constructor();
|
|
10
|
+
createOperationQueue(): async.QueueObject<() => Promise<void>>;
|
|
9
11
|
start(): void;
|
|
10
12
|
playChunk(audioData: ArrayBuffer): void;
|
|
11
13
|
private performBufferOperation;
|
package/dist/player.js
CHANGED
|
@@ -26,15 +26,18 @@ class ContinuousPlayer extends events_1.default {
|
|
|
26
26
|
this.audio.addEventListener("waiting", () => this.emit("speech-end"));
|
|
27
27
|
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
28
28
|
document.body.appendChild(this.audio);
|
|
29
|
-
this.operationsQueue =
|
|
30
|
-
task().then(() => callback());
|
|
31
|
-
}, 1);
|
|
29
|
+
this.operationsQueue = this.createOperationQueue();
|
|
32
30
|
this.mediaSource.addEventListener("sourceopen", () => {
|
|
33
31
|
this.mediaSource.duration = Number.POSITIVE_INFINITY;
|
|
34
32
|
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
|
|
35
33
|
this.sourceBuffer.mode = "sequence";
|
|
36
34
|
});
|
|
37
35
|
}
|
|
36
|
+
createOperationQueue() {
|
|
37
|
+
return async_1.default.queue((task, callback) => {
|
|
38
|
+
task().then(() => callback());
|
|
39
|
+
}, 1);
|
|
40
|
+
}
|
|
38
41
|
start() {
|
|
39
42
|
this.audio.play();
|
|
40
43
|
}
|
|
@@ -72,7 +75,7 @@ class ContinuousPlayer extends events_1.default {
|
|
|
72
75
|
if (!this.sourceBuffer)
|
|
73
76
|
return;
|
|
74
77
|
if (this.sourceBuffer.buffered.length > 0) {
|
|
75
|
-
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(
|
|
78
|
+
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length - 1));
|
|
76
79
|
}
|
|
77
80
|
});
|
|
78
81
|
}
|
|
@@ -92,6 +95,8 @@ class ContinuousPlayer extends events_1.default {
|
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
clear() {
|
|
98
|
+
this.operationsQueue.kill();
|
|
99
|
+
this.operationsQueue = this.createOperationQueue();
|
|
95
100
|
this.operationsQueue.push(() => this.abortBuffer());
|
|
96
101
|
this.operationsQueue.push(() => this.removeBuffer());
|
|
97
102
|
this.operationsQueue.push(() => this.resetTimestampOffset());
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -22,9 +22,7 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
22
22
|
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
23
23
|
document.body.appendChild(this.audio);
|
|
24
24
|
|
|
25
|
-
this.operationsQueue =
|
|
26
|
-
task().then(() => callback());
|
|
27
|
-
}, 1);
|
|
25
|
+
this.operationsQueue = this.createOperationQueue();
|
|
28
26
|
|
|
29
27
|
this.mediaSource.addEventListener("sourceopen", () => {
|
|
30
28
|
this.mediaSource.duration = Number.POSITIVE_INFINITY;
|
|
@@ -35,6 +33,12 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
35
33
|
});
|
|
36
34
|
}
|
|
37
35
|
|
|
36
|
+
createOperationQueue() {
|
|
37
|
+
return async.queue<() => Promise<void>>((task, callback) => {
|
|
38
|
+
task().then(() => callback());
|
|
39
|
+
}, 1);
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
start() {
|
|
39
43
|
this.audio.play();
|
|
40
44
|
}
|
|
@@ -81,7 +85,10 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
81
85
|
if (!this.sourceBuffer) return;
|
|
82
86
|
|
|
83
87
|
if (this.sourceBuffer.buffered.length > 0) {
|
|
84
|
-
this.sourceBuffer.remove(
|
|
88
|
+
this.sourceBuffer.remove(
|
|
89
|
+
0,
|
|
90
|
+
this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length - 1)
|
|
91
|
+
);
|
|
85
92
|
}
|
|
86
93
|
});
|
|
87
94
|
}
|
|
@@ -100,6 +107,8 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
clear() {
|
|
110
|
+
this.operationsQueue.kill();
|
|
111
|
+
this.operationsQueue = this.createOperationQueue();
|
|
103
112
|
this.operationsQueue.push(() => this.abortBuffer());
|
|
104
113
|
this.operationsQueue.push(() => this.removeBuffer());
|
|
105
114
|
this.operationsQueue.push(() => this.resetTimestampOffset());
|