Search code examples
javaaccessibility

How can I tell a screen reader to speak arbitrary text?


I am developing a game with swing and I would like to display some information when a key is pressed, for instance the health of the character. Is there a way in which a screen reader could read this information without moving the focus and therefore interrupting the game? Thank you in advance.


Solution

  • Using screen reader is better than separate TTS

    AS a blind person myself, I can effectively confirm that, it's better to make the screen reader speak rather than using a separate TTS engine. The advantages include:

    • Text is spoken using the voice already configured by the user
    • You are certain to never have the very annoying problem of two voices speaking at the same time (the screen reader and the TTS)

    When using a separate TTS engine, the voice used can dramatically differ from user settings, and in particular, can be speaking in the wrong language, far too slow, or far too fast.

    Make the screen reader speak on the web

    ON the web, making the screen reader speak some text is achieved with ARIA live region

    Make the screen reader speak in a desktop or native application

    For a desktop or native application, basically, there exist as many different API as there are screen readers. There is no common standard at all. You must detect the screen reader used if any, and then communicate with it using its specific API.

    Fortunately, there are library which helps you doing that:

    • I'm the author of one of them, UniversalSpeech (7 screen readers supported under windows only)
    • There exist another one, tolk (6 screen readers supported under windows only)
    • For python 3, you also have Accessible Output 2

    Note that several UI toolkits for desktop/native applications also implement something quite similar to ARIA live regions. If the text to be spoken has also to be displayed in the same time, you should preferably use that rather than libraries listed above. It is supported by all reasonably recent screen readers. Note that, ARIA live regions and similar systems are usually slightly slower than calling screen readers API directly though; it may be significant for a game.