[英]Web Accessibility. window.speechSynthesis vs role "alert"
To immediately announce error for control/input I have 2 choices:要立即宣布控制/输入错误,我有 2 个选择:
alert. [errorMessageHere]
alert. [errorMessageHere]
alert. [errorMessageHere]
const el = document.createElement('div'); el.setAttribute('role', 'alert'); el.className = 'visually-hidden'; el.textContent = 'Some message here'; document.body.append(el);
.visually-hidden { position: absolute; height: 1px; width: 1px; top: 0; left: 0; overflow: hidden; clip: rect(1px, 1px, 1px, 1px); }
window.speechSynthesis.speak
.window.speechSynthesis.speak
。 NVDA announce [errorMessageHere] const speakObj = new SpeechSynthesisUtterance('Some message here'); window.speechSynthesis.speak(speakObj)
What I really notice that in NVDA you can disable text-to-speech and show speech-viewer.我真正注意到的是,在 NVDA 中,您可以禁用文本转语音并显示语音查看器。 First case will be logged into speech-viewer but 2nd case - not.
第一种情况将登录到语音查看器,但第二种情况 - 不是。 NVDA directly announce text when NVDA is opened even if text-to-speech is disabled.
NVDA 在打开 NVDA 时直接播报文本,即使禁用了文本转语音。
I'd prefer to use window.speechSynthesis.speak instead of creating extra HTMLElements per each case when some details/errors must be announced but I'm not sure is it correct alternative of role 'alert' since window.speechSynthesis.speak is not logged by NVDA at all (but only announced).当必须宣布一些细节/错误时,我更喜欢使用 window.speechSynthesis.speak 而不是在每种情况下创建额外的 HTMLElements 但我不确定它是否正确替代角色“警报”,因为 window.speechSynthesis.speak 不是完全由 NVDA 记录(但仅公布)。
Could help me to understand what the best way to be announced/read by screen reader ?可以帮助我了解屏幕阅读器宣布/阅读的最佳方式是什么?
You should definitely prefer live regions and role alert over speech API.您绝对应该更喜欢实时区域和角色警报而不是语音 API。
When using live regions or role alert, the message goes through the screen reader, which brings several important advantages:使用实时区域或角色警报时,消息会通过屏幕阅读器,这带来了几个重要优势:
None of the three are possible when using speech API:使用语音 API 时,这三个都不可能:
In fact, use cases for each of the two are quite different:事实上,两者的用例都大不相同:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.