window.speechSynthesis onend gets called instantly on chrome

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) {

    if (oSpeechRecognizer) {
        //do not listen to yourself when talking

    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 

Hi @Raghavendra_U and welcome,

Are you getting any error when running your code? PlayCanvas shouldn’t be affecting that since it’s a vanilla web API.

I tried the following minimal example both on editor launch window and on a build and it works as expected:

function TextToSpeech(s) {

    let utterance = new SpeechSynthesisUtterance(s);

// TextToSpeech("Hello world!")

Make sure on launch you are running your build without an iframe if testing in the console.

Hi @Leonidas

Thanks for the reply.
Strange that the issue cannot be reproduced at your end.
The issue is consistent for me on chrome I am consistently able to reproduce this issue.
The same build when I run on Edge it works as intended.
Just re-confirmed it again. Also I am using the build link without iFrame with an extended ‘e’.
I also checked that the chrome browser I have is the updated one.


Not sure about that sorry, but given the browser text to speech API is client side, I don’t think this is related to the PlayCanvas build.

But if you can provide a sample build that reproduces the error, we can give it a try.

Thanks for the test. Will try to check maybe something to do with my browser setting.

Found the problem the issue was related to my browser setting. Somehow I had set the Not allowed to Play sounds for Playcanvas sites.

1 Like