From 1cc3493dc8219da44b9ff69fd009ddcf18ba5732 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 6 Nov 2025 01:48:10 -0500 Subject: [PATCH] enh/refac: read aloud audio queue --- src/lib/components/chat/Chat.svelte | 18 +++- .../chat/Messages/ResponseMessage.svelte | 102 +++++++----------- src/lib/stores/index.ts | 2 + src/lib/utils/audio.ts | 73 +++++++++++++ 4 files changed, 130 insertions(+), 65 deletions(-) create mode 100644 src/lib/utils/audio.ts diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 59bf1fe2a..56b93f364 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -27,6 +27,7 @@ banners, user, socket, + audioQueue, showControls, showCallOverlay, currentChatPage, @@ -43,6 +44,7 @@ pinnedChats, showEmbeds } from '$lib/stores'; + import { convertMessagesToHistory, copyToClipboard, @@ -53,6 +55,8 @@ removeAllDetails, getCodeBlockContents } from '$lib/utils'; + import { AudioQueue } from '$lib/utils/audio'; + import { createNewChat, getAllTags, @@ -529,17 +533,28 @@ let showControlsSubscribe = null; let selectedFolderSubscribe = null; + const stopAudio = () => { + try { + speechSynthesis.cancel(); + $audioQueue.stop(); + } catch {} + }; + onMount(async () => { loading = true; console.log('mounted'); window.addEventListener('message', onMessageHandler); $socket?.on('events', chatEventHandler); + audioQueue.set(new AudioQueue(document.getElementById('audioElement'))); + pageSubscribe = page.subscribe(async (p) => { if (p.url.pathname === '/') { await tick(); initNewChat(); } + + stopAudio(); }); const storageChatInput = sessionStorage.getItem( @@ -621,6 +636,7 @@ chatIdUnsubscriber?.(); window.removeEventListener('message', onMessageHandler); $socket?.off('events', chatEventHandler); + $audioQueue?.destroy(); } catch (e) { console.error(e); } @@ -2347,7 +2363,7 @@ -