Repository navigation
startListening and stopListening not working #229
Unanswered
jerinthomascarmel
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
i am developing react application using react-speech-recognition package ;
my application listens the speech, it triggers sendMessage function when the transcript is triggered after 3 seconds (using setTimeout ) .
when sendMessage function called , it needs to stopListening (SpeechRecognition.stopListening ) . but it is not working.
Here are the few code snippets having the logic ?
`
const {
transcript,
resetTranscript,
browserSupportsSpeechRecognition,
isMicrophoneAvailable,
} = useSpeechRecognition({ commands });
let [idleTimeout, setIdleTimeout] = useState(null);
useEffect(() => {
if (idleTimeout) {
clearTimeout(idleTimeout);
}
}, [transcript]);
const sendMessage = async (text) => {
playTone(TONES.BEFORE_LOADING);
if (!isOpenRef.current || !text || loading || speaking) {
return;
}
console.log("send message is called ! ");
stopSpeech({ handleStopSpeaking });
resetTranscript();
console.log("reset transcript is called before the sending message ! ");
setLoading(true);
SpeechRecognition.stopListening();
fetchResponse(text)
.then((response) => {
setInputOutputList((prevList) => [
...prevList,
{ input: text, output: response },
]);
return generateAudioSpeech({ text: response }).then((audioURL) => {
playTone(TONES.COMPLETION);
if (isOpenRef.current) {
speakText({
audioURL,
handleStartSpeaking,
handleStopSpeaking,
});
}
};
`
All reactions