I want to detect whether a screen reader is running on a user's machine to avoid sound clashing with audio tag in html. If so, please provide details on how this could be done.
The short answer is that you can't. At the time of writing there isn't a way to reliably detect whether someone visiting your site is using a screen reader (or screen magnifier). You might have heard that Flash will do the trick, but that might not be quite the solution you're expecting.
They don't parse the HTML directly but an accessible tree view of a document. This means that if your browser understands javascript, your screenreader will. That because, your screen reader will not access the DOM directly on the load of the page, but will interact with the Accessibility API provided by your browser.
The most obvious way to test for screen reader compatibility is by using screen reader software to navigate your digital content and run through the key user flows to fully understand the experience. However, using a screen reader like JAWS for testing requires knowing how to use it properly.
A screen reader is a software application that interprets things on the screen (text, images, links, and so on) and converts these to a format that visually impaired people are able to consume and interact with.
You should probably not try to do anything special even if you could detect that a screenreader is running. Even if you get it right for one group of screenreader users, you may get it wrong for another group. It's best to concentrate on writing good clean HTML5 in the first place.
Note that not all screenreader users use text-to-speech; many use braille output. Additionally, other types of accessibility tools - such as content highlighters and voice input apps - use the same techniques and APIs (eg. DOM, MSAA) that screenreaders do, so any technique that "detects a screenreader" will likely detect these also - so you cannot assume that it means that the user is fully blind and using only speech.
As things currently stand, the audio tag is currently not universally accessible, different browsers have different levels of accessibility support - see HTML5 Accessibility and scroll down to audio for more details of current support. I've seen some pages that add HTML5-based controls plus javascript after the audio tag so they can provide their own UI to ensure that keyboard or screenreader users can play/stop the audio as needed. (Eventually, when browsers catch up, this should not be needed.)
As far as general accessibility goes, WCAG 2.0 (Web Content Accessibility Guidelines) recommends that any audio that plays automatically for more than 3 seconds should have an accessible means to pause or stop the audio. (I'd go even further and recommend against using any automatic audio - when using tabbed browsing, it's often impossible to determine which tab the audio is coming from.)
While likely not a fully reliable way, a screen reader's progress can be detected via javascript using the focus event, as the user skim though content.
A hidden "skip navigation link" (http://webaim.org/techniques/skipnav/) should it be focused, would be one way to detect whether someone is using a screenreader.
Even though it doesn't address the audio part of the question, I just wanted to provide this partial solution, as I was looking for possible ways to detect screen-readers myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With