From d1f20d0c9b3b985bd68f600401e83920c24fbd57 Mon Sep 17 00:00:00 2001 From: adetyaz Date: Tue, 19 Nov 2024 15:57:37 +0100 Subject: [PATCH] fix: temp voice recognition fix --- src/components/voice-assistant.tsx | 57 +++++++++++++++--------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/components/voice-assistant.tsx b/src/components/voice-assistant.tsx index f554d00..656cc93 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 @@ -129,13 +129,14 @@ export const VoiceAssistant = ({ if (SpeechRecognition) { recognition = new SpeechRecognition() + recognition.continuous = false recognition.interimResults = false recognition.lang = 'en-US' recognition.onresult = (event: any) => { const speechToText = event.results[0][0].transcript - setTranscript(speechToText) + // setTranscript(speechToText) addMessage({ role: 'user', content: speechToText }) getOpenAIResponse(speechToText) } @@ -236,11 +237,11 @@ export const VoiceAssistant = ({ return (
- {transcript && ( + {/* {transcript && (

User:  {transcript}

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

Assistant:  {response}