@vapi-ai/web 1.0.239 → 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 +2 -0
- package/dist/vapi.js +12 -12
- package/package.json +1 -1
- package/vapi.ts +12 -11
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,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
|
|
178
|
-
const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
|
|
179
|
-
if (!isSpeaking &&
|
|
180
|
-
|
|
181
|
-
if (this.speakingTimeout) {
|
|
182
|
-
clearTimeout(this.speakingTimeout);
|
|
183
|
-
this.speakingTimeout = null;
|
|
184
|
-
}
|
|
185
|
-
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;
|
|
186
184
|
this.emit("speech-start");
|
|
185
|
+
return;
|
|
187
186
|
}
|
|
188
|
-
this.
|
|
187
|
+
if (this.isSpeaking && hasStoppedSpeaking) {
|
|
188
|
+
this.isSpeaking = false;
|
|
189
189
|
this.emit("speech-end");
|
|
190
|
-
|
|
191
|
-
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
192
|
}
|
|
193
193
|
stop() {
|
|
194
194
|
var _a;
|
package/package.json
CHANGED
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,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
|
|
220
|
-
const hasStoppedSpeaking = speechLevel < this.averageSpeechLevel * 0.5;
|
|
222
|
+
const hasStartedSpeaking = this.speechLevel > this.averageSpeechLevel * 1.5;
|
|
223
|
+
const hasStoppedSpeaking = this.speechLevel < this.averageSpeechLevel * 0.5;
|
|
221
224
|
|
|
222
|
-
if (!isSpeaking &&
|
|
223
|
-
|
|
224
|
-
if (this.speakingTimeout) {
|
|
225
|
-
clearTimeout(this.speakingTimeout);
|
|
226
|
-
this.speakingTimeout = null;
|
|
227
|
-
} else {
|
|
225
|
+
if (!this.isSpeaking && hasStartedSpeaking) {
|
|
226
|
+
this.isSpeaking = true;
|
|
228
227
|
this.emit("speech-start");
|
|
228
|
+
return;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
this.
|
|
231
|
+
if (this.isSpeaking && hasStoppedSpeaking) {
|
|
232
|
+
this.isSpeaking = false;
|
|
232
233
|
this.emit("speech-end");
|
|
233
|
-
|
|
234
|
-
}
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
stop(): void {
|