【问题标题】:Speech Synthesis API Volume, Rate, and Pitch don't work语音合成 API 音量、速率和音高不起作用
【发布时间】:2014-10-03 02:48:18
【问题描述】:

长话短说,语音合成的音量、速率和音高不起作用。是否有其他人遇到此问题并知道如何解决,还是只有我一个人?

长篇大论:

对我来说,语音合成的音量、速率和音高不起作用。这是我的语音功能:

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);
        };
    }
}

但是,当我调用speak("Hello", 0, 0, 0.1) 时,它输出的内容与speak("Hello") 完全相同。我想让它输出同样的东西,但更柔和。

我目前关注http://updates.html5rocks.com/2014/01/Web-apps-that-talk---Introduction-to-the-Speech-Synthesis-API

【问题讨论】:

    标签: speech-synthesis webspeech-api


    【解决方案1】:

    这更像是一个评论,但它可能是一个错字。

    看起来 Speech Synthesis 类也有一个 rate 属性。

    请务必将其设置在话语而不是语音合成对象上。

    不正确:

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

    正确:

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

    【讨论】:

      【解决方案2】:

      由于某种原因,如果您将语言更改为 en-EN,参数将起作用。

      【讨论】:

        【解决方案3】:

        据我所见,设置这些参数仅在声音来自local service 时有效。

        正如您所指出的,这可能是并非所有声音都支持设置参数的情况。

        【讨论】:

          【解决方案4】:

          我也在尝试做同样的事情。但是我设法通过在我希望它放慢速度的地方添加一个句号来使其工作。我知道这不是正确的方法,但它对我来说有点工作

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

          在此之前

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2015-09-14
            • 2014-03-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-03
            • 1970-01-01
            相关资源
            最近更新 更多