@@ -49,7 +49,7 @@ function restartStandByAudio() {
4949
5050export const useAgentAudio = defineStore ( 'agentAudio' , ( ) => {
5151 const agentStore = useAgentStore ( ) ;
52- const agentAudioMode = ref < 'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' | null > ( null ) ;
52+ const agentAudioMode = ref < 'transcribing' | 'streaming' | 'fetchingAudio' | 'playingAgentResponse' | 'readyToRespond' > ( 'readyToRespond' ) ;
5353 const isStreamingResponse = ref ( false ) ;
5454
5555 let currentAbortController : AbortController | null = null ;
@@ -59,15 +59,21 @@ export const useAgentAudio = defineStore('agentAudio', () => {
5959 let currentStreamingAudio : StreamingAudioState | null = null ;
6060 let bufferedAudioChunks : ArrayBuffer [ ] = [ ] ;
6161 let bufferedAudioMimeType = 'audio/mpeg' ;
62+ let wasAudioResponseReceived = false ;
6263
6364 function stopGenerationAndAudio ( ) {
64- agentAudioMode . value = null ;
65+ setAudioModeReadyToRespond ( ) ;
6566 stopCurrentAudioPlayback ( ) ;
6667 currentAbortController ?. abort ( ) ;
6768 }
6869
70+ function setAudioModeReadyToRespond ( ) {
71+ agentAudioMode . value = 'readyToRespond' ;
72+ }
73+
6974 async function sendAudioToServerAndHandleResponse ( blob : Blob ) {
7075 currentAbortController = new AbortController ( ) ;
76+ wasAudioResponseReceived = false ;
7177 const formData = new FormData ( ) ;
7278 formData . append ( 'file' , blob , 'user_prompt.wav' ) ;
7379 formData . append ( 'sessionId' , agentStore . activeSessionId ) ;
@@ -101,7 +107,9 @@ export const useAgentAudio = defineStore('agentAudio', () => {
101107 }
102108 } finally {
103109 isStreamingResponse . value = false ;
104- agentAudioMode . value = null ;
110+ if ( ! wasAudioResponseReceived ) {
111+ setAudioModeReadyToRespond ( ) ;
112+ }
105113 }
106114 }
107115
@@ -177,14 +185,15 @@ export const useAgentAudio = defineStore('agentAudio', () => {
177185 stopStandByAudio ( ) ;
178186 agentStore . setCurrentChatStatus ( 'ready' ) ;
179187 agentStore . addAgentMessage ( event . data . response . text ) ;
180- agentAudioMode . value = 'playingAgentResponse' ;
181188 return ;
182189 }
183190
184191 if ( event . type === 'audio-start' ) {
192+ wasAudioResponseReceived = true ;
185193 isStreamingResponse . value = false ;
186194 agentAudioMode . value = 'fetchingAudio' ;
187195 initializeAudioStream ( event . data . mimeType ) ;
196+ agentAudioMode . value = 'playingAgentResponse' ;
188197 return ;
189198 }
190199
@@ -348,12 +357,12 @@ export const useAgentAudio = defineStore('agentAudio', () => {
348357 detachStreamingAudio ( ) ;
349358 destroyCurrentAudioElement ( ) ;
350359 if ( ! dontResetMode ) {
351- agentAudioMode . value = null ;
360+ setAudioModeReadyToRespond ( ) ;
352361 }
353362 }
354363
355364 function handleAudioEnded ( ) {
356- agentAudioMode . value = null ;
365+ setAudioModeReadyToRespond ( ) ;
357366 stopCurrentAudioPlayback ( ) ;
358367 }
359368
0 commit comments