@vapi-ai/web 1.0.238 → 1.0.240

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
@@ -23,6 +23,8 @@ export default class Vapi extends VapiEventEmitter {
23
23
  private call;
24
24
  private speakingTimeout;
25
25
  private averageSpeechLevel;
26
+ private speechLevel;
27
+ private isSpeaking;
26
28
  constructor(apiToken: string, apiBaseUrl?: string);
27
29
  private cleanup;
28
30
  start(assistant: CreateAssistantDTO | string): Promise<Call | null>;
package/dist/vapi.js CHANGED
@@ -76,6 +76,8 @@ class Vapi extends VapiEventEmitter {
76
76
  this.call = null;
77
77
  this.speakingTimeout = null;
78
78
  this.averageSpeechLevel = 0;
79
+ this.speechLevel = 0;
80
+ this.isSpeaking = false;
79
81
  client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
80
82
  client_1.client.setSecurityData(apiToken);
81
83
  }
@@ -173,21 +175,20 @@ class Vapi extends VapiEventEmitter {
173
175
  const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
174
176
  this.averageSpeechLevel =
175
177
  this.averageSpeechLevel * 0.95 + speechLevel * 0.05;
178
+ this.speechLevel = this.speechLevel * 0.8 + speechLevel * 0.1;
176
179
  this.emit("volume-level", Math.min(1, speechLevel / 0.15));
177
- const isSpeaking = speechLevel > this.averageSpeechLevel * 1.5;
178
- if (!isSpeaking)
179
- return;
180
- if (this.speakingTimeout) {
181
- clearTimeout(this.speakingTimeout);
182
- this.speakingTimeout = null;
183
- }
184
- else {
180
+ const hasStartedSpeaking = this.speechLevel > this.averageSpeechLevel * 1.5;
181
+ const hasStoppedSpeaking = this.speechLevel < this.averageSpeechLevel * 0.5;
182
+ if (!this.isSpeaking && hasStartedSpeaking) {
183
+ this.isSpeaking = true;
185
184
  this.emit("speech-start");
185
+ return;
186
186
  }
187
- this.speakingTimeout = setTimeout(() => {
187
+ if (this.isSpeaking && hasStoppedSpeaking) {
188
+ this.isSpeaking = false;
188
189
  this.emit("speech-end");
189
- this.speakingTimeout = null;
190
- }, 1000);
190
+ return;
191
+ }
191
192
  }
192
193
  stop() {
193
194
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.238",
3
+ "version": "1.0.240",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -100,6 +100,8 @@ export default class Vapi extends VapiEventEmitter {
100
100
  private call: DailyCall | null = null;
101
101
  private speakingTimeout: NodeJS.Timeout | null = null;
102
102
  private averageSpeechLevel: number = 0;
103
+ private speechLevel: number = 0;
104
+ private isSpeaking: boolean = false;
103
105
 
104
106
  constructor(apiToken: string, apiBaseUrl?: string) {
105
107
  super();
@@ -213,23 +215,24 @@ export default class Vapi extends VapiEventEmitter {
213
215
  );
214
216
  this.averageSpeechLevel =
215
217
  this.averageSpeechLevel * 0.95 + speechLevel * 0.05;
218
+ this.speechLevel = this.speechLevel * 0.8 + speechLevel * 0.1;
216
219
 
217
220
  this.emit("volume-level", Math.min(1, speechLevel / 0.15));
218
221
 
219
- const isSpeaking = speechLevel > this.averageSpeechLevel * 1.5;
220
- if (!isSpeaking) return;
222
+ const hasStartedSpeaking = this.speechLevel > this.averageSpeechLevel * 1.5;
223
+ const hasStoppedSpeaking = this.speechLevel < this.averageSpeechLevel * 0.5;
221
224
 
222
- if (this.speakingTimeout) {
223
- clearTimeout(this.speakingTimeout);
224
- this.speakingTimeout = null;
225
- } else {
225
+ if (!this.isSpeaking && hasStartedSpeaking) {
226
+ this.isSpeaking = true;
226
227
  this.emit("speech-start");
228
+ return;
227
229
  }
228
230
 
229
- this.speakingTimeout = setTimeout(() => {
231
+ if (this.isSpeaking && hasStoppedSpeaking) {
232
+ this.isSpeaking = false;
230
233
  this.emit("speech-end");
231
- this.speakingTimeout = null;
232
- }, 1000);
234
+ return;
235
+ }
233
236
  }
234
237
 
235
238
  stop(): void {