这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
onvoiceschanged
特性为
SpeechSynthesis
interface represents an event handler that will run when the list of
SpeechSynthesisVoice
objects that would be returned by the
SpeechSynthesis.getVoices()
method has changed (when the
voiceschanged
event fires.)
This may occur when speech synthesis is being done on the server-side and the voices list is being determined asynchronously, or when client-side voices are installed/uninstalled while a speech synthesis application is running.
speechSynthesisInstance.onvoiceschanged = function() { ... };
This could be used to populate a list of voices that the user can choose between when the event fires (see our
Speak easy synthesis demo
.) Note that Firefox doesn't support it at present, and will just return a list of voices when
SpeechSynthesis.getVoices()
is fired. With Chrome however, you have to wait for the event to fire before populating the list, hence the bottom if statement seen below.
var voices = [];
function populateVoiceList() {
voices = synth.getVoices();
for(i = 0; i < voices.length ; i++) {
var option = document.createElement('option');
option.textContent = voices[i].name + ' (' + voices[i].lang + ')';
if(voices[i].default) {
option.textContent += ' -- DEFAULT';
}
option.setAttribute('data-lang', voices[i].lang);
option.setAttribute('data-name', voices[i].name);
voiceSelect.appendChild(option);
}
}
populateVoiceList();
if (speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 语音 API
The definition of 'onvoiceschanged' in that specification. |
草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onvoiceschanged
|
Chrome 33 | Edge 14 | Firefox 49 | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 4.4.3 | Chrome Android 33 | Firefox Android 62 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 3.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
SpeechSynthesis