I am using SpeechSynthesisUtterance in my mobile website. This code is okay when I use it in my desktop version website. But I found that the function is not working in mobile browser in document.ready as below:
$(document).ready(function(){
var text_tts="say something";
speakText(text_tts);
});
function speakText(text_tts){
var u = new SpeechSynthesisUtterance();
u.text = text_tts;
u.lang = 'en-US';
u.rate = 1;
u.onend = function(event) { console.log('Finished in ' + event.elapsedTime + ' seconds.'); }
speechSynthesis.speak(u);
}
But when I use "click" event, it works:
$("body").on("click",".button",function(){
var tmp_body_text="say something";
var u = new SpeechSynthesisUtterance();
u.text = tmp_body_text;
u.lang = 'en-US';
u.rate = 1;
//u.onend = function(event) { console.log('Finished in ' + event.elapsedTime + ' seconds.'); }
speechSynthesis.speak(u);
});
Please help. Thank you.