@layercode/js-sdk 2.8.9 → 2.8.10
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.
|
@@ -6876,6 +6876,23 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6876
6876
|
* Disconnect VAD
|
|
6877
6877
|
*/
|
|
6878
6878
|
stopVad() {
|
|
6879
|
+
// If user was speaking when VAD is destroyed, send synthetic vad_end to server
|
|
6880
|
+
// This ensures the server receives vad_end even when VAD is destroyed mid-speech
|
|
6881
|
+
// (e.g., due to mute, device change, or disconnect)
|
|
6882
|
+
// Only send if VAD is actually running (not for push-to-talk which uses trigger.turn events)
|
|
6883
|
+
if (this.userIsSpeaking && this.vad) {
|
|
6884
|
+
console.debug('[Layercode]: sending synthetic vad_end (VAD destroyed mid-speech)');
|
|
6885
|
+
this._setUserSpeaking(false); // Update state before callbacks (consistent with onSpeechEnd)
|
|
6886
|
+
const vadEndMessage = {
|
|
6887
|
+
type: 'vad_events',
|
|
6888
|
+
event: 'vad_end',
|
|
6889
|
+
};
|
|
6890
|
+
this._wsSend(vadEndMessage);
|
|
6891
|
+
this.options.onMessage({
|
|
6892
|
+
...vadEndMessage,
|
|
6893
|
+
userSpeaking: this.userIsSpeaking,
|
|
6894
|
+
});
|
|
6895
|
+
}
|
|
6879
6896
|
if (this.vad) {
|
|
6880
6897
|
this.vad.pause();
|
|
6881
6898
|
this.vad.destroy();
|