Skip to content

Commit 8525c70

Browse files
committed
vad working
1 parent 5571970 commit 8525c70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ interface ILayercodeClient {
205205
readonly conversationId: string | null;
206206
readonly userSpeaking: boolean;
207207
readonly agentSpeaking: boolean;
208+
readonly enableVAD: boolean;
208209
}
209210

210211
/**
@@ -225,6 +226,8 @@ interface LayercodeClientOptions {
225226
audioInput?: boolean;
226227
/** Whether audio output is enabled. I.e. do we play the sound in the browser client */
227228
audioOutput?: boolean;
229+
/** Whether Voice Activity Detection is enabled (default: true) */
230+
enableVAD?: boolean;
228231
/**
229232
* When true, defers actual audio hardware initialization (AudioContext, mic permissions)
230233
* until setAudioInput(true) or setAudioOutput(true) is called.
@@ -283,6 +286,7 @@ class LayercodeClient implements ILayercodeClient {
283286
private ws: WebSocket | null;
284287
private audioInput: boolean;
285288
private audioOutput: boolean;
289+
readonly enableVAD: boolean;
286290
private AMPLITUDE_MONITORING_SAMPLE_RATE: number;
287291
private audioOutputReady: Promise<void> | null;
288292
private pushToTalkActive: boolean;
@@ -332,6 +336,7 @@ class LayercodeClient implements ILayercodeClient {
332336
audioInput: options.audioInput ?? true,
333337
audioInputChanged: options.audioInputChanged ?? NOOP,
334338
audioOutput: options.audioOutput ?? true,
339+
enableVAD: options.enableVAD ?? true,
335340
audioOutputChanged: options.audioOutputChanged ?? NOOP,
336341
onConnect: options.onConnect ?? NOOP,
337342
onDisconnect: options.onDisconnect ?? NOOP,
@@ -370,6 +375,7 @@ class LayercodeClient implements ILayercodeClient {
370375
this.agentAudioAmplitude = 0;
371376
this.conversationId = this.options.conversationId;
372377
this.pushToTalkActive = false;
378+
this.enableVAD = this.options.enableVAD ?? true;
373379
this.pushToTalkEnabled = false;
374380
this.canInterrupt = false;
375381
this.userIsSpeaking = false;
@@ -420,6 +426,11 @@ class LayercodeClient implements ILayercodeClient {
420426
console.log('initializing VAD', { pushToTalkEnabled: this.pushToTalkEnabled, canInterrupt: this.canInterrupt, vadConfig: this.vadConfig });
421427

422428
// If we're in push to talk mode or mute mode, we don't need to use the VAD model
429+
if (!this.enableVAD) {
430+
console.debug('Skipping VAD init: VAD disabled');
431+
return;
432+
}
433+
423434
if (this.pushToTalkEnabled || !this._shouldCaptureUserAudio()) {
424435
console.debug('Skipping VAD init: audio input disabled or muted');
425436
return;

0 commit comments

Comments
 (0)