A Little Background..
I've been building Oracle APEX applications for a while now, and one thing I kept noticing was a common user behaviour - long content like Terms & Conditions, Privacy Policies, or Company Guidelines just gets skipped. People scroll past it, click "I Agree" without reading a single word, and move on. Honestly, I'm guilty of that too.
One day it just clicked - what if the page could read it out for them? They could listen while doing something else, and actually get through the content. I started digging into the browser's built-in Web Speech API and was honestly surprised by how capable it is, right out of the box - no external libraries, no paid plugins, nothing.
So in this blog, I'm going to show you exactly how I implemented a full Read Aloud feature in Oracle APEX with word-level highlighting, a pause/resume toggle, stop button, and a speed selector. I've used a Privacy Policy section as the example content. Let's get into it.
๐ฏ What you'll build: A static content region with a styled player bar - Play, Pause/Resume, and Stop buttons with speed control. As the text is read, each word gets highlighted in real-time. Everything is built with Oracle APEX's native tools and vanilla JavaScript using the browser's SpeechSynthesis API.
Create the Static Content Region
In your APEX page, create a Static Content region and give it a Static ID of policy-region. Paste the following HTML into the region source. This is the content that will be read aloud - you can replace it with your own policy text.
๐ก Note: The id="readAloudContent" on the outer div is important - the JavaScript uses it to locate and wrap the text for word highlighting.
Create the Player Controls Sub-Region
Under the region you just created (policy-region), create a Sub Region. In its Template options, set the template to Blank with Attributes so no extra wrappers interfere. Then paste the player HTML below into its source.
Add the CSS - Page Level Inline CSS
Go to your APEX page's CSS → Inline section and paste the styles below. This gives the player bar its dark blue look, styles the buttons, dropdown, and the word-highlight effect. The .ra-highlight class is what flashes on each word as it's read.
Add the JavaScript
Navigate to the page's JavaScript → Function and Global Variable Declaration section. Paste the full script below. This is where all the logic lives - wrapping words in spans, tracking character position, highlighting, managing states, and handling pause/resume accurately.
One thing that tripped me up initially was the pause behaviour. The Web Speech API doesn't support true pause across all browsers, so the trick here is to cancel the utterance (which stops audio immediately), save the last character index, then restart from that position on resume. The raPausing flag prevents the onend event from firing incorrectly when we cancel for a pause.
๐ง How It All Works - A Quick Breakdown
Word Wrapping
raWrapWords() walks through the HTML and wraps each word in a <span> with a unique index. This lets us target individual words for highlighting.
Boundary Events
The onboundary event fires on every word. We use the charIndex it gives us to match back to the correct span and apply the highlight class.
Pause Trick
Since true pause isn't reliable cross-browser, we cancel the utterance (stops audio), freeze the last charIndex, then restart from that position on resume.
Global Scope Fix
APEX wraps JS in its own scope. That's why we explicitly assign functions to window.raPlay etc., so the inline onclick handlers in the HTML can find them.
Try It Yourself
See the live demo running on Oracle APEX, or grab the full source code on GitHub.
๐ฌ Final Thoughts
What I love most about this feature is that it's entirely browser-native - no external API calls, no billing, no plugins to maintain. The Web Speech API has been around for a while and is supported in all major modern browsers, which makes it a surprisingly reliable tool for APEX applications.
From a user experience perspective, this small addition can make a real difference - especially for users who are multitasking, have reading difficulties, or just prefer consuming content through audio. I've had users genuinely thank me for this in one of my projects, which was a nice moment.
If you found this useful, drop a comment below or share it with your APEX community. Happy building! ๐
Comments
Post a Comment