I am trying speech to text part of the window.speechSynthesis
as soon as the Speak function is called the onend function gets triggered on chrome.
This works well in Playcanvas editor, but once we make the build stops working Chrome browser.
The build works fine on Edge.
The result of onended being called instantly(This is my guess, cant find a better reason) we never hear anything on chrome for TextToSpeech.
Below is the code:
function TextToSpeech(s) {
oSpeechSynthesisUtterance = new SpeechSynthesisUtterance();
if (oVoices) {
var sVoice = selVoices.value;
if (sVoice != "") {
oSpeechSynthesisUtterance.voice = oVoices[parseInt(sVoice)];
}
}
oSpeechSynthesisUtterance.onend = function () {
if (oSpeechRecognizer) {
oSpeechRecognizer.start();
}
}
if (oSpeechRecognizer) {
//do not listen to yourself when talking
oSpeechRecognizer.stop();
}
oSpeechSynthesisUtterance.lang = "en-US";
oSpeechSynthesisUtterance.text = "HELLO WORLD! YOU'RE BEAUTIFUL WORLD";
//Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed
window.speechSynthesis.speak(oSpeechSynthesisUtterance);
}