@vapi-ai/web 1.0.123 → 1.0.124
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/AtomicMediaSource.ts +5 -6
- package/dist/AtomicMediaSource.d.ts +3 -1
- package/dist/AtomicMediaSource.js +4 -4
- package/dist/player.js +2 -1
- package/package.json +1 -1
- package/player.ts +4 -1
package/AtomicMediaSource.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import async, { QueueObject } from "async";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import EventEmitter from "events";
|
|
4
|
+
|
|
5
|
+
class AtomicMediaSource extends EventEmitter {
|
|
4
6
|
mediaSource: MediaSource;
|
|
5
7
|
private sourceBuffer: SourceBuffer | null = null;
|
|
6
8
|
private operationsQueue: QueueObject<() => Promise<void>>;
|
|
7
9
|
|
|
8
10
|
constructor() {
|
|
11
|
+
super();
|
|
9
12
|
this.mediaSource = new MediaSource();
|
|
10
13
|
this.operationsQueue = this.createOperationQueue();
|
|
11
14
|
|
|
@@ -19,17 +22,13 @@ class AtomicMediaSource {
|
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
public appendBuffer(buffer: ArrayBuffer) {
|
|
22
|
-
console.log("APPEND OP PUSHED");
|
|
23
25
|
this.operationsQueue.push(() => {
|
|
24
|
-
console.log("APPEND OP START");
|
|
25
|
-
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
if (this.sourceBuffer) {
|
|
28
28
|
this.sourceBuffer.addEventListener(
|
|
29
29
|
"updateend",
|
|
30
30
|
() => {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
this.emit("audio-loaded");
|
|
33
32
|
resolve();
|
|
34
33
|
},
|
|
35
34
|
{ once: true }
|
|
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const async_1 = __importDefault(require("async"));
|
|
7
|
-
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
class AtomicMediaSource extends events_1.default {
|
|
8
9
|
constructor() {
|
|
10
|
+
super();
|
|
9
11
|
this.sourceBuffer = null;
|
|
10
12
|
this.mediaSource = new MediaSource();
|
|
11
13
|
this.operationsQueue = this.createOperationQueue();
|
|
@@ -16,13 +18,11 @@ class AtomicMediaSource {
|
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
20
|
appendBuffer(buffer) {
|
|
19
|
-
console.log("APPEND OP PUSHED");
|
|
20
21
|
this.operationsQueue.push(() => {
|
|
21
|
-
console.log("APPEND OP START");
|
|
22
22
|
return new Promise((resolve, reject) => {
|
|
23
23
|
if (this.sourceBuffer) {
|
|
24
24
|
this.sourceBuffer.addEventListener("updateend", () => {
|
|
25
|
-
|
|
25
|
+
this.emit("audio-loaded");
|
|
26
26
|
resolve();
|
|
27
27
|
}, { once: true });
|
|
28
28
|
this.sourceBuffer.appendBuffer(buffer);
|
package/dist/player.js
CHANGED
|
@@ -9,11 +9,12 @@ const events_1 = __importDefault(require("events"));
|
|
|
9
9
|
class ContinuousPlayer extends events_1.default {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this.atomic = new AtomicMediaSource_1.default();
|
|
13
12
|
this.audio = document.createElement("audio");
|
|
14
13
|
this.audio.addEventListener("playing", () => this.emit("speech-start"));
|
|
15
14
|
this.audio.addEventListener("play", () => this.emit("speech-start"));
|
|
15
|
+
this.audio.addEventListener("canplay", () => this.audio.play());
|
|
16
16
|
this.audio.addEventListener("waiting", () => this.emit("speech-end"));
|
|
17
|
+
this.atomic = new AtomicMediaSource_1.default();
|
|
17
18
|
this.audio.src = URL.createObjectURL(this.atomic.mediaSource);
|
|
18
19
|
document.body.appendChild(this.audio);
|
|
19
20
|
}
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -7,14 +7,17 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
7
7
|
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
|
-
this.atomic = new AtomicMediaSource();
|
|
11
10
|
|
|
12
11
|
this.audio = document.createElement("audio");
|
|
13
12
|
|
|
14
13
|
this.audio.addEventListener("playing", () => this.emit("speech-start"));
|
|
15
14
|
this.audio.addEventListener("play", () => this.emit("speech-start"));
|
|
15
|
+
this.audio.addEventListener("canplay", () => this.audio.play());
|
|
16
|
+
|
|
16
17
|
this.audio.addEventListener("waiting", () => this.emit("speech-end"));
|
|
17
18
|
|
|
19
|
+
this.atomic = new AtomicMediaSource();
|
|
20
|
+
|
|
18
21
|
this.audio.src = URL.createObjectURL(this.atomic.mediaSource);
|
|
19
22
|
document.body.appendChild(this.audio);
|
|
20
23
|
}
|