From b8e35002f49557c0b32928fd217ea7a5e3bbfa0c Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 30 May 2024 22:01:40 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=A3=EF=B8=8F=20fix:=20Set=20Audio=20Ru?= =?UTF-8?q?n=20ID=20at=20Top=20of=20Autoplayback=20Request=20(#2926)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/Chat/Input/StreamAudio.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/components/Chat/Input/StreamAudio.tsx b/client/src/components/Chat/Input/StreamAudio.tsx index 8edf93b517..e0d58054da 100644 --- a/client/src/components/Chat/Input/StreamAudio.tsx +++ b/client/src/components/Chat/Input/StreamAudio.tsx @@ -49,7 +49,8 @@ export default function StreamAudio({ index = 0 }) { useEffect(() => { const latestText = getLatestText(latestMessage); - const shouldFetch = + + const shouldFetch = !!( token && automaticPlayback && isSubmitting && @@ -60,7 +61,8 @@ export default function StreamAudio({ index = 0 }) { !latestMessage.messageId.includes('_') && !isFetching && activeRunId && - activeRunId !== audioRunId; + activeRunId !== audioRunId + ); if (!shouldFetch) { return; @@ -80,12 +82,12 @@ export default function StreamAudio({ index = 0 }) { const cache = await caches.open('tts-responses'); const cachedResponse = await cache.match(cacheKey); + setAudioRunId(activeRunId); if (cachedResponse) { console.log('Audio found in cache'); const audioBlob = await cachedResponse.blob(); const blobUrl = URL.createObjectURL(audioBlob); setGlobalAudioURL(blobUrl); - setAudioRunId(activeRunId); setIsFetching(false); return; } @@ -113,7 +115,6 @@ export default function StreamAudio({ index = 0 }) { mediaSource = new MediaSourceAppender(type); setGlobalAudioURL(mediaSource.mediaSourceUrl); } - setAudioRunId(activeRunId); let done = false; const chunks: Uint8Array[] = [];