[英]Chrome speech synthesis api not changing options
我正在嘗試更改語音合成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();
});
有任何想法嗎?
有一個Chrome已知的問題 ,速率,音量或音高選項對某些聲音沒有影響。
另外, speechSynthesis.getVoices()
第二次運行的原因是它在Chrome中它應該在onvoiceschanged
事件之后被調用(參見這個答案 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.