From 521daee8a6ba0b301a0a91729040155dab282edf Mon Sep 17 00:00:00 2001 From: kraken Date: Sat, 3 Aug 2024 01:44:48 +0530 Subject: [PATCH 1/4] feat: disable speaker button while speaking --- apps/web/app/(dash)/chat/chatWindow.tsx | 48 +++++++++++++++---------- apps/web/wrangler.toml | 22 ++++++------ 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index 662c7217..00d18fe3 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -51,6 +51,7 @@ function ChatWindow({ }) { const [layout, setLayout] = useState<"chat" | "initial">("chat"); const [chatHistory, setChatHistory] = useState(initialChat); + const [isSpeaking, setIsSpeaking] = useState(false); const removeJustificationFromText = (text: string) => { // remove everything after the first "" word @@ -66,6 +67,20 @@ function ChatWindow({ return text; }; + const handleTTS = (text: string) => { + if (!text) return; + const utterThis: SpeechSynthesisUtterance = new SpeechSynthesisUtterance( + text, + ); + const speechSynth: SpeechSynthesis = window.speechSynthesis; + utterThis.lang = "en-US"; + speechSynth.speak(utterThis); + setIsSpeaking(true); + utterThis.onend = () => { + setIsSpeaking(false); + }; + }; + const router = useRouter(); const getAnswer = async ( @@ -305,25 +320,6 @@ function ChatWindow({
- {/* speak response */} - {/* copy response */} + {/* speak response */} +
diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 7f3fa047..675038c6 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -5,13 +5,13 @@ pages_build_output_dir = ".vercel/output/static" kv_namespaces = [ - { binding = "CANVAS_SNAPS", id = "6df98c892b3744ccb0c631d9f60d6697" }, - { binding = "RECOMMENDATIONS", id = "83bc7055226c4657948141c2ff9a5425" } + { binding = "CANVAS_SNAPS", id = "24c7048fa9064e7787dd58760b21dc8d" }, + { binding = "RECOMMENDATIONS", id = "abfd16f09b0b4300908115a5a177429e" } ] env.production.kv_namespaces = [ - { binding = "CANVAS_SNAPS", id = "6df98c892b3744ccb0c631d9f60d6697" }, - { binding = "RECOMMENDATIONS", id = "83bc7055226c4657948141c2ff9a5425" } + { binding = "CANVAS_SNAPS", id = "24c7048fa9064e7787dd58760b21dc8d" }, + { binding = "RECOMMENDATIONS", id = "abfd16f09b0b4300908115a5a177429e" } ] [ai] @@ -22,26 +22,26 @@ mode = "smart" [[r2_buckets]] binding = "STORAGE" -bucket_name = "dev-r2-anycontext" +bucket_name = "supermemory-r2" [[d1_databases]] binding = "DATABASE" -database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" +database_name = "supermemory-db-preview" +database_id = "b09e126c-8179-4927-876a-6a03ee94334b" [[env.production.d1_databases]] binding = "DATABASE" -database_name = "prod-d1-supermemory" -database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395" +database_name = "supermemory-db-prod" +database_id = "0dea4084-3629-4aea-938c-da478a32f5cd" [env.preview.ai] binding = "AI" [[env.preview.d1_databases]] binding = "DATABASE" -database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" +database_name = "supermemory-db-preview" +database_id = "b09e126c-8179-4927-876a-6a03ee94334b" [env.production.ai] binding = "AI" \ No newline at end of file From eefea19888b0fa1d7e8c13186200af7458d88613 Mon Sep 17 00:00:00 2001 From: kraken Date: Sat, 3 Aug 2024 01:54:14 +0530 Subject: [PATCH 2/4] feat: stop tts button added --- apps/web/app/(dash)/chat/chatWindow.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 */} From 23f382a4342cd970a23ac38e1dc825ee5b05492e Mon Sep 17 00:00:00 2001 From: kraken Date: Sat, 3 Aug 2024 02:12:29 +0530 Subject: [PATCH 3/4] feat: selective disabling of buttons --- apps/web/app/(dash)/chat/chatWindow.tsx | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index eaa62b80..d186d0be 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -52,7 +52,8 @@ function ChatWindow({ }) { const [layout, setLayout] = useState<"chat" | "initial">("chat"); const [chatHistory, setChatHistory] = useState(initialChat); - const [isSpeaking, setIsSpeaking] = useState(false); + const [speakingIdx, setSpeakingIdx] = useState(null); + const speechSynth: SpeechSynthesis = window.speechSynthesis; const removeJustificationFromText = (text: string) => { // remove everything after the first "" word @@ -68,27 +69,23 @@ function ChatWindow({ return text; }; - const handleTTS = (text: string) => { - if (isSpeaking) return stopTTS(); + const handleTTS = (text: string, idx: number) => { + if (speakingIdx != null) return stopTTS(); if (!text) return; const utterThis: SpeechSynthesisUtterance = new SpeechSynthesisUtterance( text, ); - const speechSynth: SpeechSynthesis = window.speechSynthesis; utterThis.lang = "en-US"; speechSynth.speak(utterThis); - setIsSpeaking(true); + setSpeakingIdx(idx); utterThis.onend = () => { - setIsSpeaking(false); + setSpeakingIdx(null); }; }; const stopTTS = () => { - if (isSpeaking) { - const speechSynth: SpeechSynthesis = window.speechSynthesis; - speechSynth.cancel(); - setIsSpeaking(false); - } + speechSynth.cancel(); + setSpeakingIdx(null); }; const router = useRouter(); @@ -345,19 +342,23 @@ function ChatWindow({ {/* speak response */} From fe948ef2905089b5fd750d1404472e2dbcf107f8 Mon Sep 17 00:00:00 2001 From: kraken Date: Sat, 3 Aug 2024 02:18:03 +0530 Subject: [PATCH 4/4] fix: wrong icon for speaker-x --- apps/web/app/(dash)/chat/chatWindow.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index d186d0be..a691c0ce 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -6,7 +6,7 @@ import QueryInput from "./chatQueryInput"; import { cn } from "@repo/ui/lib/utils"; import { motion } from "framer-motion"; import { useRouter } from "next/navigation"; -import { ChatHistory, sourcesZod } from "@repo/shared-types"; +import { type ChatHistory, sourcesZod } from "@repo/shared-types"; import { Accordion, AccordionContent, @@ -23,8 +23,11 @@ import { codeLanguageSubset } from "@/lib/constants"; 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"; +import { + ClipboardIcon, + SpeakerWaveIcon, + SpeakerXMarkIcon, +} from "@heroicons/react/24/outline"; function ChatWindow({ q, @@ -93,7 +96,7 @@ function ChatWindow({ const getAnswer = async ( query: string, spaces: string[], - proMode: boolean = false, + proMode = false, ) => { if (query.trim() === "from_loading" || query.trim().length === 0) { return; @@ -356,7 +359,7 @@ function ChatWindow({ className="group h-8 w-8 flex justify-center items-center active:scale-75 duration-200" > {speakingIdx === idx ? ( - + ) : ( )}