gpt4 book ai didi

speech-synthesis - 语音合成 API 音量、速率和音调不起作用

转载 作者:行者123 更新时间:2023-12-04 14:34:29 29 4
gpt4 key购买 nike

长话短说,语音合成音量、速率和音调不起作用。是否有其他人遇到此问题并知道如何解决它,还是只有我一个人?

长话短说:

对我来说,语音合成的音量、速率和音调不起作用。这是我的语音功能:

function speak(message, voice, callback, volume, rate, pitch, start, lang) {
if (speech) {
window.speechSynthesis.onvoiceschanged = function() {
voices = window.speechSynthesis.getVoices();
var msg = new SpeechSynthesisUtterance();
msg.voice = (typeof voice != "undefined" && voice != 0) ? voices[voice] : voices[0]; // Note: some voices don't support altering params
msg.volume = (typeof volume != "undefined" && volume != 0) ? volume : 1; // 0 to 1
msg.rate = (typeof rate != "undefined" && rate != 0) ? rate : 1; // 0.1 to 10
msg.pitch = (typeof pitch != "undefined" && pitch != 0) ? pitch : 2; //0 to 2
msg.text = message;
msg.lang = (typeof lang != "undefined" && lang != 0) ? lang : "en-US";

msg.onstart = function(event) {
if (typeof start != "undefined" && start != 0) {
start(event);
}
}

msg.onend = function(event) {
console.log(event.elapsedTime);
if (typeof callback != "undefined" && callback != 0) {
callback(event);
}
};

speechSynthesis.speak(msg);
};
}
}

但是,当我调用 speak("Hello", 0, 0, 0.1) 时,它输出与 speak("Hello") 完全相同的内容。我想让它输出同样的东西,但更柔和。

我目前正在关注 http://updates.html5rocks.com/2014/01/Web-apps-that-talk---Introduction-to-the-Speech-Synthesis-API .

最佳答案

这更像是评论,但可能是错字。

看起来语音合成类也有速率属性。

一定要把它设置在话语上而不是语音合成对象上。

不正确:

speechSynthesis.rate = 2;
speechSynthesis.speak(utterance);

正确:

utterance.rate = 2;
speechSynthesis.speak(utterance);

关于speech-synthesis - 语音合成 API 音量、速率和音调不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25223547/

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