简体   繁体   English

如何使用 JavaScript 确定屏幕阅读器会读取什么内容?

[英]How can I determine with JavaScript what a screen reader would read?

I have a web application that is already accessible using iOS and Android devices, but I'm trying to make the same thing work on a device where there is no screen reader.我有一个已经可以使用 iOS 和 Android 设备访问的 Web 应用程序,但我正在尝试在没有屏幕阅读器的设备上进行相同的操作。 I have a solution in the form of an application shell that I can launch my web app within;我有一个应用程序外壳形式的解决方案,我可以在其中启动我的 Web 应用程序; the shell can navigate through/manipulate the elements just like Talk Back, without problem...effectively, I've already achieved accessibility for the mobility impaired using alternative screen manipulation devices. shell 可以像 Talk Back 一样导航/操作元素,没有问题......实际上,我已经使用替代屏幕操作设备为行动不便的人实现了可访问性。

I also need to support screen-readers, and what I don't know is whether there's a way (in JavaScript/Typescript) to retrieve what should be read for a given button.我还需要支持屏幕阅读器,我不知道是否有办法(在 JavaScript/Typescript 中)检索给定按钮应该读取的内容。 For example, if presented with an button titled "Next", I would like to retrieve the text "next, button" or something like it.例如,如果显示一个标题为“下一步”的按钮,我想检索文本“下一步,按钮”或类似的内容。

Is there a standard-based way to do this?有没有基于标准的方法来做到这一点? Alternatively, is there a third-party library that others have successfully used to solve a similar problem?或者,是否有其他人已成功使用第三方库来解决类似问题? Or am I destined to write my own?还是我注定要自己写?

To clarify: I have access to JAWS and NVDA and have validated my solution on both of them.澄清一下:我可以访问 JAWS 和 NVDA 并且已经在它们两个上验证了我的解决方案。

TL;DR: I am looking for a way for JavaScript to query an element and retrieve the content that would be spoke, not for my own edification, but so that I can pass the information that is being spoken to another tool of my own creation. TL;DR:我正在寻找一种让 JavaScript 查询元素并检索将要讲述的内容的方法,不是为了我自己的启迪,而是为了我可以将正在讲述的信息传递给我自己创建的另一个工具.

我认为最好的方法是实际安装/启用屏幕阅读器(例如,macOS 内置了一个),然后闭上眼睛自己听。

TL;DR: No Way TL; DR:没办法

Basically, you have no possibility to get a string spoken by a particular screen reader, neither can you determine whether a screen reader is launched at all.基本上,您无法获得特定屏幕阅读器朗读的字符串,您也无法确定屏幕阅读器是否已启动。
More than that, different screen readers convey information in different ways, and even moreover, a user can adjust his/her screen reader so it would say, following your example, next button , button next or just next (or play a sound instead of saying "Button").更重要的是,不同的屏幕阅读器以不同的方式传达信息,甚至此外,用户可以调整他/她的屏幕阅读器,因此可以说,下面的例子中,下一个按钮按钮旁边旁边(或播放声音,而不是说“按钮”)。 Thus, you have no real opportunity to get what you need, it seems.因此,您似乎没有真正的机会获得所需的东西。

What you're looking for is the accessible name computation .您正在寻找的是可访问的名称计算 Jump to section 4.3.1 “Terminology” and you'll find the algorithm step by step.跳转到第 4.3.1 节“术语”,您将逐步找到算法。

It's quite a mouthful.真是够口的。 I have yet to find a good open-source implementation of it.我还没有找到一个好的开源实现。 And even if you follow it correctly, you will find that established screen-reader software doesn't always.即使您正确地遵循它,您也会发现已建立的屏幕阅读器软件并不总是如此。

You could also wait until the Accessibility API (or the AOM Project ) gains wide support, and just utilize that, but who knows when that will happen.您也可以等到 Accessibility API(或AOM 项目)获得广泛支持,然后利用它,但谁知道什么时候会发生。

However, if you completely control the speech output, why not optimize the experience in collaboration with visually impaired users, instead of aiming for what the software would come up with?但是,如果您完全控制语音输出,为什么不与视障用户合作优化体验,而不是针对软件会提出什么?

Perhaps you could use Puppeteer's accessibility API to work out what the accessibility tree for a given node looks like.也许您可以使用Puppeteer 的可访问性 API来计算给定节点的可访问性树是什么样的。

The Accessibility class provides methods for inspecting Chromium's accessibility tree. Accessibility 类提供了检查 Chromium 的可访问性树的方法。 The accessibility tree is used by assistive technology such as screen readers or switches.辅助技术(例如屏幕阅读器或开关)使用可访问性树。

I'm not sure you can work out exactly the output for each screen readers but it may be worth a shot.我不确定您是否可以准确计算出每个屏幕阅读器的输出,但这可能值得一试。

暂无
暂无

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

相关问题 如何确定屏幕阅读器阅读文本的顺序? - How can I determine the order in which text is read by a screen reader? 如何:指导屏幕阅读器从代码中读出什么 - How to: Instruct a screen reader what to read out in code 如何让屏幕阅读器读出混合的文本和组件? - How can I make a screen reader read out a mix of text and components? 如何以屏幕阅读器仍会阅读文本并向用户指示已禁用的方式“禁用”单选按钮? - How to “disable” a radio button in a way that a screen reader would still read the text and indicate to a user that it is disabled? 在将按键事件应用于 DOM 之前,如何确定按键事件之后的值是什么? - How can I determine what a value would be after a keypress event BEFORE it is applied to the DOM? 我可以确定使用JavaScript单击的内容吗? - Can I determine what was clicked using JavaScript? 在屏幕阅读器可以使用JavaScript或CSS读取网站内容之前删除网站上的内容? - removing content on website before a screen reader can read it with either JavaScript or CSS…? 如何确定javascript数组中值> 0的最后一项的索引 - How would I determine the index of the last item in javascript array with a value > 0 如何通过屏幕阅读器读取输入然后标签? - How to read input then label via screen reader? 在 Spotfire Mods 中,作为阅读器的一部分,我可以确定数据视图中发生了什么变化吗? - In Spotfire Mods can I determine what has changed in the dataview as part of the reader?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM