@vapi-ai/web 1.0.243 → 1.0.245

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