@vapi-ai/web 1.0.22 → 1.0.24
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.js +6 -7
- package/package.json +1 -1
- package/player.ts +9 -6
package/dist/player.js
CHANGED
|
@@ -9,18 +9,17 @@ class ContinuousPlayer extends events_1.default {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
this.sourceBuffer = null;
|
|
12
|
-
this.audio = null;
|
|
13
12
|
this.audioQueue = [];
|
|
14
13
|
this.mediaSource = new MediaSource();
|
|
15
14
|
this.mediaSource.addEventListener("sourceopen", () => {
|
|
16
15
|
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
|
|
17
|
-
this.audio = document.createElement("audio");
|
|
18
|
-
document.body.appendChild(this.audio);
|
|
19
|
-
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
20
16
|
this.sourceBuffer.addEventListener("updateend", () => {
|
|
21
17
|
this.appendNextChunk();
|
|
22
18
|
});
|
|
23
19
|
});
|
|
20
|
+
this.audio = document.createElement("audio");
|
|
21
|
+
document.body.appendChild(this.audio);
|
|
22
|
+
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
24
23
|
}
|
|
25
24
|
start() { }
|
|
26
25
|
playChunk(audioData) {
|
|
@@ -28,8 +27,8 @@ class ContinuousPlayer extends events_1.default {
|
|
|
28
27
|
this.appendNextChunk();
|
|
29
28
|
}
|
|
30
29
|
appendNextChunk() {
|
|
31
|
-
var _a;
|
|
32
|
-
console.log(
|
|
30
|
+
var _a, _b;
|
|
31
|
+
console.log(this.sourceBuffer, (_a = this.sourceBuffer) === null || _a === void 0 ? void 0 : _a.updating, this.audioQueue.length);
|
|
33
32
|
if (this.sourceBuffer &&
|
|
34
33
|
!this.sourceBuffer.updating &&
|
|
35
34
|
this.audioQueue.length > 0) {
|
|
@@ -38,7 +37,7 @@ class ContinuousPlayer extends events_1.default {
|
|
|
38
37
|
if (chunk) {
|
|
39
38
|
console.log("chunk");
|
|
40
39
|
this.sourceBuffer.appendBuffer(chunk);
|
|
41
|
-
(
|
|
40
|
+
(_b = this.audio) === null || _b === void 0 ? void 0 : _b.play();
|
|
42
41
|
console.log(this.audio);
|
|
43
42
|
}
|
|
44
43
|
}
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -3,7 +3,7 @@ import EventEmitter from "events";
|
|
|
3
3
|
export class ContinuousPlayer extends EventEmitter {
|
|
4
4
|
private mediaSource: MediaSource;
|
|
5
5
|
private sourceBuffer: SourceBuffer | null = null;
|
|
6
|
-
private audio: HTMLAudioElement
|
|
6
|
+
private audio: HTMLAudioElement;
|
|
7
7
|
private audioQueue: ArrayBuffer[] = [];
|
|
8
8
|
|
|
9
9
|
constructor() {
|
|
@@ -14,14 +14,13 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
14
14
|
this.sourceBuffer = this.mediaSource.addSourceBuffer(
|
|
15
15
|
'audio/webm; codecs="opus"'
|
|
16
16
|
);
|
|
17
|
-
this.audio = document.createElement("audio");
|
|
18
|
-
document.body.appendChild(this.audio);
|
|
19
|
-
|
|
20
|
-
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
21
17
|
this.sourceBuffer.addEventListener("updateend", () => {
|
|
22
18
|
this.appendNextChunk();
|
|
23
19
|
});
|
|
24
20
|
});
|
|
21
|
+
this.audio = document.createElement("audio");
|
|
22
|
+
document.body.appendChild(this.audio);
|
|
23
|
+
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
start() {}
|
|
@@ -33,7 +32,11 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
private appendNextChunk(): void {
|
|
36
|
-
console.log(
|
|
35
|
+
console.log(
|
|
36
|
+
this.sourceBuffer,
|
|
37
|
+
this.sourceBuffer?.updating,
|
|
38
|
+
this.audioQueue.length
|
|
39
|
+
);
|
|
37
40
|
if (
|
|
38
41
|
this.sourceBuffer &&
|
|
39
42
|
!this.sourceBuffer.updating &&
|