I'm trying to create a speech-to-text command then the server will reply as text then convert it to speech using react-speech-kit. Both function works fine, but what I wanted to do is call the Speak() function from useSpeechSynthesis automatically.
I've called the speak function on onEnd function from useSpeechRecognition like this
const onEnd = () => {
fetch(
"http://api/Main?id=test&lang=kor&req=" +
value,
{}
)
.then((res) => res.json())
.then(
(result) => {
setResponse(result.res);
speak(result.res);
console.log(result);
},
(error) => {
console.log(error);
}
);
// You could do something here after speaking has finished
};
But it doesn't speak for itself after the value has been passed.
Does anyone know how to make it automatic?
EDIT
I was wrong to call speak function like that, it should've be like this
speak({text:result.res}); It is working now, TTS automatically calls, but it calls over and over again, not once, anyone knows how to fix it?