New issue
Advanced search Search tips
Starred by 28 users

Issue metadata

Status: Duplicate
Owner:
Closed: Oct 2014
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

SpeechSynthesisUtterance is stopping

Reported by bored...@gmail.com, Jan 18 2014

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0

Steps to reproduce the problem:
1. var u=new SpeechSynthesisUtterance();
2. set u.text to a long text (at least a few 100, better 1000 signs), maybe a full article of a news site.
3. window.speechSynthesis.speak(u)

What is the expected behavior?
it should read the complete text.

What went wrong?
after a few lines, it suddenly stops. For example in the attached text file (a description of the SpeechSynthesis API of the W3C), it ALWAYS stops after "...zero or more interim results. On subsequent" and then break, and window.speechSynthesis.speaking=false (the length of the read text is something like 300 signs)

Did this work before? N/A 

Chrome version: 33.0.1750.29 (Offizieller Build 244627) beta-m  Channel: beta
OS Version: 6.3
Flash Version: Shockwave Flash 12.0 r0

no.

 
Labels: Needs-Feedback
Thanks so much for filing. Can you please provide a sample file to reproduce this issue?

Comment 2 by bored...@gmail.com, Jan 24 2014

When setting the following String as Input (german language) "Suchbegriff TrackingDie Analyse von Suchbegriffen auf angeschlossenen Webseiten wurde geaendert. War dies vorher nur auf Videos und fuer Webseiten mit Community bezogen, steht die Analyse hier nun fuer alle Webseiten/Apps und auch ohne Community Modul zur Verfuegung unter Analyse/Statistik/Sessions/Suchbegriffe." - Chrome33 starts speaking but stops always after "ohne Community Modul". I can see this behaviour with every text I add and which is longer than a few words (I already stripped the german special characters, if they are present, it doesnt event start to speak..."

Comment 3 by tkent@chromium.org, Jan 28 2014

Labels: Cr-Blink-Speech
Owner: dmazz...@chromium.org
Status: Assigned
Labels: -Needs-Feedback

Comment 6 by ashm...@gmail.com, Feb 22 2014

I have same issue.

See second speak() call below for an example of a long text that breaks speech synthesis. It always stops after 'information'.

function speak(text) {
    var msg = new SpeechSynthesisUtterance();
    var voices = speechSynthesis.getVoices();
    msg.voice = voices[10];
    msg.voiceURI = 'native';
    msg.volume = 1;
    msg.rate = 1;
    msg.pitch = 2;
    msg.text = text;
    msg.lang = 'en-US';
    
    speechSynthesis.speak(msg);
}

speak('Short text');
speak('Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without revolutionary ROI. Efficiently unleash cross-media information without cross-media value. Quickly maximize timely deliverables for real-time schemas. Dramatically maintain clicks-and-mortar solutions without functional solutions.');
speak('Another short text');

This example is available at
http://jsfiddle.net/Mdm47/1/

After that, speech synthesis is completely blocked in the browser (all tabs). All new texts silently fail: they are not spoken, but there are no exceptions or console logs.

State of speechSynthesis object after the problem:
  paused: false
  pending: false
  speaking: false

Even though speaking is false, calling speechSynthesis.cancel unblocks speech synthesis and allows texts to be spoken again.

Comment 7 by ashm...@gmail.com, Feb 22 2014

My environment is: Windows 7 x64, Chrome 33.0.1750.117.
Labels: Needs-Feedback
I think this should have been fixed by r252208,  bug 333515 . Can you confirm it's working on Canary now?

Comment 9 by Deleted ...@, Mar 13 2014

I have been experiencing the same problem. The TTS is cut off around the 285-310 character point. I tested it in Chrome Canary (35.0.1887.0), but I'm still having the same problem.

Comment 10 by Deleted ...@, Mar 13 2014

I am seeing the same issue on Version 33.0.1750.149 OSX

I note that after the sound cuts out, SpeechSynthesisUtterance is completely broken unless you restart the browser.

Comment 11 by Deleted ...@, Mar 13 2014

Same bug with text in French. Tested with Chrome Canary 35.0.1888.0 OSX. No problem with the same text on Safari (Mac OS X Mavericks or iOS 7).
just tested this with canary 35.0.1892.0 on osx 10.9 and have the same bug, it cuts off after ~280 characters.

calling speechSynthesis.cancel() gets it working again, but it will never read the full text.

Comment 13 by Deleted ...@, Mar 29 2014

Confirmed bug on Windows 35.0.1914.0 canary

Comment 14 by end...@gmail.com, Apr 9 2014

Confirmed on Chrome 34.0.1847.116 (Vista 32bit).

Comment 15 by Deleted ...@, Apr 9 2014

Solution found: You need to set the voice to a native voice.

Comment 16 by Deleted ...@, May 2 2014

I have the exactly the same issue here.   Any fix for it?

Comment 17 by Deleted ...@, May 2 2014

Set the voice to native does not solve the issue.

Comment 18 Deleted

I beleive this to be a duplicate of https://code.google.com/p/chromium/issues/detail?id=369472 

Comment 20 by mle...@gmail.com, May 6 2014

Same issue on Chrome 34.0.1847.131 and Chrome Canary 36.0.1976.2 (OSX 10.6.8) 
Labels: -Needs-Feedback
I've had this issue for a while now with Google Chrome Speech Synthesis. After some investigation, I discovered the following:

 - The breaking of the utterances only happens when the voice is not a native voice,
 - The cutting out usually occurs between 200-300 characters as previously mentioned,
 - When it does break, as someone previously mentioned, you can un-freeze it by doing speechSynthesis.cancel();
 - The 'onend' event sometimes decides not to fire. A quirky work-around to this is to console.log() out the utterance object before speaking it. Also I found wrapping the speak invocation in a setTimeout callback helps smooth these issues out.
 
In response to these problems, I have written a function that overcomes the character limit, by chunking the text up into smaller utterances, and playing them one after another. Obviously you'll get some odd sounds sometimes as sentences might be chunked into two separate utterances with a small time delay in between each, however the code will try and split these points at punctuation marks as to make the breaks in sound less obvious.

Usage of the code:

//create an utterance as you normally would...
var myLongText = "JavaScript is a dynamic computer programming language. It is most commonly used as part of web browsers, "+
                             "whose implementations allow client-side scripts to interact with the user, control the browser, communicate "+
                             "asynchronously, and alter the document content that is displayed. It is also being used in server-side "+
                             "programming, game development and the creation of desktop and mobile applications.";

var utterance = new SpeechSynthesisUtterance(myLongText);

//modify it as you normally would
var voiceArr = speechSynthesis.getVoices();
utterance.voice = voiceArr[2];

//pass it into the chunking function to have it played out.
//you can set the max number of characters by changing the chunkLength property below.
//a callback function can also be added that will fire once the entire text has been spoken.
speechUtteranceChunker(utterance, { chunkLength:120 }, function(){
    //some code to execute when done
    console.log('done');
});


The code:

var speechUtteranceChunker = function (utt, settings, callback) {
    settings = settings || {};
    var chunkLength = settings && settings.chunkLength || 160;
    var pattRegex = new RegExp('^.{' + Math.floor(chunkLength / 2) + ',' + chunkLength + '}[\.\!\?\,]{1}|^.{1,' + chunkLength + '}$|^.{1,' + chunkLength + '} ');
    var txt = (settings && settings.offset !== undefined ? utt.text.substring(settings.offset) : utt.text);
    var chunkArr = txt.match(pattRegex);

    if (chunkArr[0] !== undefined && chunkArr[0].length > 2) {
        var chunk = chunkArr[0];
        var newUtt = new SpeechSynthesisUtterance(chunk);
        for (x in utt) {
            if (utt.hasOwnProperty(x) && x !== 'text') {
                newUtt[x] = utt[x];
            }
        }
        newUtt.onend = function () {
            settings.offset = settings.offset || 0;
            settings.offset += chunk.length - 1;
            speechUtteranceChunker(utt, settings, callback);
        }
        console.log(newUtt); //IMPORTANT!! Do not remove: Logging the object out fixes some onend firing issues.
        //placing the speak invocation inside a callback fixes ordering and onend issues.
        setTimeout(function () {
            speechSynthesis.speak(newUtt);
        }, 0);
    } else {
        //call once all text has been spoken...
        if (callback !== undefined) {
            callback();
        }
    }
}

Comment 23 Deleted

Comment 24 by Deleted ...@, Sep 19 2014

PJ, I modified your code to turn it into a bookmarklet which speaks the text currently selected:

javascript:(function(){var text="";if(typeof window.getSelection!="undefined"){var sel=window.getSelection();if(sel.rangeCount){var container=document.createElement("div");for(var i=0,len=sel.rangeCount;i<len;++i){container.appendChild(sel.getRangeAt(i).cloneContents());}text=container.innerText;}}else if(typeof document.selection!="undefined"){if(document.selection.type=="Text"){text=document.selection.createRange().text;}}text=text.replace(/\s+/g," ");console.log(text);speechSynthesis.cancel();var speechUtteranceChunker=function(utt,settings,callback){settings=settings||{};var chunkLength=settings&&settings.chunkLength||160;var pattRegex=new RegExp('^.{'+Math.floor(chunkLength/2)+','+chunkLength+'}[\.\!\?\,]{1}|^.{1,'+chunkLength+'}$|^.{1,'+chunkLength+'} ');var txt=(settings&&settings.offset!==undefined?utt.text.substring(settings.offset):utt.text);var chunkArr=txt.match(pattRegex);if(chunkArr[0]!==undefined&&chunkArr[0].length>2){var chunk=chunkArr[0];var newUtt=new SpeechSynthesisUtterance(chunk);for(var x in utt){if(utt.hasOwnProperty(x)&&x!=='text'){newUtt[x]=utt[x];}}newUtt.onend=function(){settings.offset=settings.offset||0;settings.offset+=chunk.length-1;speechUtteranceChunker(utt,settings,callback);};console.log(newUtt);setTimeout(function(){speechSynthesis.speak(newUtt);},0);}else{if(callback!==undefined){callback();}}};var utterance=new SpeechSynthesisUtterance(text);speechUtteranceChunker(utterance,{chunkLength:120},function(){console.log('done');});})();
Mergedinto: 369472
Status: Duplicate

Comment 26 by kar...@quizlet.com, Jul 17 2015

Issue is still occurring in Chrome 43.0.2357.132 on OS X 10.10.4.

Comment 27 by Deleted ...@, Aug 20 2015

Issue is stil occuring in Chrome 44.0.2403.155. Even with a very simple implementation, such as...

if ('speechSynthesis' in window) {
    var utterance = new SpeechSynthesisUtterance();
    utterance.text = "This is a chunk of text that will be spoken.";
    window.speechSynthesis.speak(utternace);
}

I can't get this to even read the text once. It just doesn't work at all.
You mistyped here "window.speechSynthesis.speak(utterNAce);" instead of utterANce.
Hello,

Just for information, I've made some tests and this problem is reproducible only when you select a voice different than the native voice.

I'm using Version 51.0.2704.106 on Windows 7 64 bits.

When I try to read a long text (more than 300 characters), the utteration stops brutally, but not with native voice.

You cant find in attachments the script I used to bypass the problem: split the text in sentences.
SpeechSynthesis.js
2.0 KB View Download

Comment 30 by hai.p...@gmail.com, Oct 14 2016

I'm having the same issue but with chrome.tts extension API.  I believe it's not the # of characters but the number of words.  It stops at about 43 words:

chrome.tts.speak("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ", {voiceName: "Google US English"})
so its almost 2017 now. was anyone able to get this working?

i think the issue may be related to the fact that the on.end event is never fired

Comment 32 by hai.p...@gmail.com, Jan 27 2017

I figured it out.  It's not the # of words, characters or syllables.  It's a 15-second timer!  If the speechlet is longer than 15 seconds, it gets stuck.

I changed the Rate so it speaks twice as slowly or twice as fast, and it still gets stuck at the same time duration.

Comment 33 by tsteu...@gmail.com, Mar 21 2017

I can confirm this issue still exists:

Version 56.0.2924.87 (64-bit)
Linux (Ubuntu 16.10)

Comment 34 by tsteu...@gmail.com, Mar 26 2017

Posting this here in case anyone doesn't read the other issue:

=======

This issue still happens in Version 56.0.2924.87 (64-bit) on Ubuntu 16.10.

I have found the following:

To get the speech to keep going without chunking the data, you can do the following:


setTimeout(function() {
  speechSynthesis.pause();
  speechSynthesis.resume();
}, 10000);

And it will continue playing without any issues. However, there is another issue no one has mentioned:

If you pause the speechSynthesis and wait for more than 5-10 seconds and then resume(), it will not read anymore and none of the events fire anymore.

---

In regards to my comment above, please see this JSfiddle:

https://jsfiddle.net/8dsv1y7a/3/

If you hit play, then pause, wait 15-20 seconds, and hit resume, it will not make any noise nor fire any events.

Comment 35 Deleted

Comment 36 by ise...@gmail.com, Sep 22 2017

What is the status of issue 369472? https://code.google.com/p/chromium/issues/detail?id=369472
This bug still exists in Version 64.0.3282.119 (Offizieller Build) (64-Bit) on Ubuntu 16.04. That's more than 4 years now!
Chrome 65.0.3325.181 on OSX stil has this bug. Longer texts don't work at all. 

After I try to get a long tekst read, other tabs refuses to read (short) textx as wel. 

Bug is open for close to 4.5 year now...

Yes, the google synthesis api will stop at some point during speaking a long text.

We can see onend event, onpause and onerror event of SpeechSynthesisUtterance won't be fired normally when the sudden stop happens, so does the speechSynthesis onerror event.

After several trials, found speechSynthesis.paused is working, and speechSynthesis.resume() can help resume the speaking. 

Hence we just need to have a timer to check the pause status during the speaking, and calling speechSynthesis.resume() to continue. The interval should be small enough to prevent glitch when continuing the speak.



    let timer = null;
    let reading = false;

    let readText = function(text) {

        if (!reading) {
            speechSynthesis.cancel();
            if (timer) {
                clearInterval(timer);
            }
            let msg = new SpeechSynthesisUtterance();
            let voices = window.speechSynthesis.getVoices();
            msg.voice = voices[82];
            msg.voiceURI = 'native';
            msg.volume = 1; // 0 to 1
            msg.rate = 1.0; // 0.1 to 10
            msg.pitch = 1; //0 to 2
            msg.text = text;
            msg.lang = 'zh-TW';

            msg.onerror = function(e) {
                speechSynthesis.cancel();
                reading = false;
                clearInterval(timer);
            };

            msg.onpause = function(e) {
                console.log('onpause in ' + e.elapsedTime + ' seconds.');
            }            

            msg.onend = function(e) {
                console.log('onend in ' + e.elapsedTime + ' seconds.');
                speechSynthesis.cancel();
                reading = false;
                clearInterval(timer);
            };

            speechSynthesis.onerror = function(e) {
                console.log('speechSynthesis onerror in ' + e.elapsedTime + ' seconds.');
                speechSynthesis.cancel();
                reading = false;
                clearInterval(timer);
            };

            speechSynthesis.speak(msg);

            timer = setInterval(function(){
                if (speechSynthesis.paused) {
                    console.log("#continue")
                    speechSynthesis.resume();
                }

            }, 100);

            reading = true;

        }
    }

Sign in to add a comment