I'm trying to execute a function once while there are many times a single event listener is repeating, I'm building a text-to-speech app, and I'm trying critical event listeners but the app generates voice again and again on every single event, I did with start/stop button it works, but I want to speak automatically after 1 or 0.5 seconds when we type something in textarea
document.querySelector("textarea").addEventListener("keyup", async e => {
let executed = false;
speech.text = document.querySelector("textarea").value;
if (!executed) {
executed = true;
window.speechSynthesis.speak(speech);
} else {
console.log("executed");
}
});
I tried to complete using Booleans but not worked