@vapi-ai/web 1.0.17 → 1.0.19
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 -4
- package/dist/vapi.d.ts +0 -1
- package/dist/vapi.js +0 -1
- package/package.json +1 -1
- package/player.ts +6 -3
- package/vapi.ts +0 -1
package/dist/player.js
CHANGED
|
@@ -15,27 +15,29 @@ class ContinuousPlayer extends events_1.default {
|
|
|
15
15
|
this.mediaSource.addEventListener("sourceopen", () => {
|
|
16
16
|
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
|
|
17
17
|
this.audio = document.createElement("audio");
|
|
18
|
+
document.body.appendChild(this.audio);
|
|
18
19
|
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
19
20
|
this.sourceBuffer.addEventListener("updateend", () => {
|
|
20
21
|
this.appendNextChunk();
|
|
21
22
|
});
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
start() {
|
|
25
|
-
var _a;
|
|
26
|
-
(_a = this.audio) === null || _a === void 0 ? void 0 : _a.play();
|
|
27
|
-
}
|
|
25
|
+
start() { }
|
|
28
26
|
playChunk(audioData) {
|
|
29
27
|
this.audioQueue.push(audioData);
|
|
30
28
|
this.appendNextChunk();
|
|
31
29
|
}
|
|
32
30
|
appendNextChunk() {
|
|
31
|
+
var _a;
|
|
32
|
+
console.log("appending");
|
|
33
33
|
if (this.sourceBuffer &&
|
|
34
34
|
!this.sourceBuffer.updating &&
|
|
35
35
|
this.audioQueue.length > 0) {
|
|
36
|
+
console.log("appended");
|
|
36
37
|
const chunk = this.audioQueue.shift();
|
|
37
38
|
if (chunk) {
|
|
38
39
|
this.sourceBuffer.appendBuffer(chunk);
|
|
40
|
+
(_a = this.audio) === null || _a === void 0 ? void 0 : _a.play();
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
}
|
package/dist/vapi.d.ts
CHANGED
package/dist/vapi.js
CHANGED
|
@@ -13,7 +13,6 @@ class Vapi extends events_1.default {
|
|
|
13
13
|
this.started = false;
|
|
14
14
|
this.ws = null;
|
|
15
15
|
this.mediaRecorder = null;
|
|
16
|
-
this.audioQueue = [];
|
|
17
16
|
client_1.client.setSecurityData(apiToken);
|
|
18
17
|
this.player = new player_1.ContinuousPlayer();
|
|
19
18
|
this.player.on("speech-start", () => this.emit("speech-start"));
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -15,6 +15,8 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
15
15
|
'audio/webm; codecs="opus"'
|
|
16
16
|
);
|
|
17
17
|
this.audio = document.createElement("audio");
|
|
18
|
+
document.body.appendChild(this.audio);
|
|
19
|
+
|
|
18
20
|
this.audio.src = URL.createObjectURL(this.mediaSource);
|
|
19
21
|
this.sourceBuffer.addEventListener("updateend", () => {
|
|
20
22
|
this.appendNextChunk();
|
|
@@ -22,9 +24,7 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
start() {
|
|
26
|
-
this.audio?.play();
|
|
27
|
-
}
|
|
27
|
+
start() {}
|
|
28
28
|
|
|
29
29
|
playChunk(audioData: ArrayBuffer) {
|
|
30
30
|
this.audioQueue.push(audioData);
|
|
@@ -33,14 +33,17 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
private appendNextChunk(): void {
|
|
36
|
+
console.log("appending");
|
|
36
37
|
if (
|
|
37
38
|
this.sourceBuffer &&
|
|
38
39
|
!this.sourceBuffer.updating &&
|
|
39
40
|
this.audioQueue.length > 0
|
|
40
41
|
) {
|
|
42
|
+
console.log("appended");
|
|
41
43
|
const chunk = this.audioQueue.shift();
|
|
42
44
|
if (chunk) {
|
|
43
45
|
this.sourceBuffer.appendBuffer(chunk);
|
|
46
|
+
this.audio?.play();
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
}
|
package/vapi.ts
CHANGED
|
@@ -10,7 +10,6 @@ export default class Vapi extends EventEmitter {
|
|
|
10
10
|
private ws: WebSocket | null = null;
|
|
11
11
|
private mediaRecorder: MediaRecorder | null = null;
|
|
12
12
|
private player: ContinuousPlayer;
|
|
13
|
-
private audioQueue: ArrayBuffer[] = [];
|
|
14
13
|
|
|
15
14
|
constructor(apiToken: string) {
|
|
16
15
|
super();
|