\n This is the text that will be read aloud.\n
\n```\n\n## Better implementation tips\n\n### Split content into chunks\nLong text works better if you:\n- break it into sentences or paragraphs\n- queue utterances one by one\n- allow resuming from the last sentence\n\n### Handle voices and languages\n- Detect user locale\n- Offer voice selection\n- Support multilingual content if your app contains it\n\n### Support mobile platforms\nIf building native apps:\n- use system TTS\n- let users configure accessibility settings\n- test with VoiceOver and TalkBack\n\n### Avoid common pitfalls\n- Don’t read out hidden or irrelevant UI text\n- Don’t interrupt speech on minor UI changes\n- Don’t rely only on color or visual cues\n- Don’t assume text size is enough; read order matters\n\n## Recommended architecture\nA simple pattern:\n\n1. **Content extractor** gets readable text\n2. **Reading controller** manages current position, pause/resume/stop\n3. **TTS adapter** talks to platform speech APIs\n4. **UI layer** shows controls and current highlight\n5. **Accessibility layer** exposes proper labels and focus handling\n\n## If you want the best user experience\nAdd:\n- sentence-by-sentence navigation\n- “tap to read this paragraph”\n- adjustable reading speed\n- word highlighting\n- offline support if possible\n- remembered user preferences\n\nIf you want, I can give you:\n1. a **web implementation**, \n2. a **React component**, or \n3. a **native iOS/Android version**."}}}Prompt
How do I build a read-aloud mode for an accessibility feature?
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
To build a read-aloud accessibility mode, think in terms of capturing text, converting it to speech, and giving the user control over playback.
Core pieces
1. Identify the content to read
- Determine which UI text should be spoken:
- selected text
- current paragraph/article
- focused element
- page content
- Prefer a logical reading order, not raw DOM order if your layout is complex.
2. Use a text-to-speech engine
Common options:
- Web:
SpeechSynthesisAPI - iOS: AVSpeechSynthesizer
- Android: TextToSpeech
- Backend-generated audio: cloud TTS services like Amazon Polly, Google Cloud TTS, Azure TTS
For most app-side accessibility features, native device TTS is simplest.
3. Add playback controls
Users should be able to:
- play / pause
- stop
- skip forward/back
- change speed
- change voice, pitch, language
- see what is currently being read
4. Sync spoken text with highlighting
If possible:
- highlight the current sentence/word
- scroll content into view
- show a “reading cursor” This greatly improves usability.
5. Respect accessibility standards
- Support keyboard navigation
- Make controls screen-reader friendly
- Don’t auto-play speech unexpectedly
- Preserve focus and user control
- Provide captions/transcripts if audio is used elsewhere
Basic web example
If you’re building for the browser, you can start with the Web Speech API:
<button onclick="speakText()">Read Aloud</button>
<button onclick="pauseSpeech()">Pause</button>
<button onclick="resumeSpeech()">Resume</button>
<button onclick="stopSpeech()">Stop</button>
<script>
let utterance;
function speakText() {
const text = document.getElementById("content").innerText;
utterance = new SpeechSynthesisUtterance(text);
utterance.lang = "en-US";
utterance.rate = 1;
speechSynthesis.speak(utterance);
}
function pauseSpeech() {
speechSynthesis.pause();
}
function resumeSpeech() {
speechSynthesis.resume();
}
function stopSpeech() {
speechSynthesis.cancel();
}
</script>
<div id="content">
This is the text that will be read aloud.
</div>
Better implementation tips
Split content into chunks
Long text works better if you:
- break it into sentences or paragraphs
- queue utterances one by one
- allow resuming from the last sentence
Handle voices and languages
- Detect user locale
- Offer voice selection
- Support multilingual content if your app contains it
Support mobile platforms
If building native apps:
- use system TTS
- let users configure accessibility settings
- test with VoiceOver and TalkBack
Avoid common pitfalls
- Don’t read out hidden or irrelevant UI text
- Don’t interrupt speech on minor UI changes
- Don’t rely only on color or visual cues
- Don’t assume text size is enough; read order matters
Recommended architecture
A simple pattern:
- Content extractor gets readable text
- Reading controller manages current position, pause/resume/stop
- TTS adapter talks to platform speech APIs
- UI layer shows controls and current highlight
- Accessibility layer exposes proper labels and focus handling
If you want the best user experience
Add:
- sentence-by-sentence navigation
- “tap to read this paragraph”
- adjustable reading speed
- word highlighting
- offline support if possible
- remembered user preferences
If you want, I can give you:
- a web implementation,
- a React component, or
- a native iOS/Android version.