【问题标题】:Chrome speech synthesis api not changing optionsChrome 语音合成 api 不改变选项
【发布时间】:2014-04-27 21:20:18
【问题描述】:

我正在尝试更改语音合成 API 选项(例如音高、音量等)的实例,但它不起作用。出于某种原因,我可以将声音从英国男性更改为英国女性的唯一方法是调用 var voices 变量两次,但这是我可以更改的唯一选项。代码如下:

//After the document loads (using the prototype library)
document.observe("dom:loaded", function() {
    //When the speakMe button is clicked
    $("speakMe").observe('click', function() {
        //Get the entered phrase
        phrase = $('phraseBar').getValue();
        //If the phrase is blank
        if(phrase =="")
        {
            //Warning message
            alert("Please enter a phrase before asking me to speak for you. Thank you!");
        }
        else
        {
            //Declare the speach object & set attributes
            var speech = new SpeechSynthesisUtterance(phrase);
            var voices = speechSynthesis.getVoices();
            var options = new Object();
            speech.default = false;
            speech.localservice = true;
            speech.voice = voices.filter(function(voice) { return voice.name == userVoice; })[0];    
            speech.lang = userLang;
            speech.rate = userRate;
            speech.pitch = 2;
            speech.volume = userVolume;

            //Speak the phrase
            window.speechSynthesis.speak(speech);

        }
    });
    var voices = speechSynthesis.getVoices();
});

有什么想法吗?

【问题讨论】:

    标签: javascript prototype text-to-speech speech-synthesis google-text-to-speech


    【解决方案1】:

    有一个Chrome known issue,其中速率、音量或音高选项对某些声音没有影响。

    另外,speechSynthesis.getVoices() 第二次工作的原因是它在 Chrome 中应该在onvoiceschanged 事件之后调用(参见this answer)。

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 2017-07-30
      • 1970-01-01
      • 2018-10-03
      • 2019-11-05
      • 2014-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多