diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index 00d18fe3..eaa62b80 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -24,6 +24,7 @@ import { toast } from "sonner"; import Link from "next/link"; import { createChatObject } from "@/app/actions/doers"; import { ClipboardIcon, SpeakerWaveIcon } from "@heroicons/react/24/outline"; +import { SpeakerOffIcon } from "@radix-ui/react-icons"; function ChatWindow({ q, @@ -68,6 +69,7 @@ function ChatWindow({ }; const handleTTS = (text: string) => { + if (isSpeaking) return stopTTS(); if (!text) return; const utterThis: SpeechSynthesisUtterance = new SpeechSynthesisUtterance( text, @@ -81,6 +83,14 @@ function ChatWindow({ }; }; + const stopTTS = () => { + if (isSpeaking) { + const speechSynth: SpeechSynthesis = window.speechSynthesis; + speechSynth.cancel(); + setIsSpeaking(false); + } + }; + const router = useRouter(); const getAnswer = async ( @@ -335,7 +345,6 @@ function ChatWindow({ {/* speak response */}