Read-Aloud active/running flag/variable

  1. 6 years ago

    I have been creating a epub with PubCoder, which is working great, thanks.

    I have a question about using the Read-Aloud feature.

    Is there anyway, through Javascript, to identify that the Read-Aloud feature is active/running? (a variable maybe?) when you open/load a page?


    Rob Waterman

  2. Angelo S

    21 Feb 2018 Administrator

    Hello Rob,
    read aloud playback on EPUB is totally managed by the reader application, natively. Checking the rad aloud status is not part of the EPUB standard, therefore there's no way (I'm aware of) to check if read aloud is playing or not.

  3. Thanks Angelo

    The only way I figured out to check, is by watching the CSS changes using the following Javascript:

    /* ==========================================*/
    // Add this Javascript script to 'Load' event of a hidden button

    var triggerWord = 'word30'; // CSS class name of the trigger word to watch in the read-aloud text
    var triggerObject = $("#obj3689"); // ID of object that has the script that is triggered (hidden button)
    var triggerEvent = 'TouchDown'; // The event that triggers the script in 'triggerObject' (hidden button)

    // The 'triggerEvent' (TouchDown) of the 'triggerObject' can be added to the same hidden button as 'Load'

    /* ==========================================*/

    var observeWord = document.getElementById(triggerWord);

    // Generate the observers:
    // ---- observer ----
    var observer = new MutationObserver(function(mutations){
    if ($( "#"+triggerWord ).hasClass( "-epub-media-overlay-active" )){

    /* ==========================================*/

    // Start observing:
    observer.observe(observeWord, {attributes: true});

    FYI: I don't know if this will work on all devices.

    Regards, Rob W.

  4. Paolo A

    23 Feb 2018 Administrator

    Hi Rob,

    I have implemented a similar custom feature, the MutationObserver is the correct way. Will try to figure out how to bring this in PubCoder's native features.

  5. Angelo S

    23 Feb 2018 Administrator

    Yep, that's a way to check if read aloud is active on a certain word/block. I thought you were searching for a consistent way of knowing if the read aloud is playing at all (there's not always an "active" block)

  6. Hi Angelo,

    Yes I was/am looking for a consistent way of knowing if the read aloud is playing.

    The programming I did above was a "poor mans" way of doing it. If I test the first word(s) and have it trigger an action. i.e image switch on a button.

    Again, thanks for you help.

    - Rob W -


or Sign Up to reply!