Speech synthesis keeps speaking on page load

Viewed 354

In one of my PHP project I have integrated speech synthesis. On click of button I am calling a function for text to speech. Like,

var newUtterance = new SpeechSynthesisUtterance();
newUtterance.text = 'Test Message';
window.speechSynthesis.speak(newUtterance);

This works perfect. But when user refreshes the page it keeps speaking where I want to stop it on page load. I tried with, On document ready function,

if (window.speechSynthesis.speaking) {
   window.speechSynthesis.cancel();
}

and also like, On page load function,

var newUtterance = new SpeechSynthesisUtterance();
newUtterance.text = '';
window.speechSynthesis.speak(newUtterance);

But not working. Working on chrome browser. Thanks in advance.

0 Answers
Related