我正在尝试更改语音合成 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();
});
有任何想法吗?