diff --git a/src/lib/components/chat/MessageInput/CallOverlay.svelte b/src/lib/components/chat/MessageInput/CallOverlay.svelte index 11adc5298..1bbbdc293 100644 --- a/src/lib/components/chat/MessageInput/CallOverlay.svelte +++ b/src/lib/components/chat/MessageInput/CallOverlay.svelte @@ -31,6 +31,7 @@ let loading = false; let confirmed = false; let interrupted = false; + let assistantSpeaking = false; let emoji = null; @@ -268,6 +269,14 @@ return; } + if (assistantSpeaking) { + analyser.maxDecibels = 0; + analyser.minDecibels = -10; + } else { + analyser.minDecibels = MIN_DECIBELS; + analyser.maxDecibels = -30; + } + analyser.getByteTimeDomainData(timeDomainData); analyser.getByteFrequencyData(domainData); @@ -379,6 +388,7 @@ }; const stopAllAudio = async () => { + assistantSpeaking = false; interrupted = true; if (chatStreaming) { @@ -485,6 +495,7 @@ } } else if (finishedMessages[id] && messages[id] && messages[id].length === 0) { // If the message is finished and there are no more messages to process, break the loop + assistantSpeaking = false; break; } else { // No messages to process, sleep for a bit @@ -511,6 +522,7 @@ } audioAbortController = new AbortController(); + assistantSpeaking = true; // Start monitoring and playing audio for the message ID monitorAndPlayAudio(id, audioAbortController.signal); } @@ -545,9 +557,9 @@ const chatFinishHandler = async (e) => { const { id, content } = e.detail; // "content" here is the entire message from the assistant + finishedMessages[id] = true; chatStreaming = false; - finishedMessages[id] = true; }; eventTarget.addEventListener('chat:start', chatStartHandler); @@ -577,7 +589,15 @@ >