Опитвам се да променя екземпляр на опциите на API за синтез на реч (като височина, сила на звука и т.н.), но не работи. По някаква причина единственият начин да го накарам да промени гласа от UK мъжки на UK женски е да извикам променливата 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();
});
Някакви идеи?