Skip to main content
BeyondWords can usually detect content segments on your page automatically. When segment detection is working correctly, the following widget features can be turned on in Widget → Audio, in the Immersion reading card (needs Article turned on), without any additional integration:
  • Playback from paragraphs: Allow users to click or tap a paragraph to begin playback from that point.
  • Word highlighting: Highlight individual words as they are spoken, creating an immersion reading experience.
  • Paragraph highlighting: Highlight the paragraph currently being read aloud, helping users follow along with the audio.
In some cases, however, the structure of your website or app may prevent the widget from detecting segments correctly. The following sections explain how to implement segment detection manually for JavaScript, iOS, and Android.

JavaScript

If you’re using the JavaScript widget and segment detection isn’t working properly, you can add markers to elements on your page to improve detection accuracy:

Markers

If you add markers manually, we recommend using randomly generated UUIDs. Markers must be stable and should not change between page refreshes.
  • If you’re using the client-side integration, markers will be automatically retrieved from your page when content is processed.
  • If you’re sending HTML to the BeyondWords API, markers will be automatically extracted from the HTML when content is processed.
  • If you’re sending plaintext to the BeyondWords API, you will need to set the marker attribute on each segment alongside the text.
If a segment marker isn’t provided, BeyondWords will generate one for you. You can retrieve these from the Get content endpoint (use ?segments=full) and add them to the HTML of your article. We recommend generating UUIDs as markers to avoid duplicates, in case there are multiple widgets on the same page.

How it works

Once the widget script has loaded, it adds global listeners to your page to detect click and mousemove events. When a user hovers over or clicks on an element, the widget attempts to match that element against segments using markers (see above), xpath, or an MD5 fingerprint of the text content. If a match is found, the widget emits HoveredSegmentUpdated and PressedSegment events. Additionally, when the currentTime of the media updates (e.g., during playback), the widget emits a CurrentSegmentUpdated event. These events are used to highlight segments on the page and control playback, for example, by setting currentTime to the startTime of the segment the user clicked on. The currentSegment and hoveredSegment properties of the widget are also updated accordingly. To highlight segments, the widget wraps the segment content in a <mark> element with custom styles. The mark is removed once highlighting ends. To avoid interfering with your page, highlighting and click handling are disabled when hovering over a link or an element with a click or mousedown handler. This doesn’t apply to event listeners (see below).

Event listeners

The widget can’t detect event listeners registered on elements within a segment. For example, the button below doesn’t have an onclick property, so playback will be affected when it is clicked:
To prevent this, call event.preventDefault() at the top of the event listener:
This will prevent the widget from changing its current time when the button is clicked.

Configuration

Playback from paragraphs can be configured using the following widget properties:

Mobile SDKs

The mobile SDK implementations are based on the JavaScript version above. Unlike the JavaScript widget, the mobile SDKs can’t automatically identify segments, so you’ll need to manually link each text segment to its BeyondWords marker.
You can find a full example of playback from paragraphs integration in the Android GitHub repository:

Highlighting the current segment

Listen for the CurrentSegmentUpdated event, then find the corresponding UI element and apply your desired styling:

Handling segment clicks

Set a View.OnClickListener and call setCurrentSegment with the corresponding marker: