Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ yarn-error.log*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Thumbs.db

.npm-cache
55 changes: 32 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,35 @@ class LayercodeClient implements ILayercodeClient {
this.options.onDevicesChanged = callback ?? NOOP;
}

private _startSpeech(): void {
console.debug('onSpeechStart: sending vad_start');
this._setUserSpeaking(true);
const vadStartMessage: ClientVadEventsMessage = {
type: 'vad_events',
event: 'vad_start',
};
this._wsSend(vadStartMessage);
this.options.onMessage({
...vadStartMessage,
userSpeaking: this.userIsSpeaking,
});
}

private _endSpeech(): void {
console.debug('onSpeechEnd: sending vad_end');
this._setUserSpeaking(false);
this.audioBuffer = []; // Clear buffer on speech end
const vadEndMessage: ClientVadEventsMessage = {
type: 'vad_events',
event: 'vad_end',
};
this._wsSend(vadEndMessage);
this.options.onMessage({
...vadEndMessage,
userSpeaking: this.userIsSpeaking,
});
}

private _initializeVAD(): void {
console.log('initializing VAD', { pushToTalkEnabled: this.pushToTalkEnabled, canInterrupt: this.canInterrupt, vadConfig: this.vadConfig });

Expand Down Expand Up @@ -509,31 +538,10 @@ class LayercodeClient implements ILayercodeClient {
onnxWASMBasePath: 'https://assets.layercode.com/onnxruntime-web/1.23.2/',
baseAssetPath: 'https://assets.layercode.com/vad-web/0.0.29/',
onSpeechStart: () => {
console.debug('onSpeechStart: sending vad_start');
this._setUserSpeaking(true);
const vadStartMessage: ClientVadEventsMessage = {
type: 'vad_events',
event: 'vad_start',
};
this._wsSend(vadStartMessage);
this.options.onMessage({
...vadStartMessage,
userSpeaking: this.userIsSpeaking,
});
this._startSpeech();
},
onSpeechEnd: () => {
console.debug('onSpeechEnd: sending vad_end');
this._setUserSpeaking(false);
this.audioBuffer = []; // Clear buffer on speech end
const vadEndMessage: ClientVadEventsMessage = {
type: 'vad_events',
event: 'vad_end',
};
this._wsSend(vadEndMessage);
this.options.onMessage({
...vadEndMessage,
userSpeaking: this.userIsSpeaking,
});
this._endSpeech();
},
};

Expand Down Expand Up @@ -1471,6 +1479,7 @@ class LayercodeClient implements ILayercodeClient {
this.options.onMuteStateChange(true);
this.stopVad();
this._stopRecorderAmplitudeMonitoring();
// this._endSpeech();
}
}

Expand Down
Loading