gpt4 book ai didi

javascript - Chrome 语音合成 api 不更改选项

转载 作者:行者123 更新时间:2023-12-02 17:28:02 25 4
gpt4 key购买 nike

我正在尝试更改语音合成 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 known issue速率、音量或音高选项对某些声音没有影响。

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

关于javascript - Chrome 语音合成 api 不更改选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23329139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com