0

我正在尝试更改语音合成 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();
});

有任何想法吗?

4

1 回答 1

2

Chrome存在一个已知问题,即速率、音量或音高选项对某些声音没有影响。

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

于 2015-02-09T22:09:37.040 回答