@layercode/js-sdk 1.0.17 → 1.0.19
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.
|
@@ -3507,6 +3507,9 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3507
3507
|
this.pushToTalkEnabled = false;
|
|
3508
3508
|
this.canInterrupt = false;
|
|
3509
3509
|
this.userIsSpeaking = false;
|
|
3510
|
+
this.endUserTurn = false;
|
|
3511
|
+
this.recorderStarted = false;
|
|
3512
|
+
this.readySent = false;
|
|
3510
3513
|
// Bind event handlers
|
|
3511
3514
|
this._handleWebSocketMessage = this._handleWebSocketMessage.bind(this);
|
|
3512
3515
|
this._handleDataAvailable = this._handleDataAvailable.bind(this);
|
|
@@ -3540,11 +3543,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3540
3543
|
this.userIsSpeaking = false;
|
|
3541
3544
|
},
|
|
3542
3545
|
onSpeechEnd: () => {
|
|
3543
|
-
this.
|
|
3544
|
-
this._wsSend({
|
|
3545
|
-
type: 'vad_events',
|
|
3546
|
-
event: 'vad_end',
|
|
3547
|
-
});
|
|
3546
|
+
this.endUserTurn = true; // Set flag to indicate that the user turn has ended, so we can send a vad_end event to the server
|
|
3548
3547
|
},
|
|
3549
3548
|
})
|
|
3550
3549
|
.then((vad) => {
|
|
@@ -3720,6 +3719,14 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3720
3719
|
type: 'client.audio',
|
|
3721
3720
|
content: base64,
|
|
3722
3721
|
});
|
|
3722
|
+
if (this.endUserTurn) {
|
|
3723
|
+
this.endUserTurn = false;
|
|
3724
|
+
this.userIsSpeaking = false; // Reset userIsSpeaking to false so we don't send any more audio to the server
|
|
3725
|
+
this._wsSend({
|
|
3726
|
+
type: 'vad_events',
|
|
3727
|
+
event: 'vad_end',
|
|
3728
|
+
});
|
|
3729
|
+
}
|
|
3723
3730
|
}
|
|
3724
3731
|
}
|
|
3725
3732
|
catch (error) {
|
|
@@ -3737,6 +3744,13 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3737
3744
|
this.ws.send(messageString);
|
|
3738
3745
|
}
|
|
3739
3746
|
}
|
|
3747
|
+
_sendReadyIfNeeded() {
|
|
3748
|
+
var _a;
|
|
3749
|
+
if (this.recorderStarted && ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN && !this.readySent) {
|
|
3750
|
+
this._wsSend({ type: 'client.ready' });
|
|
3751
|
+
this.readySent = true;
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3740
3754
|
/**
|
|
3741
3755
|
* Sets up amplitude monitoring for a given audio source.
|
|
3742
3756
|
* @param {WavRecorder | WavStreamPlayer} source - The audio source (recorder or player).
|
|
@@ -3812,6 +3826,8 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3812
3826
|
console.log('WebSocket connection established');
|
|
3813
3827
|
this._setStatus('connected');
|
|
3814
3828
|
this.options.onConnect({ sessionId: this.sessionId });
|
|
3829
|
+
// Attempt to send ready message if recorder already started
|
|
3830
|
+
this._sendReadyIfNeeded();
|
|
3815
3831
|
};
|
|
3816
3832
|
this.ws.onclose = () => {
|
|
3817
3833
|
console.log('WebSocket connection closed');
|
|
@@ -3832,6 +3848,9 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3832
3848
|
await this.wavPlayer.connect();
|
|
3833
3849
|
// Set up audio player amplitude monitoring
|
|
3834
3850
|
this._setupAmplitudeMonitoring(this.wavPlayer, this.options.onAgentAmplitudeChange, (amp) => (this.agentAudioAmplitude = amp));
|
|
3851
|
+
// Mark recorder as started and attempt to notify server
|
|
3852
|
+
this.recorderStarted = true;
|
|
3853
|
+
this._sendReadyIfNeeded();
|
|
3835
3854
|
}
|
|
3836
3855
|
catch (error) {
|
|
3837
3856
|
console.error('Error connecting to Layercode pipeline:', error);
|