@layercode/js-sdk 2.8.0 → 2.8.1
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.
|
@@ -5945,6 +5945,7 @@ class LayercodeClient {
|
|
|
5945
5945
|
this._emitAudioInput();
|
|
5946
5946
|
this.AMPLITUDE_MONITORING_SAMPLE_RATE = 2;
|
|
5947
5947
|
this._websocketUrl = DEFAULT_WS_URL;
|
|
5948
|
+
this.audioOutputReady = null;
|
|
5948
5949
|
this.wavRecorder = new WavRecorder({ sampleRate: 8000 }); // TODO should be set my fetched agent config
|
|
5949
5950
|
this.wavPlayer = new WavStreamPlayer({
|
|
5950
5951
|
finishedPlayingCallback: this._clientResponseAudioReplayFinished.bind(this),
|
|
@@ -6106,12 +6107,19 @@ class LayercodeClient {
|
|
|
6106
6107
|
this.status = status;
|
|
6107
6108
|
this.options.onStatusChange(status);
|
|
6108
6109
|
}
|
|
6110
|
+
async _waitForAudioOutputReady() {
|
|
6111
|
+
if (!this.audioOutputReady) {
|
|
6112
|
+
return;
|
|
6113
|
+
}
|
|
6114
|
+
await this.audioOutputReady;
|
|
6115
|
+
}
|
|
6109
6116
|
_setAgentSpeaking(isSpeaking) {
|
|
6110
|
-
|
|
6117
|
+
const shouldReportSpeaking = this.audioOutput && isSpeaking;
|
|
6118
|
+
if (this.agentIsSpeaking === shouldReportSpeaking) {
|
|
6111
6119
|
return;
|
|
6112
6120
|
}
|
|
6113
|
-
this.agentIsSpeaking =
|
|
6114
|
-
this.options.onAgentSpeakingChange(
|
|
6121
|
+
this.agentIsSpeaking = shouldReportSpeaking;
|
|
6122
|
+
this.options.onAgentSpeakingChange(shouldReportSpeaking);
|
|
6115
6123
|
}
|
|
6116
6124
|
_setUserSpeaking(isSpeaking) {
|
|
6117
6125
|
const shouldReportSpeaking = this._shouldCaptureUserAudio() && isSpeaking;
|
|
@@ -6179,7 +6187,6 @@ class LayercodeClient {
|
|
|
6179
6187
|
if (message.role === 'assistant') {
|
|
6180
6188
|
// Start tracking new agent turn
|
|
6181
6189
|
console.debug('Agent turn started, will track new turn ID from audio/text');
|
|
6182
|
-
this._setAgentSpeaking(true);
|
|
6183
6190
|
this._setUserSpeaking(false);
|
|
6184
6191
|
}
|
|
6185
6192
|
else if (message.role === 'user' && !this.pushToTalkEnabled) {
|
|
@@ -6201,6 +6208,7 @@ class LayercodeClient {
|
|
|
6201
6208
|
break;
|
|
6202
6209
|
}
|
|
6203
6210
|
case 'response.audio':
|
|
6211
|
+
await this._waitForAudioOutputReady();
|
|
6204
6212
|
this._setAgentSpeaking(true);
|
|
6205
6213
|
const audioBuffer = base64ToArrayBuffer(message.content);
|
|
6206
6214
|
this.wavPlayer.add16BitPCM(audioBuffer, message.turn_id);
|
|
@@ -6427,6 +6435,7 @@ class LayercodeClient {
|
|
|
6427
6435
|
}
|
|
6428
6436
|
else {
|
|
6429
6437
|
this.wavPlayer.mute();
|
|
6438
|
+
this._setAgentSpeaking(false);
|
|
6430
6439
|
}
|
|
6431
6440
|
}
|
|
6432
6441
|
}
|
|
@@ -6485,7 +6494,9 @@ class LayercodeClient {
|
|
|
6485
6494
|
this.setupVadConfig(config);
|
|
6486
6495
|
// Bind the websocket message callbacks
|
|
6487
6496
|
this.bindWebsocketMessageCallbacks(ws, config);
|
|
6488
|
-
|
|
6497
|
+
const audioOutputReady = this.setupAudioOutput();
|
|
6498
|
+
this.audioOutputReady = audioOutputReady;
|
|
6499
|
+
await audioOutputReady;
|
|
6489
6500
|
}
|
|
6490
6501
|
catch (error) {
|
|
6491
6502
|
console.error('Error connecting to Layercode agent:', error);
|