每当我运行此代码时,我都会得到一个女性响应,然后第二次我得到一个男性声音,如果我尝试再次运行它,它将无法响应。
这是代码/
var aiload = document.getElementById('ai').innerHTML
var msg = new SpeechSynthesisUtterance(aiload);
var voices = window.speechSynthesis.getVoices();
voices.forEach(function (voice, i) {
var voiceName = 'Google UK English Female';
var selected = '';
if(voiceName == 'native') {
selected = 'selected';
}
var option = "<option value='" + voiceName + "' " + selected + " >" + voiceName + "</option>";
voiceSelect.append(option);
console.log(voiceName);
});
msg.volume = 1; // 0 to 1
msg.rate = 1; // 0.1 to 10
msg.pitch = 0; //0 to 2 …Run Code Online (Sandbox Code Playgroud)