3

Long story short, Speech Synthesis volume, rate, and pitch don't work. Is there anyone else having this issue and know how to resolve it, or am I alone?

Long story longer:

For me, Speech Synthesis volume, rate, and pitch don't work. Here is my speech function:

function speak(message, voice, callback, volume, rate, pitch, start, lang) {
    if (speech) {
        window.speechSynthesis.onvoiceschanged = function() {
            voices = window.speechSynthesis.getVoices();
            var msg = new SpeechSynthesisUtterance();
            msg.voice = (typeof voice != "undefined" && voice != 0) ? voices[voice] : voices[0]; // Note: some voices don't support altering params
            msg.volume = (typeof volume != "undefined" && volume != 0) ? volume : 1; // 0 to 1
            msg.rate = (typeof rate != "undefined" && rate != 0) ? rate : 1; // 0.1 to 10
            msg.pitch = (typeof pitch != "undefined" && pitch != 0) ? pitch : 2; //0 to 2
            msg.text = message;
            msg.lang = (typeof lang != "undefined" && lang != 0) ? lang : "en-US";

            msg.onstart = function(event) {
                if (typeof start != "undefined" && start != 0) {
                    start(event);
                }
            }

            msg.onend = function(event) {
                console.log(event.elapsedTime);
                if (typeof callback != "undefined" && callback != 0) {
                    callback(event);
                }
            };

            speechSynthesis.speak(msg);
        };
    }
}

However, when I call speak("Hello", 0, 0, 0.1) it outputs the exact same thing as speak("Hello"). I want to make it output the same thing but softer.

I am currently following http://updates.html5rocks.com/2014/01/Web-apps-that-talk---Introduction-to-the-Speech-Synthesis-API .

Sarah Elan
  • 2,465
  • 1
  • 23
  • 45
Nathan
  • 1,321
  • 1
  • 18
  • 32

4 Answers4

2

This is more of a comment but it could be a typo.

It looks like Speech Synthesis class has a rate property as well.

Be sure to set it on the utterance and not the speech synthesis object.

Incorrect:

speechSynthesis.rate = 2;
speechSynthesis.speak(utterance);

Correct:

utterance.rate = 2;
speechSynthesis.speak(utterance);
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
1

For some reason, the parameters will work if you change the language to en-EN.

John Lee
  • 893
  • 13
  • 14
0

From what I am seeing, setting these parameters only has an effect when the voice is from a local service.

As you noted, this is probably a case of not all voices supporting the ability to set parameters.

Sarah Elan
  • 2,465
  • 1
  • 23
  • 45
0

I am trying to do the same thing too. But i managed to make it work by adding a fullstop where I want it to slow down. I know this is not the right way to do it but it is kind of working for me

var u = new SpeechSynthesisUtterance();
        u.text = 'Welcome to Handy Mandy. Lets Get Started. Say Handy Mandy.';
        //u.lang = 'en-US';
        //u.rate = 10;
        //u.onend = function(event) { alert('Finished in ' + event.elapsedTime + ' seconds.'); }
        speechSynthesis.speak(u);

Before this it

Raaz
  • 1,669
  • 2
  • 24
  • 48