这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
voiceschanged
event of the
Web 语音 API
is fired when the list of
SpeechSynthesisVoice
objects that would be returned by the
SpeechSynthesis.getVoices()
method has changed (when the
voiceschanged
event fires.)
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
事件
|
| 事件处理程序特性 |
onvoiceschanged
|
This could be used to repopulate a list of voices that the user can choose between when the event fires. You can use the
voiceschanged
event in an
addEventListener
方法:
var synth = window.speechSynthesis;
synth.addEventListener('voiceschanged', function() {
var voices = synth.getVoices();
for(i = 0; i < voices.length ; i++) {
var option = document.createElement('option');
option.textContent = voices[i].name + ' (' + voices[i].lang + ')';
option.setAttribute('data-lang', voices[i].lang);
option.setAttribute('data-name', voices[i].name);
voiceSelect.appendChild(option);
}
});
或使用
onvoiceschanged
事件处理程序特性:
synth.onvoiceschanged = function() {
var voices = synth.getVoices();
for(i = 0; i < voices.length ; i++) {
var option = document.createElement('option');
option.textContent = voices[i].name + ' (' + voices[i].lang + ')';
option.setAttribute('data-lang', voices[i].lang);
option.setAttribute('data-name', voices[i].name);
voiceSelect.appendChild(option);
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 语音 API
The definition of 'speech synthesis events' in that specification. |
草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
voiceschanged
event
|
Chrome 33 | Edge 14 | Firefox 49 | IE 不支持 No | Opera 21 | Safari 7 | WebView Android 4.4.3 | Chrome Android 33 | Firefox Android 62 | Opera Android 不支持 No | Safari iOS 7 | Samsung Internet Android 3.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
SpeechSynthesis
voiceschanged