@adminforth/agent 1.41.1 → 1.41.3
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.
- package/build.log +2 -2
- package/custom/composables/useAgentAudio.ts +21 -8
- package/custom/speech_recognition_frontend/MicrophoneButon.vue +6 -9
- package/dist/custom/composables/useAgentAudio.ts +21 -8
- package/dist/custom/speech_recognition_frontend/MicrophoneButon.vue +6 -9
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -58,5 +58,5 @@ custom/speech_recognition_frontend/voiceActivityDetection.ts
|
|
|
58
58
|
custom/speech_recognition_frontend/types/
|
|
59
59
|
custom/speech_recognition_frontend/types/voice-activity-detection.d.ts
|
|
60
60
|
|
|
61
|
-
sent 1,660,
|
|
62
|
-
total size is 1,656,
|
|
61
|
+
sent 1,660,390 bytes received 860 bytes 3,322,500.00 bytes/sec
|
|
62
|
+
total size is 1,656,528 speedup is 1.00
|
|
@@ -15,7 +15,7 @@ type StreamingAudioState = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
let standByAudio: HTMLAudioElement | null = null;
|
|
18
|
-
|
|
18
|
+
let isStandByAudioPlaying = false;
|
|
19
19
|
function playStandByAudio() {
|
|
20
20
|
if (!standByAudio) {
|
|
21
21
|
standByAudio = new Audio(`/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`);
|
|
@@ -27,6 +27,7 @@ function playStandByAudio() {
|
|
|
27
27
|
}
|
|
28
28
|
standByAudio.currentTime = 0;
|
|
29
29
|
standByAudio.play()
|
|
30
|
+
isStandByAudioPlaying = true;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function stopStandByAudio() {
|
|
@@ -35,6 +36,7 @@ function stopStandByAudio() {
|
|
|
35
36
|
}
|
|
36
37
|
standByAudio.pause();
|
|
37
38
|
standByAudio.currentTime = 0;
|
|
39
|
+
isStandByAudioPlaying = false;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function restartStandByAudio() {
|
|
@@ -47,7 +49,7 @@ function restartStandByAudio() {
|
|
|
47
49
|
|
|
48
50
|
export const useAgentAudio = defineStore('agentAudio', () => {
|
|
49
51
|
const agentStore = useAgentStore();
|
|
50
|
-
const agentAudioMode = ref<'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' |
|
|
52
|
+
const agentAudioMode = ref<'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' | 'readyToRespond' >('readyToRespond');
|
|
51
53
|
const isStreamingResponse = ref(false);
|
|
52
54
|
|
|
53
55
|
let currentAbortController: AbortController | null = null;
|
|
@@ -57,15 +59,21 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
57
59
|
let currentStreamingAudio: StreamingAudioState | null = null;
|
|
58
60
|
let bufferedAudioChunks: ArrayBuffer[] = [];
|
|
59
61
|
let bufferedAudioMimeType = 'audio/mpeg';
|
|
62
|
+
let wasAudioResponseReceived = false;
|
|
60
63
|
|
|
61
64
|
function stopGenerationAndAudio() {
|
|
62
|
-
|
|
65
|
+
setAudioModeReadyToRespond();
|
|
63
66
|
stopCurrentAudioPlayback();
|
|
64
67
|
currentAbortController?.abort();
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
function setAudioModeReadyToRespond() {
|
|
71
|
+
agentAudioMode.value = 'readyToRespond';
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
async function sendAudioToServerAndHandleResponse(blob: Blob) {
|
|
68
75
|
currentAbortController = new AbortController();
|
|
76
|
+
wasAudioResponseReceived = false;
|
|
69
77
|
const formData = new FormData();
|
|
70
78
|
formData.append('file', blob, 'user_prompt.wav');
|
|
71
79
|
formData.append('sessionId', agentStore.activeSessionId);
|
|
@@ -99,7 +107,9 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
99
107
|
}
|
|
100
108
|
} finally {
|
|
101
109
|
isStreamingResponse.value = false;
|
|
102
|
-
|
|
110
|
+
if (!wasAudioResponseReceived) {
|
|
111
|
+
setAudioModeReadyToRespond();
|
|
112
|
+
}
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
115
|
|
|
@@ -175,14 +185,15 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
175
185
|
stopStandByAudio();
|
|
176
186
|
agentStore.setCurrentChatStatus('ready');
|
|
177
187
|
agentStore.addAgentMessage(event.data.response.text);
|
|
178
|
-
agentAudioMode.value = 'playingAgentResponse';
|
|
179
188
|
return;
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
if (event.type === 'audio-start') {
|
|
192
|
+
wasAudioResponseReceived = true;
|
|
183
193
|
isStreamingResponse.value = false;
|
|
184
194
|
agentAudioMode.value = 'fetchingAudio';
|
|
185
195
|
initializeAudioStream(event.data.mimeType);
|
|
196
|
+
agentAudioMode.value = 'playingAgentResponse';
|
|
186
197
|
return;
|
|
187
198
|
}
|
|
188
199
|
|
|
@@ -197,7 +208,9 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
197
208
|
}
|
|
198
209
|
|
|
199
210
|
if (event.type === 'data-tool-call') {
|
|
200
|
-
|
|
211
|
+
if (!isStandByAudioPlaying) {
|
|
212
|
+
playStandByAudio();
|
|
213
|
+
}
|
|
201
214
|
agentStore.addDataToolCallMessage(event.data);
|
|
202
215
|
}
|
|
203
216
|
}
|
|
@@ -344,12 +357,12 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
344
357
|
detachStreamingAudio();
|
|
345
358
|
destroyCurrentAudioElement();
|
|
346
359
|
if (!dontResetMode) {
|
|
347
|
-
|
|
360
|
+
setAudioModeReadyToRespond();
|
|
348
361
|
}
|
|
349
362
|
}
|
|
350
363
|
|
|
351
364
|
function handleAudioEnded() {
|
|
352
|
-
|
|
365
|
+
setAudioModeReadyToRespond();
|
|
353
366
|
stopCurrentAudioPlayback();
|
|
354
367
|
}
|
|
355
368
|
|
|
@@ -63,7 +63,7 @@ onMounted(() => {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
watch(agentAudioMode, (newVal) => {
|
|
66
|
+
watch(agentAudioMode, async (newVal) => {
|
|
67
67
|
if(newVal === 'streaming') {
|
|
68
68
|
stopCurrentAudioPlayback(true);
|
|
69
69
|
microphoneButtonMode.value = 'generating';
|
|
@@ -72,10 +72,11 @@ watch(agentAudioMode, (newVal) => {
|
|
|
72
72
|
} else if (newVal === 'fetchingAudio') {
|
|
73
73
|
//Generation is done, waiting for audio to be ready
|
|
74
74
|
} else if (newVal === 'playingAgentResponse') {
|
|
75
|
-
// Audio is playing
|
|
76
|
-
} else {
|
|
75
|
+
// Audio is playing'
|
|
76
|
+
} else if (newVal === 'readyToRespond') {
|
|
77
77
|
if(isAudioChatMode.value) {
|
|
78
78
|
microphoneButtonMode.value = 'listen';
|
|
79
|
+
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
79
80
|
} else {
|
|
80
81
|
microphoneButtonMode.value = 'off';
|
|
81
82
|
}
|
|
@@ -94,8 +95,8 @@ function toggleChatMode() {
|
|
|
94
95
|
|
|
95
96
|
async function onStartRecording() {
|
|
96
97
|
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
microphoneButtonMode.value = 'listen';
|
|
99
|
+
agentAudio.playBeep(1000);
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function onStopRecording() {
|
|
@@ -142,12 +143,8 @@ async function sendRecordForTranscription() {
|
|
|
142
143
|
showAudioWavesAnimation.value = false;
|
|
143
144
|
const recordBlob = await getRecord();
|
|
144
145
|
if (recordBlob) {
|
|
145
|
-
console.log('Audio recorded, sending to server for transcription. Audio Blob size:', recordBlob.size, recordBlob.type);
|
|
146
146
|
onStopRecording();
|
|
147
147
|
await sendAudioToServerAndHandleResponse(recordBlob);
|
|
148
|
-
if (agentStore.isAudioChatMode) {
|
|
149
|
-
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
150
|
-
}
|
|
151
148
|
} else {
|
|
152
149
|
console.error('No audio recorded');
|
|
153
150
|
}
|
|
@@ -15,7 +15,7 @@ type StreamingAudioState = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
let standByAudio: HTMLAudioElement | null = null;
|
|
18
|
-
|
|
18
|
+
let isStandByAudioPlaying = false;
|
|
19
19
|
function playStandByAudio() {
|
|
20
20
|
if (!standByAudio) {
|
|
21
21
|
standByAudio = new Audio(`/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`);
|
|
@@ -27,6 +27,7 @@ function playStandByAudio() {
|
|
|
27
27
|
}
|
|
28
28
|
standByAudio.currentTime = 0;
|
|
29
29
|
standByAudio.play()
|
|
30
|
+
isStandByAudioPlaying = true;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function stopStandByAudio() {
|
|
@@ -35,6 +36,7 @@ function stopStandByAudio() {
|
|
|
35
36
|
}
|
|
36
37
|
standByAudio.pause();
|
|
37
38
|
standByAudio.currentTime = 0;
|
|
39
|
+
isStandByAudioPlaying = false;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function restartStandByAudio() {
|
|
@@ -47,7 +49,7 @@ function restartStandByAudio() {
|
|
|
47
49
|
|
|
48
50
|
export const useAgentAudio = defineStore('agentAudio', () => {
|
|
49
51
|
const agentStore = useAgentStore();
|
|
50
|
-
const agentAudioMode = ref<'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' |
|
|
52
|
+
const agentAudioMode = ref<'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' | 'readyToRespond' >('readyToRespond');
|
|
51
53
|
const isStreamingResponse = ref(false);
|
|
52
54
|
|
|
53
55
|
let currentAbortController: AbortController | null = null;
|
|
@@ -57,15 +59,21 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
57
59
|
let currentStreamingAudio: StreamingAudioState | null = null;
|
|
58
60
|
let bufferedAudioChunks: ArrayBuffer[] = [];
|
|
59
61
|
let bufferedAudioMimeType = 'audio/mpeg';
|
|
62
|
+
let wasAudioResponseReceived = false;
|
|
60
63
|
|
|
61
64
|
function stopGenerationAndAudio() {
|
|
62
|
-
|
|
65
|
+
setAudioModeReadyToRespond();
|
|
63
66
|
stopCurrentAudioPlayback();
|
|
64
67
|
currentAbortController?.abort();
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
function setAudioModeReadyToRespond() {
|
|
71
|
+
agentAudioMode.value = 'readyToRespond';
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
async function sendAudioToServerAndHandleResponse(blob: Blob) {
|
|
68
75
|
currentAbortController = new AbortController();
|
|
76
|
+
wasAudioResponseReceived = false;
|
|
69
77
|
const formData = new FormData();
|
|
70
78
|
formData.append('file', blob, 'user_prompt.wav');
|
|
71
79
|
formData.append('sessionId', agentStore.activeSessionId);
|
|
@@ -99,7 +107,9 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
99
107
|
}
|
|
100
108
|
} finally {
|
|
101
109
|
isStreamingResponse.value = false;
|
|
102
|
-
|
|
110
|
+
if (!wasAudioResponseReceived) {
|
|
111
|
+
setAudioModeReadyToRespond();
|
|
112
|
+
}
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
115
|
|
|
@@ -175,14 +185,15 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
175
185
|
stopStandByAudio();
|
|
176
186
|
agentStore.setCurrentChatStatus('ready');
|
|
177
187
|
agentStore.addAgentMessage(event.data.response.text);
|
|
178
|
-
agentAudioMode.value = 'playingAgentResponse';
|
|
179
188
|
return;
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
if (event.type === 'audio-start') {
|
|
192
|
+
wasAudioResponseReceived = true;
|
|
183
193
|
isStreamingResponse.value = false;
|
|
184
194
|
agentAudioMode.value = 'fetchingAudio';
|
|
185
195
|
initializeAudioStream(event.data.mimeType);
|
|
196
|
+
agentAudioMode.value = 'playingAgentResponse';
|
|
186
197
|
return;
|
|
187
198
|
}
|
|
188
199
|
|
|
@@ -197,7 +208,9 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
197
208
|
}
|
|
198
209
|
|
|
199
210
|
if (event.type === 'data-tool-call') {
|
|
200
|
-
|
|
211
|
+
if (!isStandByAudioPlaying) {
|
|
212
|
+
playStandByAudio();
|
|
213
|
+
}
|
|
201
214
|
agentStore.addDataToolCallMessage(event.data);
|
|
202
215
|
}
|
|
203
216
|
}
|
|
@@ -344,12 +357,12 @@ export const useAgentAudio = defineStore('agentAudio', () => {
|
|
|
344
357
|
detachStreamingAudio();
|
|
345
358
|
destroyCurrentAudioElement();
|
|
346
359
|
if (!dontResetMode) {
|
|
347
|
-
|
|
360
|
+
setAudioModeReadyToRespond();
|
|
348
361
|
}
|
|
349
362
|
}
|
|
350
363
|
|
|
351
364
|
function handleAudioEnded() {
|
|
352
|
-
|
|
365
|
+
setAudioModeReadyToRespond();
|
|
353
366
|
stopCurrentAudioPlayback();
|
|
354
367
|
}
|
|
355
368
|
|
|
@@ -63,7 +63,7 @@ onMounted(() => {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
watch(agentAudioMode, (newVal) => {
|
|
66
|
+
watch(agentAudioMode, async (newVal) => {
|
|
67
67
|
if(newVal === 'streaming') {
|
|
68
68
|
stopCurrentAudioPlayback(true);
|
|
69
69
|
microphoneButtonMode.value = 'generating';
|
|
@@ -72,10 +72,11 @@ watch(agentAudioMode, (newVal) => {
|
|
|
72
72
|
} else if (newVal === 'fetchingAudio') {
|
|
73
73
|
//Generation is done, waiting for audio to be ready
|
|
74
74
|
} else if (newVal === 'playingAgentResponse') {
|
|
75
|
-
// Audio is playing
|
|
76
|
-
} else {
|
|
75
|
+
// Audio is playing'
|
|
76
|
+
} else if (newVal === 'readyToRespond') {
|
|
77
77
|
if(isAudioChatMode.value) {
|
|
78
78
|
microphoneButtonMode.value = 'listen';
|
|
79
|
+
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
79
80
|
} else {
|
|
80
81
|
microphoneButtonMode.value = 'off';
|
|
81
82
|
}
|
|
@@ -94,8 +95,8 @@ function toggleChatMode() {
|
|
|
94
95
|
|
|
95
96
|
async function onStartRecording() {
|
|
96
97
|
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
microphoneButtonMode.value = 'listen';
|
|
99
|
+
agentAudio.playBeep(1000);
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function onStopRecording() {
|
|
@@ -142,12 +143,8 @@ async function sendRecordForTranscription() {
|
|
|
142
143
|
showAudioWavesAnimation.value = false;
|
|
143
144
|
const recordBlob = await getRecord();
|
|
144
145
|
if (recordBlob) {
|
|
145
|
-
console.log('Audio recorded, sending to server for transcription. Audio Blob size:', recordBlob.size, recordBlob.type);
|
|
146
146
|
onStopRecording();
|
|
147
147
|
await sendAudioToServerAndHandleResponse(recordBlob);
|
|
148
|
-
if (agentStore.isAudioChatMode) {
|
|
149
|
-
await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
|
|
150
|
-
}
|
|
151
148
|
} else {
|
|
152
149
|
console.error('No audio recorded');
|
|
153
150
|
}
|