@vapi-ai/web 1.0.175 → 1.0.177

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/vapi.d.ts CHANGED
@@ -4,6 +4,7 @@ import EventEmitter from "events";
4
4
  export default class Vapi extends EventEmitter {
5
5
  private started;
6
6
  private call;
7
+ private speakingTimeout;
7
8
  constructor(apiToken: string, apiBaseUrl?: string);
8
9
  start(assistant: CreateAssistantDTO | string): void;
9
10
  private handleRemoteParticipantsAudioLevel;
package/dist/vapi.js CHANGED
@@ -20,6 +20,7 @@ class Vapi extends events_1.default {
20
20
  super();
21
21
  this.started = false;
22
22
  this.call = null;
23
+ this.speakingTimeout = null;
23
24
  client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
24
25
  client_1.client.setSecurityData(apiToken);
25
26
  }
@@ -50,8 +51,18 @@ class Vapi extends events_1.default {
50
51
  });
51
52
  }
52
53
  handleRemoteParticipantsAudioLevel(e) {
53
- const volume = Object.values(e.participantsAudioLevel).reduce((acc, curr) => acc + curr, 0);
54
- this.emit("speech-volume", volume);
54
+ const isSpeaking = Object.values(e.participantsAudioLevel).some((v) => v > 0.01);
55
+ if (!isSpeaking)
56
+ return;
57
+ if (this.speakingTimeout) {
58
+ clearTimeout(this.speakingTimeout);
59
+ }
60
+ else {
61
+ this.emit("speech-start");
62
+ }
63
+ this.speakingTimeout = setTimeout(() => {
64
+ this.emit("speech-end");
65
+ }, 500);
55
66
  }
56
67
  stop() {
57
68
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.175",
3
+ "version": "1.0.177",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -11,6 +11,7 @@ import { client } from "./client";
11
11
  export default class Vapi extends EventEmitter {
12
12
  private started: boolean = false;
13
13
  private call: DailyCall | null = null;
14
+ private speakingTimeout: NodeJS.Timeout | null = null;
14
15
 
15
16
  constructor(apiToken: string, apiBaseUrl?: string) {
16
17
  super();
@@ -53,11 +54,20 @@ export default class Vapi extends EventEmitter {
53
54
  private handleRemoteParticipantsAudioLevel(
54
55
  e: DailyEventObjectRemoteParticipantsAudioLevel
55
56
  ) {
56
- const volume = Object.values(e.participantsAudioLevel).reduce(
57
- (acc, curr) => acc + curr,
58
- 0
57
+ const isSpeaking = Object.values(e.participantsAudioLevel).some(
58
+ (v) => v > 0.01
59
59
  );
60
- this.emit("speech-volume", volume);
60
+ if (!isSpeaking) return;
61
+
62
+ if (this.speakingTimeout) {
63
+ clearTimeout(this.speakingTimeout);
64
+ } else {
65
+ this.emit("speech-start");
66
+ }
67
+
68
+ this.speakingTimeout = setTimeout(() => {
69
+ this.emit("speech-end");
70
+ }, 500);
61
71
  }
62
72
 
63
73
  stop(): void {