语音综合在Safari Macos中不起作用12.3
语音综合API在MacOS 12.3上无法使用Safari(它在MACOS11上起作用)。我有以下代码,当用户单击一个按钮时,请调用speaknow()函数。在功能中,将创建新的语音语言和窗口。SpeeChsynthesis.speak(Tusterance)将被调用。之后,期望tublesance.onstart(),发声的声音,然后称呼tustance.onend()。
function speaknow() {
if ('speechSynthesis' in window) {
window.utterances = [];
this.utterance = new SpeechSynthesisUtterance();
this.utterance.text = 'Speaker on';
window.utterances.push(this.utterance);
this.utterance.onstart = function(event) {
console.info('this.utterance.onstart()');
}
this.utterance.onend = function(){
console.info('this.utterance.onend()');
};
this.utterance.onerror = function(event) {
console.error('error utterance ', event );
}
window.speechSynthesis.speak(this.utterance);
setTimeout(function(){
// NOTE: forceStop=true is set through button click
if (!window.speechSynthesis.speaking && (!forceStop)) {
speaknow(); // re-attempt
console.info('window.speechSynthesis is not speaking. Re-attempt speaknow().');
}
else if (window.speechSynthesis.speaking) {
console.info('window.speechSynthesis.speaking: ' + window.speechSynthesis.speaking);
}
},500);
}
}
观察:
- 根本没有声音。
- 在第一次time window.speechsynthesis.speak()被调用,tusterance.onstart()从未被调用,但是tusterance.onend()被调用。
- window.speechsynthesis.speaking始终是正确的。
- 对于下一个time window.speechsynthesis.speak()被调用,tublesance.onstart()和tusterance.onend()均被调用。 window.speechsynthesis。说话仍然是真实的,但仍然没有声音。
The Speech Synthesis API does not work on Safari on MacOS 12.3 (It is working on MacOS11). I have the code below where when user clicks a button will call speaknow() function. In the function, new SpeechUtterance utterance is created and window.speechSynthesis.speak(utterance) will be called. Afterwards, it is expected for utterance.onstart(), sound of the utterance, then utterance.onend() to be called.
function speaknow() {
if ('speechSynthesis' in window) {
window.utterances = [];
this.utterance = new SpeechSynthesisUtterance();
this.utterance.text = 'Speaker on';
window.utterances.push(this.utterance);
this.utterance.onstart = function(event) {
console.info('this.utterance.onstart()');
}
this.utterance.onend = function(){
console.info('this.utterance.onend()');
};
this.utterance.onerror = function(event) {
console.error('error utterance ', event );
}
window.speechSynthesis.speak(this.utterance);
setTimeout(function(){
// NOTE: forceStop=true is set through button click
if (!window.speechSynthesis.speaking && (!forceStop)) {
speaknow(); // re-attempt
console.info('window.speechSynthesis is not speaking. Re-attempt speaknow().');
}
else if (window.speechSynthesis.speaking) {
console.info('window.speechSynthesis.speaking: ' + window.speechSynthesis.speaking);
}
},500);
}
}
Observation:
- No sound at all.
- During the first time window.speechSynthesis.speak() gets called, utterance.onstart() never gets called, but utterance.onend() gets called.
- window.speechSynthesis.speaking is always true.
- For the next time window.speechSynthesis.speak() gets called, neither utterance.onstart() nor utterance.onend() gets called. window.speechSynthesis.speaking remains true but still no sound.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论