From 1ac947bcf67da9c67340974a7c71921d09f94cb6 Mon Sep 17 00:00:00 2001 From: adetyaz Date: Tue, 19 Nov 2024 09:50:39 +0100 Subject: [PATCH] fix: transcript, header --- src/components/header.tsx | 50 +++++++++++++------------- src/components/voice-assistant.tsx | 56 +++++++++++++++--------------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/components/header.tsx b/src/components/header.tsx index bef6ecb..05c82ac 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -12,7 +12,7 @@ const Header = ({ home, onClick, userType, - showAttestation + showAttestation, }: { home: boolean onClick?: React.ReactEventHandler @@ -33,7 +33,6 @@ const Header = ({ const [storedAddress, setStoredAddress] = useState(null) - const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com' useEffect(() => { @@ -136,7 +135,7 @@ const Header = ({ className={`fixed top-0 w-full py-4 transition-all duration-300 ease-in-out ${isScrolled ? 'bg-white' : 'bg-transparent'} ${home ? 'bg-gradient-to-r' : 'bg-transparent'} - + text-white z-20`} style={ home @@ -156,27 +155,28 @@ const Header = ({ !home ? 'hidden' : 'sm:flex' }`} > - - Home - - - Studio + Studio + Discover + + WebXR - Discover - - - - WebXR + Home + + +
@@ -314,9 +314,11 @@ const Header = ({ Menu - {userType === 'owner' &&
- Create -
} + {userType === 'owner' && ( +
+ Create +
+ )}
{isDropdownOpen && ( diff --git a/src/components/voice-assistant.tsx b/src/components/voice-assistant.tsx index c6b8e85..f554d00 100644 --- a/src/components/voice-assistant.tsx +++ b/src/components/voice-assistant.tsx @@ -18,7 +18,7 @@ export const VoiceAssistant = ({ userType, }: any) => { const [isListening, setIsListening] = useState(false) - // const [transcript, setTranscript] = useState('') + const [transcript, setTranscript] = useState('') // const [response, setResponse] = useState('') // console.log(userType) @@ -95,30 +95,30 @@ export const VoiceAssistant = ({ }, ]) - // useEffect(() => { - // const synth = window.speechSynthesis - - // // Create a speech synthesis utterance - // const utterance = new SpeechSynthesisUtterance( - // `Welcome, Feel free to explore ${brandName} and discover hidden treasures together with your AI companion.` - // ) - - // // Speak the message after a delay of 5 seconds - // const timeoutId = setTimeout(() => { - // if (!synth.speaking) { - // synth.speak(utterance) - // } - // }, 5000) - - // // Cleanup function to cancel speech synthesis and timeout if necessary - // return () => { - // clearTimeout(timeoutId) - // if (synth.speaking) { - // synth.cancel() - // console.log('Speech synthesis canceled') - // } - // } - // }, []) + useEffect(() => { + const synth = window.speechSynthesis + + // Create a speech synthesis utterance + const utterance = new SpeechSynthesisUtterance( + `Welcome, Feel free to explore ${brandName} and discover hidden treasures together with your AI companion.` + ) + + // Speak the message after a delay of 5 seconds + const timeoutId = setTimeout(() => { + if (!synth.speaking) { + synth.speak(utterance) + } + }, 5000) + + // Cleanup function to cancel speech synthesis and timeout if necessary + return () => { + clearTimeout(timeoutId) + if (synth.speaking) { + synth.cancel() + console.log('Speech synthesis canceled') + } + } + }, []) useEffect(() => { // Feature detection for webkitSpeechRecognition @@ -135,7 +135,7 @@ export const VoiceAssistant = ({ recognition.onresult = (event: any) => { const speechToText = event.results[0][0].transcript - // setTranscript(speechToText) + setTranscript(speechToText) addMessage({ role: 'user', content: speechToText }) getOpenAIResponse(speechToText) } @@ -236,12 +236,12 @@ export const VoiceAssistant = ({ return (
- {/* {transcript && ( + {transcript && (

User:  {transcript}

)} - {response && ( + {/* {response && (

Assistant:  {response}