@vapi-ai/web 1.0.239 → 1.0.241

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,22 +175,21 @@ 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
- const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
179
- if (!isSpeaking && !hasStoppedSpeaking)
180
- return;
181
- if (this.speakingTimeout) {
182
- clearTimeout(this.speakingTimeout);
183
- this.speakingTimeout = null;
184
- }
185
- else {
180
+ console.log(this.averageSpeechLevel, this.speechLevel);
181
+ const hasStartedSpeaking = this.speechLevel > this.averageSpeechLevel * 1.5;
182
+ const hasStoppedSpeaking = this.speechLevel < this.averageSpeechLevel * 0.5;
183
+ if (!this.isSpeaking && hasStartedSpeaking) {
184
+ this.isSpeaking = true;
186
185
  this.emit("speech-start");
186
+ return;
187
187
  }
188
- this.speakingTimeout = setTimeout(() => {
188
+ if (this.isSpeaking && hasStoppedSpeaking) {
189
+ this.isSpeaking = false;
189
190
  this.emit("speech-end");
190
- this.speakingTimeout = null;
191
- }, 1000);
191
+ return;
192
+ }
192
193
  }
193
194
  stop() {
194
195
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.239",
3
+ "version": "1.0.241",
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,25 +215,26 @@ 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
- const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
222
+ console.log(this.averageSpeechLevel, this.speechLevel);
221
223
 
222
- if (!isSpeaking && !hasStoppedSpeaking) return;
224
+ const hasStartedSpeaking = this.speechLevel > this.averageSpeechLevel * 1.5;
225
+ const hasStoppedSpeaking = this.speechLevel < this.averageSpeechLevel * 0.5;
223
226
 
224
- if (this.speakingTimeout) {
225
- clearTimeout(this.speakingTimeout);
226
- this.speakingTimeout = null;
227
- } else {
227
+ if (!this.isSpeaking && hasStartedSpeaking) {
228
+ this.isSpeaking = true;
228
229
  this.emit("speech-start");
230
+ return;
229
231
  }
230
232
 
231
- this.speakingTimeout = setTimeout(() => {
233
+ if (this.isSpeaking && hasStoppedSpeaking) {
234
+ this.isSpeaking = false;
232
235
  this.emit("speech-end");
233
- this.speakingTimeout = null;
234
- }, 1000);
236
+ return;
237
+ }
235
238
  }
236
239
 
237
240
  stop(): void {