Skip to content

Commit a4a20bb

Browse files
committed
fix: add debug logs for the play audio
1 parent 5d80332 commit a4a20bb

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

custom/composables/agentAudio/utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function unlockAudio() {
2525
if (isAudioUnlocked) {
2626
return;
2727
}
28-
28+
console.log('Unlocking audio context by playing silent audio');
2929
await ctx.resume();
3030

3131
const buffer = ctx.createBuffer(1, 1, 22050);
@@ -35,13 +35,15 @@ export async function unlockAudio() {
3535
source.connect(ctx.destination);
3636
source.start(0);
3737
isAudioUnlocked = true;
38+
console.log('Audio context unlocked');
3839
}
3940

4041
export async function startStandByAudio() {
42+
console.log('Starting standby audio');
4143
const response = await fetch(
4244
loadFile('plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3')
4345
);
44-
46+
console.log('Standby audio file loaded:, response:', response);
4547
const arrayBuffer = await response.arrayBuffer();
4648
const audioBuffer = await ctx.decodeAudioData(arrayBuffer);
4749

@@ -50,7 +52,7 @@ export async function startStandByAudio() {
5052

5153
source.buffer = audioBuffer;
5254
source.connect(ctx.destination);
53-
55+
console.log('Playing standby audio');
5456
source.start();
5557
}
5658

@@ -81,6 +83,7 @@ export function playChatResponseCurrentChunks({
8183
playback: ChatResponseAudioPlayback;
8284
chunks: ArrayBuffer[];
8385
}) {
86+
console.log('Playing chat response audio chunks:', chunks.length);
8487
void ctx.resume().catch(() => undefined);
8588

8689
for (const chunk of chunks) {
@@ -133,7 +136,7 @@ export function finishChatResponseAudio(playback: ChatResponseAudioPlayback | nu
133136
if (!playback || playback.isStopped) {
134137
return;
135138
}
136-
139+
console.log('Finishing chat response audio playback');
137140
playback.isDone = true;
138141

139142
if (playback.pendingSourceCount === 0) {
@@ -145,7 +148,7 @@ export function stopChatResponseAudio(playback: ChatResponseAudioPlayback | null
145148
if (!playback || playback.isStopped) {
146149
return;
147150
}
148-
151+
console.log('Stopping chat response audio playback');
149152
playback.isStopped = true;
150153

151154
for (const source of playback.activeSources) {
@@ -207,6 +210,7 @@ function concatUint8Arrays(left: Uint8Array, right: Uint8Array) {
207210

208211
export function endStandByAudio() {
209212
if (standbySource) {
213+
console.log('Ending standby audio');
210214
standbySource.stop();
211215
standbySource = null;
212216
}

custom/composables/useAgentAudio.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const useAgentAudio = defineStore('agentAudio', () => {
5757
const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}/adminapi/v1/agent/speech-response`;
5858
try {
5959
agentAudioMode.value = 'transcribing';
60+
console.log('Sending audio to server for transcription and response generation');
6061
const res = await fetch(fullPath, {
6162
method: 'POST',
6263
body: formData,
@@ -137,12 +138,12 @@ export const useAgentAudio = defineStore('agentAudio', () => {
137138
.filter((line) => line.startsWith('data:'))
138139
.map((line) => line.slice(5).trimStart())
139140
.join('\n');
140-
141141
if (!data || data === '[DONE]') {
142142
return;
143143
}
144144

145145
const event = JSON.parse(data) as SpeechStreamEvent;
146+
console.log('Received speech stream event type:', event.type);
146147

147148
if (event.type === 'error') {
148149

0 commit comments

Comments
 (0)