I want to add Read Aloud feature in my weweb project which means it will read the text aloud and for this I am using the following code on button click but it is not working for me. Please help!!
function readAloud(text) {
if ('speechSynthesis' in window) {
const speech = new SpeechSynthesisUtterance(text);
speech.lang = 'en-US'; // You can set the language.
speechSynthesis.speak(speech);
} else {
alert('Sorry, your browser does not support text-to-speech.');
}
}
// Pass the text you want to read aloud.
readAloud(“hello please help me”);