简体   繁体   English

网页可访问性。 window.speechSynthesis 与角色“警报”

[英]Web Accessibility. window.speechSynthesis vs role "alert"

To immediately announce error for control/input I have 2 choices:要立即宣布控制/输入错误,我有 2 个选择:

  1. append HTMLElement to document with role 'alert' and error-message.将 HTMLElement 附加到具有角色“警报”和错误消息的文档。 NVDA reads alert. [errorMessageHere] NVDA 读取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); }

  1. Use window.speechSynthesis.speak .使用window.speechSynthesis.speak NVDA announce [errorMessageHere] NVDA 宣布 [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:使用实时区域或角色警报时,消息会通过屏幕阅读器,这带来了几个重要优势:

  • It is read with the voice settings configured in the screen reader (voice, language, rate, pitch, volume, etc.)使用屏幕阅读器中配置的语音设置(语音、语言、速率、音高、音量等)读取
  • It is recorded in speech history, meaning that the user can repeat the message if he/she missed it or didn't understand it the first time.它被记录在语音历史中,这意味着如果他/她第一次错过或不理解该消息,用户可以重复该消息。 He/she also can copy the message text.他/她也可以复制消息文本。
  • The user can interrupt the message before its end (by pressing Ctrl), in case he/she finds it annoying用户可以在消息结束之前打断消息(按 Ctrl 键),以防他/她觉得烦人

None of the three are possible when using speech API:使用语音 API 时,这三个都不可能:

  • The message is spoken using voice settings that may come from unappropriate defaults, and certainly different from what the user has configured in the screen reader.使用可能来自不适当默认值的语音设置说出消息,并且肯定与用户在屏幕阅读器中配置的不同。 At best it's quite annoying, at worst the message is totally impossible to understand (the speech can be in the wrong language, way too fast or too slow for example).最好的情况是很烦人,最坏的情况是消息完全无法理解(语音可能是错误的语言,例如太快或太慢)。
  • You can't repeat, copy the text, or shut up the message您不能重复、复制文本或关闭消息
  • You may provide UI on your site to configure voice, language, rate, pitch, volume, etc. as well as handle Ctrl key to shut up and something else to repeat, but the user won't take the time to configure this kind of settings and/or learn how to use them on every site visited, so it's mostly useless您可以在您的站点上提供 UI 来配置语音、语言、速率、音调、音量等,以及处理 Ctrl 键以关闭和重复其他内容,但用户不会花时间配置此类设置和/或学习如何在访问的每个站点上使用它们,所以它几乎没用

In fact, use cases for each of the two are quite different:事实上,两者的用例都大不相同:

  • Use ARIA live regions, role alert, and other ARIA features of that kind when you need to communicate things specifically to screen readers, like in the present case with error messages.当您需要专门与屏幕阅读器进行交流时,例如在本例中使用错误消息,请使用 ARIA 实时区域、角色警报和其他 ARIA 功能。
  • Use speech API when speech is going to be used equally by all users, using a screen reader or not.当语音将被所有用户平等使用时,使用语音 API,无论是否使用屏幕阅读器。 You can think about a voice assistant or a GPS guide, for example.例如,您可以考虑语音助手或 GPS 指南。 IN this case you will typically provide ways to configure voice settings as well, because there it perfectly makes sense.在这种情况下,您通常还会提供配置语音设置的方法,因为这非常有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 睡眠时移动设备上的 window.speechSynthesis - window.speechSynthesis on mobile devices while asleep 带有角色警报的 IE11 JAWS 可访问性问题 - IE11 JAWS accessibility issue with role alert HTML 可访问性 combobox 角色 - HTML accessibility combobox role 在React中为Web可访问性切换aria压缩角色的最有效方法 - Most efficient way to toggle aria-pressed role in React for web accessibility 如何从 window.speechSynthesis.speak() 调用中捕获生成的音频? - How to capture generated audio from window.speechSynthesis.speak() call? window.speechSynthesis.getVoices() 在 macOS safari 15.4 上返回空数组 - window.speechSynthesis.getVoices() returns empty array on macOS safari 15.4 window.speechSynthesis.speak(msg) 在按钮单击之前不起作用 - window.speechSynthesis.speak(msg) not working until button click 显示模态窗口时,删除 tabindex = '-1' 属性是否也会影响 Web 可访问性? - Does deleting the tabindex = '-1' attribute also affect web accessibility when the modal window is shown? 视障用户的警报辅助功能开发 Javascript - Alert accessibility development for visually impaired users Javascript 在JavaScript中添加Web可访问性支持 - Adding Web Accessibility Support in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM