@vapi-ai/web 1.0.237 → 1.0.239

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
@@ -22,6 +22,7 @@ export default class Vapi extends VapiEventEmitter {
22
22
  private started;
23
23
  private call;
24
24
  private speakingTimeout;
25
+ private averageSpeechLevel;
25
26
  constructor(apiToken: string, apiBaseUrl?: string);
26
27
  private cleanup;
27
28
  start(assistant: CreateAssistantDTO | string): Promise<Call | null>;
package/dist/vapi.js CHANGED
@@ -75,6 +75,7 @@ class Vapi extends VapiEventEmitter {
75
75
  this.started = false;
76
76
  this.call = null;
77
77
  this.speakingTimeout = null;
78
+ this.averageSpeechLevel = 0;
78
79
  client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
79
80
  client_1.client.setSecurityData(apiToken);
80
81
  }
@@ -170,9 +171,12 @@ class Vapi extends VapiEventEmitter {
170
171
  }
171
172
  handleRemoteParticipantsAudioLevel(e) {
172
173
  const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
174
+ this.averageSpeechLevel =
175
+ this.averageSpeechLevel * 0.95 + speechLevel * 0.05;
173
176
  this.emit("volume-level", Math.min(1, speechLevel / 0.15));
174
- const isSpeaking = speechLevel > 0.1;
175
- if (!isSpeaking)
177
+ const isSpeaking = speechLevel > this.averageSpeechLevel * 1.5;
178
+ const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
179
+ if (!isSpeaking && !hasStoppedSpeaking)
176
180
  return;
177
181
  if (this.speakingTimeout) {
178
182
  clearTimeout(this.speakingTimeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.237",
3
+ "version": "1.0.239",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -99,6 +99,7 @@ export default class Vapi extends VapiEventEmitter {
99
99
  private started: boolean = false;
100
100
  private call: DailyCall | null = null;
101
101
  private speakingTimeout: NodeJS.Timeout | null = null;
102
+ private averageSpeechLevel: number = 0;
102
103
 
103
104
  constructor(apiToken: string, apiBaseUrl?: string) {
104
105
  super();
@@ -210,10 +211,15 @@ export default class Vapi extends VapiEventEmitter {
210
211
  (a, b) => a + b,
211
212
  0
212
213
  );
214
+ this.averageSpeechLevel =
215
+ this.averageSpeechLevel * 0.95 + speechLevel * 0.05;
216
+
213
217
  this.emit("volume-level", Math.min(1, speechLevel / 0.15));
214
218
 
215
- const isSpeaking = speechLevel > 0.1;
216
- if (!isSpeaking) return;
219
+ const isSpeaking = speechLevel > this.averageSpeechLevel * 1.5;
220
+ const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
221
+
222
+ if (!isSpeaking && !hasStoppedSpeaking) return;
217
223
 
218
224
  if (this.speakingTimeout) {
219
225
  clearTimeout(this.speakingTimeout);