Google Chrome浏览器语音中的女性声音 [英] Female voice in google chrome speechSynthesis
本文介绍了Google Chrome浏览器语音中的女性声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在两种情况下我都使用此确切的代码.
Im using this exact code in both the scenarios.
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[1];
msg.text = "hello world";
msg.lang = 'en-US';
speechSynthesis.speak(msg);
如果我在chrome控制台中运行此命令,则会听到女性声音.但是,如果我将确切的代码放在index.html中并运行它,它会发出男性的声音.任何人都可以澄清为什么会出现这种差异.预先感谢.
If I run this in the chrome console I get a female voice. But if I put the exact code in an index.html and run it, it plays a male voice. Could any one please clarify why this difference occurs. Thanks in advance.
推荐答案
找到了根本原因. 获取语音中的语音列表Chrome(Web Speech API)
这些调用是异步的,因此当我尝试在index.html中运行时,voices数组为空.正如我建议的那样,当我运行该程序然后使用语音时,效果很好.
The calls are async, so when I try to run in index.html the voices array is empty. As I suggested when I run this and then use the speak it works fine.
var msg;
var voices;
var timer = setInterval(function() {
voices = speechSynthesis.getVoices();
console.log(voices);
if (voices.length !== 0) {
msg = new SpeechSynthesisUtterance();
msg.voice = voices[0];
speechSynthesis.speak(msg);
msg.lang = 'en-US';
clearInterval(timer);
}
}, 200);
timer();
speechSynthesis.speak("hello world");
这篇关于Google Chrome浏览器语音中的女性声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文