Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

ReadAloud

A player that reads a region of the page aloud, one sentence at a time, with the browser’s own speech. ReadAloud reads a page's text aloud, sentence by sentence, and shows which sentence in words. It is not a substitute for a screen reader (software that reads the whole screen aloud), and it never starts by itself.

Package
@kvirn-ui/react
Pattern
APG Button (for the buttons), APG Toolbar (for the Bar's transport)
Testing
Planning. Automated 0 of 5, Core 0 of 2, Release 0 of 3

When to use it#

  • Offer it on text people may prefer to hear: a long guidance page, a decision letter, a notice. It helps someone with dyslexia, low literacy or a cognitive disability, a reader using their second language, a visitor with low vision, or anyone who is tired or doing something else at the same time.
  • It is not aimed at screen-reader users: they already have a better reader, and ReadAloud must never fight it. Offer it to everyone and never hide it from assistive technology (software that people with disabilities use, such as a screen reader).
  • There are two ways to offer it. The panel sits beside one article, with full-word buttons (Listen, Previous sentence, Next sentence, Stop): add one wherever you have a long text. The ReadAloud.Bar sits once in your page layout and reads whichever page the visitor is on, with Previous, Next, Stop and Settings as icons and the word kept on Play: choose it for listening everywhere without adding anything to each page. Both share one Settings menu for speed and voice.
  • Put the panel directly before the text it reads, in the normal flow of the page — never floating, never in a menu. The bar is different: it sits at the top of every page, above the site’s own navigation, and only becomes sticky while it is reading, so it never covers anything before a visitor has pressed anything. Neither player starts by itself.
  • Listen reads the whole text, or only the text the reader has selected (select with Shift and the arrow keys, then press Listen). Pause and Stop control it, and Previous and Next move one sentence at a time.
  • Pressing Listen sends that page's text to Kvirn's voice service, which turns it into speech. The service is Kvirn's own, hosted in the EU, sets no cookies and, by default, does not save the text or the audio — unless you opt in with store: true, which is only for public page text, never for anything that could contain an identity number. The player's recipient sentence changes its own wording to match. Nothing is sent before the reader presses Listen. Each player already tells the visitor who receives the text — the Note part in the panel, or the Settings menu in the bar — but linking your own explanation of how listening works, and naming the service in your privacy notice, is still your own job.
  • Today the service has voices for Swedish, Norwegian (Bokmål) and English only. A page in Finnish or Norwegian Nynorsk gets no player at all, not even for a moment: the check happens before anything is shown, so nothing flashes on screen.
  • The voice always follows the text's own declared language, never the page's interface language. A Finnish municipality can run a Finnish interface around Swedish-language content, and it still reads in Swedish.
  • It is not for announcing a change in the page. Use the Announcer for that.

Example#

Press Listen to hear the article. Previous and Next move one sentence; Speed changes how fast it is read, without a new request. If the voice service isn’t running (it reads the address from an environment variable, and uses a local address during development), Status says it can’t be reached right now, rather than the button doing nothing.

Listening sends this text to Kvirn’s voice service to make the audio. The text and the audio are not saved. How listening works

Applying for a building permit

You apply for a building permit in the municipality where the building will stand. Start with the property designation and a short description of the work. Attach a site plan.

The case officer reviews the application within ten weeks. If something is missing you are told what, and the time stops until you reply.

Use cases#

A quiet panel that only shows controls once you start listening

At rest, show only Listen. A row of controls that do nothing yet — a disabled Previous and Next, an empty progress bar — can look broken. Wrap the rest in ReadAloud.WhenStarted: it appears once you press Listen, in the same place, so the button under your finger does not move, and it never collapses back once reading has started.

Listening sends this text to Kvirn’s voice service to make the audio. The text and the audio are not saved. How listening works

How winter parking rules work

From 1 December to 31 March, parking on odd dates is allowed on the odd side of the street, and on even dates on the even side, so snow ploughs can get through. Move your car by 8 a.m.

A listening bar for the whole site

Add ReadAloud.Bar once in your page layout, with a scope selector, instead of placing a player on every page. It reads whichever part of the page matches that selector, sits above the site’s own navigation, and only becomes sticky while it is reading.

Road closed for water main repairs

Elm Street is closed to through traffic from 3 to 14 November while the water main is replaced. Buses use the marked diversion. Residents on Elm Street keep access to their driveways.

Props in this example:

Marking which part of a CMS page to read

A content management system renders its own HTML, where React cannot write a comment. Wrap the part a resident should hear in <!-- KV:READ-ALOUD:START --> and <!-- KV:READ-ALOUD:STOP -->, so the player skips things like a related-links box around it.

Listening sends this text to Kvirn’s voice service to make the audio. The text and the audio are not saved. How listening works

Your case decision

The municipality has decided to grant your application for a disabled parking permit.

The permit is valid for three years and is sent to your registered address.

Props in this example:

Information: Did you know?

Most HTML minifiers strip comments by default. Keep comments on in production, or the markers disappear and the player reads everything instead.

Content in a different language from the interface

The voice follows the text’s own declared language, never the page’s interface language. Here the page is in English, but the decision it quotes keeps its original Swedish wording: Listen reads that part in Swedish. In English, the quoted text says “The decision becomes final three weeks after it is announced.”

The original wording of a decision

This page is in English, but the decision itself is kept in the language it was issued in. In English, it says: “The decision becomes final three weeks after it is announced.”

Beslutet vinner laga kraft tre veckor efter att det har kungjorts.

Warning: Don't forget

Put lang on the content itself, not only on the page. Without it, this part would be read with whatever language the page declares (3.1.2 Language of Parts, level AA).

Accessibility#

What it does for you#

  • APG pattern: none for the group. Buttons follow Button, the naming practice for media buttons such as Play and Pause. ReadAloud.Bar's transport follows Toolbar: one Tab stop with roving tabindex, arrows between the items.
  • Deviations: none from the APG. Previous, Next and Stop stay focusable while unavailable (aria-disabled) while idle, so their names can be found and the keyboard path doesn't jump.
  • Native elements used: <button type="button">, <select> with a <label>, a plain <span> for the status, a plain <p> for the privacy note. Bar is a plain <div>, no role of its own, around a Toolbar.Root (role="toolbar"); Settings is a Popover (role="dialog"); Hide is a <button>; WhenStarted renders no element of its own, a Fragment.

ReadAloud reads a region of the page aloud for people who benefit from hearing it, using Kvirn's own voice service. It is not a screen reader substitute and never starts by itself.

PartElement / roleARIANotes
Root<div> → grouparia-label = readAloud.labeldata-status (idle, preparing, playing, paused), data-error (one of the five below, while an error is current), data-source (content, selection), data-kv-read-aloud-skip (its own words are never read). Renders nothing once hasVoice is false: no voice for the resolved content language, or no engine configured at all
Progress<p>, decorativearia-hidden="true"The sentence meter. No progressbar or slider role, no handle, not focusable, no hover or pointer behaviour: position is only ever in words, in Status. Renders nothing while status is idle, since nothing has been read yet
Play<button> → buttonnonedata-playing while reading; data-busy once a wait (first chunk or a later one) has passed 300 ms. Never disabled: it is the way to cancel the wait. Pause is real: pressing it while paused resumes the same point, never restarting the sentence. Its icon (play/pause/a spinner) and its three possible words are each aria-hidden except the active one, so the name is always exactly the one visible word (2.5.3)
Previous<button>aria-disabled="true" while idleDecorative skip-previous icon before the word. Focusable, activation blocked
Next<button>aria-disabled="true" while idleDecorative skip-next icon before the word. As Previous
Stop<button>aria-disabled="true" while idleDecorative stop icon before the word. As Previous. Reachable during preparing, so a slow service can always be cancelled
Transport<div>nonePurely structural: groups Previous and Next in the markup so the cluster, its gap and Stop's separation survive a consumer reordering parts. Adds no Tab stop and no role
Rate<select> → comboboxvisible <label>Options 0.75× … 2×, formatted with the provider locale
Voice<select> → comboboxvisible <label>Only voices for the content language. Not rendered with fewer than two. Not part of the default composition: the list is fetched lazily, on the first press or (B4, Plan 0154) as soon as ReadAloud.Voice itself mounts, never eagerly on Root mount (rule 7). Only en currently has a real choice
Note<p>noneThe privacy affordance: names who receives the text, with an optional link. Says nothing is stored (readAloud.note), or that the audio may be (readAloud.noteStored, B5) when the engine's stores is true — never the false sentence regardless of configuration. Renders nothing without name. No consent gate: nothing leaves the browser before Play is pressed regardless
SelectionTrigger<button> → buttonpopover="manual", tabindex="-1", not aria-hiddenPointer-only convenience. Name and text readAloud.playSelection. Shown below the end of a selection finished with a pointer; never after a keyboard selection. Never takes focus: pointerdown is prevented, so the selection survives. Dismissed on collapse, any key (Escape included), scroll, resize, Stop and use
Status<span>role="status" with aria-live="off": findable, silentSentence {current} of {total} while reading, Paused at sentence {current} of {total}, Getting the audio… once a wait is visible, One part of the text was skipped after a skip, There is nothing here to read aloud after a press with nothing resolved (B3), or the current error's text. data-error carries the cause for the five machine errors; the no-content notice is a hook-level state, not a machine error, and sets no data-error
Bar<div>, no rolenone of its ownReadAloud.Bar: a plain grouping <div>, nested inside Root's own role="group". One group, not two: while a Bar is mounted, Root's aria-label reads readAloud.barLabel instead of readAloud.label. Carries no lede and no meter; the Status reused inside it (the "count", kv-read-aloud-count) is empty while idle and reads the position while playing, same text as the panel's. Static by default; a theme may make it sticky only while data-status is not idle
Toolbar<div> (Toolbar.Root) → toolbararia-label = readAloud.toolbarLabelReadAloud.Bar's default composition only (kv-toolbar kv-read-aloud-toolbar): Previous, Play, Next, Stop and Settings as one Tab stop with roving tabindex. Its own name, distinct from the group's readAloud.barLabel and from readAloud.label, so entering it does not repeat a phrase a screen reader already read on the way in
SettingsPopover.Trigger → button, Popover.Popup → dialogaria-haspopup="dialog", aria-expanded; the popup's aria-label = readAloud.settingsReadAloud.Settings: Speed, Voice, then the recipient sentence (readAloud.note, or readAloud.noteStored with store: true, shown whenever name is known) and, only with a howItWorksHref prop, the readAloud.howItWorks link — shared by the Bar and the panel, one implementation, rendered at either call site. The trigger's name comes from a visible, i18n label span next to the icon, like every other Bar control, not aria-label — so the --words choice class, which only reveals visually hidden text, reaches it too. Never modal, never covers Pause, Previous, Next or Stop (2.2.2)
Hide<button>aria-label = readAloud.hideReadAloud.Bar only. Renders nothing once status is not idle: hiding the only Pause while audio runs would break 2.2.2. Collapses the Bar to one Play button for the rest of the page view (no storage) and moves focus there; nothing is announced
WhenStartednone, a FragmentnoneRenders children once hasEverPlayed is true, else nothing. Reads the Root it is mounted in through context, so the idle-panel composition stays one machine. Adds no element and no Tab stop of its own

Read aloud#

State or actionExpected phrase(s) as read aloudLive region politenessPlanned test (not yet written)
Idle, read top to bottomgroup, Listen to this text → button, Listen → button, Stop, disabled → button, Listening settings → the contentnoneread-aloud.test.tsx › read aloud › idle reading order: the group, Listen, Stop disabled, Settings, then the content
Play pressed, a slow first chunkbutton, Pause, then, once preparing has shown for 1 second, polite: Getting the audio… (once per press, never once per sentence)politeread-aloud.test.tsx › read aloud › a slow first chunk announces "Getting the audio…" once, past one second
Buffering mid-readingnothing: a later chunk still loading never re-announces preparingnoneread-aloud.test.tsx › read aloud › buffering mid-reading announces nothing
Play pressed, then pausedbutton, Listen → button, Pause + Sentence 1 of 2 → button, Listen + Paused at sentence 1 of 2noneread-aloud.test.tsx › read aloud › the Play name reads Listen, then Pause, then Listen after pause
A selection is capturedbutton, Listen to selected textnoneread-aloud.test.tsx › read aloud › the Play name reads Listen to selected text while a selection is captured
No voice for the content's languagepolite: There is no voice for Finnish yet, so this page can't be read aloud.politeread-aloud.test.tsx › read aloud › no voice is announced politely, naming the content's language
The voice service is busypolite: The listening service is busy. Press Listen to try again.politeread-aloud.test.tsx › read aloud › a busy service is announced politely, after its one retry
The voice service is unavailablepolite: The text can't be read aloud right now. Press Listen to try again, or read on.politeread-aloud.test.tsx › read aloud › a service failure is announced politely
The browser couldn't play the audiopolite: This browser couldn't play the audio.politeread-aloud.test.tsx › read aloud › a playback error is announced politely
A part of the text is skippednothing: One part of the text was skipped is shown in Status, never announced, and stays shown until Stop (not a few seconds), so a listener who kept going can still find itnoneread-aloud.test.tsx › read aloud › a skipped part is shown until Stop but never announced
Play, pause, next, stop, endnothingnoneread-aloud.test.tsx › read aloud › play, pause and stop announce nothing
Bar, idle, read top to bottomgroup, Listen to this page → toolbar, Playback controls → button, Previous sentence, disabled → button, Listen → button, Next sentence, disabled → button, Stop, disabled → button, Listening settings → button, Hide the listening barnoneread-aloud.test.tsx › bar read aloud › idle reading order through the toolbar and Hide
Bar, Settings openeddialog, Listening settings → the Speed select's name and value → the recipient sentencenoneread-aloud.test.tsx › bar read aloud › Settings announces the popup, Speed and the recipient sentence
Bar, Hide pressednothing: focus moves silently to the one remaining Play buttonnoneread-aloud.test.tsx › bar read aloud › Hide announces nothing

Other texts: Speed and Voice labels (readAloud.rate, readAloud.voice), the speed options (readAloud.rateOption, 1.5×), the Note text (readAloud.note) and its howItWorks link, read in the normal reading order like any other static text — not announced.

The phrases are the approximation of a virtual screen reader (software that imitates one for tests), not NVDA or JAWS wording.

The "no voice" row above and Root's own "renders nothing once hasVoice is false" (Roles table) are two different moments, not a contradiction: hasVoice is resolved synchronously at mount from the engine's own voice map (D14), so a language with no voice at all (fi, nn) never renders a player, not even briefly — there is nothing to announce because there is no group to read. The polite "no voice" announcement fires later, during an already-mounted, already-reading session, when a chunk's own resolved voice turns out missing once the real voice list has loaded (error: 'no-voice') — the player is already on screen, so the state is announced in place instead of the player vanishing under the resident.

What you need to do#

  • Set lang on the content, not just the page: the voice follows the content's own declared language, never the UI's locale (3.1.2). Offer the player to everyone: don't auto-start and don't hide it from assistive technology.
  • Give the engine a url (directly, or once via <KvirnProvider readAloud>) and a name: Note and Settings both need it to tell residents who the text is sent to.
  • Wrap the app in KvirnProvider: errors are announced through it.
  • Mark what must not be read with data-kv-read-aloud-skip.
  • ReadAloud.Bar only: without contentRef, it reads scope (a CSS selector) if given, else the page's <main>. ` / ` HTML comment pairs inside that root narrow it further; they are for server-rendered and CMS markup, since React/JSX cannot emit a comment, and an HTML minifier that strips comments removes them with it.
  • The disclosure's destination page is yours. ReadAloud.Settings's howItWorksHref and ReadAloud.Note's own both link to a page you write, explaining that listening sends the text to your chosen service. The library names no URL and does none of this for you: with no howItWorksHref, there is no link and no dev warning — only the recipient sentence, which already names who receives the text, but a site that sends text to a third-party voice service should still link its own explanation, most usefully from the Bar's Settings, since a Bar composes no standalone Note.

Warning: Don't forget

Wrap your app in a KvirnProvider. The player announces its errors through it. Without it, a screen reader user hears nothing when reading stops (4.1.3 Status Messages, level AA).

Visual and modes#

Headless: no CSS. Classes kv-read-aloud, kv-read-aloud-progress, kv-read-aloud-progress-fill, kv-read-aloud-button, kv-read-aloud-play, kv-read-aloud-button-label, kv-read-aloud-transport, kv-read-aloud-previous, kv-read-aloud-next, kv-read-aloud-stop, kv-read-aloud-select, kv-read-aloud-label, kv-read-aloud-status, kv-read-aloud-note, kv-read-aloud-selection-trigger, kv-read-aloud-bar, kv-read-aloud-toolbar, kv-read-aloud-count, kv-read-aloud-settings, kv-read-aloud-settings-popup, kv-read-aloud-hide, the choice classes kv-read-aloud--icons and kv-read-aloud--words, both on Root (hybrid, with the word on Play/Pause only, is the default with no class), and the highlight ::highlight(kv-read-aloud) are for the theme. The highlight is not the only cue: Status shows the sentence position, and a data-busy/data-error icon on Status, in text colour, backs up the spinner and the error text (1.4.1 Use of Color, level A). The meter is the same: decorative length, never the only position cue, since Status already carries the words. Every icon-only control in the Bar still carries its name from i18n in the button's own text (visually hidden by the choice class, not aria-hidden), so its accessible name never depends on the class.

  • Focus indicator: the Button's (data-focus-visible); the selects use the browser's focus ring.
  • Target size: buttons and selects are native controls at least 24 × 24 CSS px (2.5.8 Target Size (Minimum), level AA), set by the theme.
  • Forced colours: ::highlight maps to Highlight/HighlightText; Status is the position cue either way.
  • Reduced motion: the sentence scrolls into view only when it is out of view and prefers-reduced-motion is not set; the preparing spinner animation is suppressed (the theme's job).

Information: Did you know?

The default theme styles the player but not the sentence highlight. Where the browser supports it (the CSS Custom Highlight API), the sentence being read is registered as ::highlight(kv-read-aloud), and nothing paints it until you add that style. Where the browser doesn't, or you add no style, the Status text is the only cue to which sentence is playing.

Focus management#

  • Initial focus: not moved. Focus never leaves the control that was used, including after stop and at the end of the content.
  • Trap: no. Restore to: not applicable.
  • Never obscured by: the panel composition is in the page flow and never sticky. ReadAloud.Bar is the one exception: static by default, a theme rule may make it sticky only while data-status is not idle; it un-sticks at (max-height: 30rem) instead of covering a focused element, and the consumer sets scroll-padding-block-start to its height. The selection trigger is placed below the selection, beside it when there is no room, and never over the selected text (2.4.11 Focus Not Obscured (Minimum), level AA).
  • Hide: on press, focus moves to the one remaining Play button in the same place, so it is never lost to the page.
  • SelectionTrigger: never takes focus. Any key, Tab included, dismisses it before focus moves, so it never covers a focused element (2.4.11 Focus Not Obscured (Minimum) (AA)). It is not in the Tab order, and it is not hidden from assistive technology. The identical action, and the whole keyboard path, is Play.
  • Selection: a selection made in the content is captured, so Tab to Play doesn't lose it. Reading it collapses the selection.

Allowed elements#

A tag outside the list changes the page's outline or semantics (1.3.1 Info and Relationships, level A; 4.1.2 Name, Role, Value, level A). as is a string, so it works from a Server Component.

Part`as`Why
Statusspan (default), p, divVisible text of the position or the reason nothing is read, with role="status" and aria-live="off" kept. A value outside the list is a type error and, in plain JavaScript, warns once and renders the default element.
Root, Progress, Play, Transport, Previous, Next, Stop, Rate, Voice, Note, SelectionTrigger, Bar, Settings, Hide, WhenStartednoneA role="group" <div>, native <button>s, <select>s, a plain <p> (Progress, Note) and a plain <div> (Transport, Bar), a Toolbar, a Popover, and a Fragment (WhenStarted): no other element keeps the keyboard and name contract (4.1.2 Name, Role, Value, level A)

WCAG success criteria#

  • 2.2.2 Pause, Stop, Hide (A) and 1.4.2 Audio Control (A) do not apply: speech and the highlight start only when the user presses Play. Pause and Stop are offered anyway, reachable during preparing too, and the highlight is cleared on stop and unmount.
  • 2.1.1 Keyboard (A): every control works from the keyboard.
  • 2.4.11 Focus Not Obscured (Minimum) (AA): the SelectionTrigger never takes focus and any key dismisses it before focus moves.
  • 3.1.1 Language of Page (A) and 3.1.2 Language of Parts (AA): each chunk is spoken with a voice for its own lang, never another language's and never the UI's locale. Unmarked text takes the closest [lang] above it, then the provider's locale, then en; an inner lang attribute wins. A chunk with no voice either stops the reading (the content's own language) with a message naming it, or is skipped and read past (an inline, differently-languaged chunk, D10).
  • 4.1.2 Name, Role, Value (A): the controls have names and roles, and axe finds no violation.
  • 4.1.3 Status Messages (AA): preparing (once per press), the five errors, and nothing per sentence or per skip.
  • 3.3.1 Error Identification (A): each error says what happened and, where there is one, what to do next (errorServiceBusy, errorNoVoice, errorNoContent).
  • 2.5.8 Target Size (Minimum) (AA), 1.4.11 Non-text Contrast (AA): the default theme's job, including the Bar's icon-only controls.
  • 2.4.3 Focus Order (A): ReadAloud.Bar's toolbar keeps the bar at 2–3 Tab stops (toolbar, Settings' popup once open, Hide while idle) ahead of the page's own navigation, which a worded five-button bar would not be.
  • 3.3.1 Error Identification (A), applied to scope: a selector or a missing <main> that leaves nothing to read is shown and announced to the resident (readAloud.errorNoContent), not just a development-only warning (B3, Plan 0154) — the dev console.warn still fires too, for whoever wired scope.

Keyboard#

Focus
native in the panel; roving tabindex inside ReadAloud.Bar's toolbar
Selection follows focus
n/a
Arrows wrap
yes, inside the Bar's toolbar (APG Toolbar default)
Shortcuts
none

Native controls in DOM order, no tabindex, in the panel. Note is static text, never a Tab stop. Progress (aria-hidden) and Transport (a structural grouping element) add no Tab stop either. Inside ReadAloud.Bar's toolbar, Previous, Play, Next, Stop and Settings are one Tab stop: the last-focused item (or the first, before any has) carries tabindex="0", the rest -1, and the arrows move the roving stop between them (the Toolbar part has its own keyboard contract; the rows below are this component's).

KeyWhereWhat happens
TabPlayerMoves through Play, Stop, Settings (the default button row, D44)
Planned test: read-aloud.test.tsx › keyboard › Tab moves through Play, Stop and Settings
Shift+TabPlayerMoves to the previous control
Planned test: read-aloud.test.tsx › keyboard › Shift+Tab moves focus back to the previous control
EnterPlayReads. Focus stays on Play
Planned test: read-aloud.test.tsx › keyboard › Enter on Play starts reading and keeps focus
SpacePlayReads. Focus stays on Play
Planned test: read-aloud.test.tsx › keyboard › Space on Play starts reading and keeps focus
EscapeInside the playerStops reading. Focus stays where it is
Planned test: read-aloud.test.tsx › keyboard › Escape inside the player stops reading and keeps focus
EscapeInside the player, idleNot handled, not prevented
Planned test: read-aloud.test.tsx › keyboard › Escape while idle is not prevented
EnterPrevious, Next, Stop, idleDoes nothing
Planned test: read-aloud.test.tsx › keyboard › Enter on Previous, Next and Stop while idle does nothing and keeps focus
EscapeAnywhere, trigger shownDismisses the selection trigger
Planned test: read-aloud.test.tsx › selection trigger › is dismissed by Escape
Arrows, typeaheadSpeed, VoiceNative <select> behaviour
Planned test: read-aloud.test.tsx › keyboard › arrow keys on the speed select are not handled or prevented
TabReadAloud.BarOne Tab stop reaches the toolbar; a second reaches Settings' popup once open, a third Hide while idle
Planned test: read-aloud.test.tsx › bar keyboard › Tab reaches the toolbar in one stop
ArrowRight/LeftReadAloud.Bar's toolbarMoves the roving stop between Previous, Play, Next, Stop, Settings, wrapping, flipped in RTL
Planned test: read-aloud.test.tsx › bar keyboard › arrow keys move between the toolbar's items
Home / EndReadAloud.Bar's toolbarJump to Previous / Settings
Planned test: read-aloud.test.tsx › bar keyboard › Home and End jump to the first and last item
Enter / SpaceSettings triggerOpens the popup; Escape closes it and returns focus to the trigger
Planned test: read-aloud.test.tsx › bar keyboard › Settings opens on Enter and closes on Escape
EscapeSettings open, then againFirst closes the popup and returns focus to the trigger; a second, inside the player while playing, stops reading (one Escape, one layer)
Planned test: read-aloud.test.tsx › bar keyboard › Escape closes Settings before it stops the player
Enter / SpaceHide, idleCollapses the Bar to Play and moves focus to it
Planned test: read-aloud.test.tsx › bar keyboard › Hide collapses the Bar and moves focus to Play

Announcements#

ReadAloud tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).

WhenWhat it saysMessage keyPoliteness
A wait past 1 second (once per press)readAloud.preparingPolite
No voice for the content's languagereadAloud.errorNoVoicePolite
The voice service is busyreadAloud.errorServiceBusyPolite
The voice service is unavailablereadAloud.errorServiceUnavailablePolite
The browser couldn't play the audioreadAloud.errorPlaybackPolite
Nothing resolved to read (B3, Plan 0154): a misconfigured scope, no <main>, or empty contentreadAloud.errorNoContentPolite

The text in all five languages

Change the text#

For your whole app, pass messages to KvirnProvider. For one ReadAloud, pass its messages prop.

<KvirnProvider messages={{ readAloud: { preparing: '…' } }}>

Warning: Don't forget

Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.

API reference#

import { ReadAloud, useReadAloud } from '@kvirn-ui/read-aloud'
import { kvirnSpeechEngine } from '@kvirn-ui/core'

ReadAloud.Root

Renders <div> with the role group, named by the message readAloud.label. It takes the options of useReadAloud as props and every attribute of a <div> except lang and onKeyDown, and passes ref to it. Renders nothing once it knows the page's language has no voice on the service. Put the other parts inside it. The default theme is described on Theming.

PropTypeDefaultDescription
contentRefRefObject<Element | null>RequiredThe element whose text is read. It is read when Play is pressed.
scopestring–A CSS selector for the element to read, used only while contentRef is not given (ReadAloud.Bar’s own default composition uses this). With neither, the page’s <main> is read. A selector that matches nothing, or no <main> at all, warns once in development and reads nothing.
engineReadAloudEngineRequiredThe speech engine: kvirnSpeechEngine({ url }) from @kvirn-ui/core, or a fake for tests.
namestring–Who receives the text, named by the Note part. Pass the same value you gave kvirnSpeechEngine. Left out, the Note renders nothing.
urlstring | URLthe provider’s readAloud.urlBuilds the engine for you instead of passing one. Ignored when you pass engine. Without either, and with no provider config, no player renders.
storebooleanfalseAsks the service to cache the audio. Only for public page text. Used with url.
timeoutnumber10000Total budget per request, in milliseconds. Used with url.
voicesReadonly<Record<string, string>>the provider’s readAloud.voicesWhich voice reads each language, by BCP 47 tag. Your entries resolve over the service’s own map. The language comes from the content’s lang, then the provider’s locale.
highlightbooleantrueRegisters the sentence being read as a highlight where the browser supports the CSS Custom Highlight API. Nothing is painted until you style ::highlight(kv-read-aloud).
scrollbooleantrueScrolls the sentence into view when it is out of view. Never when the user prefers reduced motion.
messagesPartial<KvirnMessages['readAloud']>–Overrides the readAloud messages for this player, such as { play: "Listen to the notice" }.
onStatusChange(status: 'idle' | 'preparing' | 'playing' | 'paused') => void–Called when the status changes.
Class or attributeValuesMeaning
kv-read-aloudalwaysThe part class. In the content flow it paints no panel: a bare row of buttons (D44). Inside a ReadAloud.Bar it is the full-width band instead.
kv-read-aloud--iconsyour own class, on Root, with a Bar insideHides every button’s word in the Bar, Play included, for the smallest possible bar. Each control keeps its name for assistive technology; only the visible text is hidden.
kv-read-aloud--wordsyour own class, on Root, with a Bar insideShows every button’s word in the Bar, matching the inline row’s look. With neither class, the Bar shows the word on Play only and icons on the rest.
data-statusidle, preparing, playing, pausedWhat the player is doing. preparing covers the first press and a mid-text gap.
data-errorno-voice, speech-error, service-unavailable, service-busy, text-too-longWhy reading stopped, or a part was skipped. Absent otherwise.
data-sourcecontent, selectionWhether Play reads the whole content or a captured selection.
data-kv-read-aloud-skipalwaysThe player’s own words are never read. Put it on content that must not be read too.

ReadAloud.Progress

Renders <p aria-hidden="true"> wrapping the fill: the sentence meter. No progressbar or slider role, no handle, nothing to drag — it is informative only, since ReadAloud.Status already carries the position in words. Renders nothing while idle.

Class or attributeValuesMeaning
kv-read-aloud-progressalwaysThe part class, on a decorative <p aria-hidden="true">. No progressbar or slider role, no handle: the position is in words, in Status.

ReadAloud.Play

Renders <button type="button"> with the role button, named Listen, Listen to selected text while a selection is captured, or Pause while reading or getting the audio. It stays pressable while getting the audio, so pressing it is how you stop the wait. A play/pause icon sits before the word, decorative, and is replaced by a spinner past 300 ms of getting the audio. It takes every attribute of a <button> and passes ref to it.

PropTypeDefaultDescription
childrenReactNodethe messageYour own text. It replaces the message, so its language is yours to set.
Class or attributeValuesMeaning
kv-button kv-read-aloud-button kv-read-aloud-playalwaysThe part classes. Previous, Next and Stop share the first two and add their own instead of the third (kv-read-aloud-previous, -next, -stop). SelectionTrigger has its own instead (kv-read-aloud-selection-trigger).
data-playingwhile readingPlay is showing Pause.
data-busypast 300 ms of preparingThe wait for the first or next chunk has become visible. Play stays pressable: it is the way to stop the wait. The play/pause icon is replaced by a spinner in the same cell, so nothing moves.

ReadAloud.Transport

Renders <div> grouping ReadAloud.Previous and ReadAloud.Next: the cluster, its gap, and Stop's separation from it. Adds no Tab stop and no role. It takes every attribute of a <div> and passes ref to it.

PropTypeDefaultDescription
childrenReactNode–Put ReadAloud.Previous and ReadAloud.Next here.
Class or attributeValuesMeaning
kv-read-aloud-transportalwaysThe part class, on a plain <div>. Creates the cluster, its gap and the separation from Stop. Adds no Tab stop.

ReadAloud.Previous

Renders <button type="button"> with the role button, named Previous sentence. It stays focusable with aria-disabled while idle. A decorative icon sits before the word. It takes every attribute of a <button> and passes ref to it.

PropTypeDefaultDescription
childrenReactNodethe messageYour own text. It replaces the message, so its language is yours to set.

ReadAloud.Next

Renders <button type="button"> with the role button, named Next sentence. It stays focusable with aria-disabled while idle. A decorative icon sits before the word. It takes every attribute of a <button> and passes ref to it.

PropTypeDefaultDescription
childrenReactNodethe messageYour own text. It replaces the message, so its language is yours to set.

ReadAloud.Stop

Renders <button type="button"> with the role button, named Stop. It stays focusable with aria-disabled while idle. A decorative icon sits before the word. It takes every attribute of a <button> and passes ref to it.

PropTypeDefaultDescription
childrenReactNodethe messageYour own text. It replaces the message, so its language is yours to set.

ReadAloud.Rate

Renders A native <select> of the speeds with a visible <label>. Changing it changes the speed of the sentence already playing: no new request. It takes every attribute of a <select>.

PropTypeDefaultDescription
labelReactNodethe messageThe visible label. It replaces the message readAloud.rate or readAloud.voice.
Class or attributeValuesMeaning
kv-read-aloud-selectalwaysThe class of the <select>.
kv-read-aloud-labelalwaysThe class of its <label>.

ReadAloud.Voice

Renders A native <select> of the voices for the content language, with a visible <label>. It renders only when there are two or more; while the list has not arrived from the service yet, it shows a loading message instead. Not in any composition on this page: today only English has more than one voice.

PropTypeDefaultDescription
labelReactNodethe messageThe visible label. It replaces the message readAloud.rate or readAloud.voice.
Class or attributeValuesMeaning
kv-read-aloud-selectalwaysThe class of the <select>.
kv-read-aloud-labelalwaysThe class of its <label>.

ReadAloud.Status

Renders <span> with role="status" and aria-live="off": findable, but silent, since the speech is the feedback. It shows the sentence position, that the audio is on its way, that a part was skipped, or why reading stopped.

PropTypeDefaultDescription
as'span' | 'p' | 'div''span'Changes the element. Another tag warns once and renders a span.
refRef<HTMLElement>–Reaches the element.
childrenReactNodethe status textYour own text. It replaces the position or the reason nothing is read.
Class or attributeValuesMeaning
kv-read-aloud-statusalwaysThe part class.
data-errorno-voice, speech-error, service-unavailable, service-busy, text-too-longWhy nothing is read.

ReadAloud.Note

Renders <p> naming who the text is sent to, and saying that nothing is stored (readAloud.note) or that the audio may be (readAloud.noteStored, when you set store: true), with your howItWorksHref as a link at the end. Renders nothing when ReadAloud.Root was given no name: there is no sensible text to show without knowing the recipient.

PropTypeDefaultDescription
howItWorksHrefstring–Shown as a readAloud.howItWorks link at the end of the note, pointing at your own page. Left out, no link is shown.
childrenReactNodethe note textYour own text. It replaces readAloud.note, so its language is yours to set.
Class or attributeValuesMeaning
kv-read-aloud-notealwaysThe part class.

ReadAloud.SelectionTrigger

Renders <button type="button"> in the top layer, shown below a selection made with a pointer. It never takes focus and is not a Tab stop: the keyboard path is Play. It is named Listen to selected text and takes every attribute of a <button>.

PropTypeDefaultDescription
childrenReactNodethe messageYour own text. It replaces the message, so its language is yours to set.
Class or attributeValuesMeaning
kv-button kv-read-aloud-selection-triggeralwaysThe part classes.
popover="manual"alwaysPuts the button in the top layer below the end of a selection made with a pointer.

ReadAloud.Bar

Renders <div> with no role or name of its own: it sits inside ReadAloud.Root's own group, which is named readAloud.barLabel while a Bar is mounted. Its default content is a Toolbar of Previous, Play, Next, Stop and Settings (one Tab stop), a status count, and Hide. It takes every attribute of a <div> and passes ref to it.

PropTypeDefaultDescription
childrenReactNodethe default toolbar, status count and HideYour own markup instead of the default transport. Build it from the part props of useReadAloud.
Class or attributeValuesMeaning
kv-read-aloud-baralwaysThe part class, on a plain <div> with no role or name of its own: ReadAloud.Root’s own group is the Bar’s group too. The default theme keeps it static while idle and makes it sticky only while playing.

ReadAloud.Settings

Renders A Popover trigger button, icon-only and named by readAloud.settings, opening a menu with Speed, Voice and the recipient note. One part works both standalone in the panel and as a toolbar item in the Bar. It takes every attribute of a <button> and passes ref to it.

PropTypeDefaultDescription
howItWorksHrefstring–Shown as a readAloud.howItWorks link after the recipient sentence, pointing at your own page. Left out, no link is shown and nothing warns: the destination is your own to write.
childrenReactNodeSpeed, Voice, then the recipient noteYour own content for the popup. The trigger button itself stays fixed.
Class or attributeValuesMeaning
kv-button kv-button--icon-only kv-read-aloud-settingsalways, on the triggerThe classes of the icon-only button that opens the menu.
kv-read-aloud-settings-popupalways, on the popupThe class of the menu itself: Speed, Voice, then the recipient note.
aria-haspopup / aria-expanded"dialog" / true or falseTells assistive technology the button opens a menu, and whether it is open.

ReadAloud.Hide

Renders <button type="button">, icon-only and named by readAloud.hide. ReadAloud.Bar only. Collapses the Bar to its one Play button and moves focus there. Renders nothing once reading has started: hiding the only Pause would leave no way to stop it.

PropTypeDefaultDescription
childrenReactNodea close iconYour own icon or text, named by readAloud.hide either way.
Class or attributeValuesMeaning
kv-button kv-button--icon-only kv-read-aloud-hidealwaysThe part classes.
aria-labelreadAloud.hideNames the button, since its icon is the only visible content.

ReadAloud.WhenStarted

Renders Nothing of its own: its children only, once reading has started at least once, and nothing before. It never goes back to showing nothing. It reads the ReadAloud.Root it is inside, so there is still one engine, not a second one built separately.

PropTypeDefaultDescription
childrenReactNode–Shown only once reading has started at least once; nothing before that, and it never goes back to hidden. Not part of the recommended inline row (D44, D47, gated on `status` instead), kept for a consumer's own composition that wants a sticky reveal. Reads the ReadAloud.Root it is inside, so there is still one engine, not a second one.

kvirnSpeechEngine

Renders nothing: kvirnSpeechEngine(options) from @kvirn-ui/core returns the engine for Kvirn's voice service, for useReadAloud's engine option. These are its options.

PropTypeDefaultDescription
urlstring | URLRequiredThe service’s base URL: an origin, or a path on your own proxy. Named by none.
namestringthe URL’s hostWho receives the text, named in the privacy notice. Pass the same value to useReadAloud’s name.
storebooleanfalseAsks the service to cache the audio. Only for public page text.
timeoutnumber10000Total budget per request, in milliseconds.
voicesReadonly<Record<string, string>>the service’s own mapWhich voice reads each language, by BCP 47 tag, such as { sv: sv_SE-male-0-medium }. Your entries resolve over the service’s own map. A language with no voice gets no player.

useReadAloud

Returns the prop objects of every part (rootProps, playProps and so on), the labels and the state. Use it to build the player with your own markup.

Options

PropTypeDefaultDescription
contentRefRefObject<Element | null>RequiredThe element whose text is read. It is read when Play is pressed.
scopestring–A CSS selector for the element to read, used only while contentRef is not given (ReadAloud.Bar’s own default composition uses this). With neither, the page’s <main> is read. A selector that matches nothing, or no <main> at all, warns once in development and reads nothing.
engineReadAloudEngineRequiredThe speech engine: kvirnSpeechEngine({ url }) from @kvirn-ui/core, or a fake for tests.
namestring–Who receives the text, named by the Note part. Pass the same value you gave kvirnSpeechEngine. Left out, the Note renders nothing.
urlstring | URLthe provider’s readAloud.urlBuilds the engine for you instead of passing one. Ignored when you pass engine. Without either, and with no provider config, no player renders.
storebooleanfalseAsks the service to cache the audio. Only for public page text. Used with url.
timeoutnumber10000Total budget per request, in milliseconds. Used with url.
voicesReadonly<Record<string, string>>the provider’s readAloud.voicesWhich voice reads each language, by BCP 47 tag. Your entries resolve over the service’s own map. The language comes from the content’s lang, then the provider’s locale.
highlightbooleantrueRegisters the sentence being read as a highlight where the browser supports the CSS Custom Highlight API. Nothing is painted until you style ::highlight(kv-read-aloud).
scrollbooleantrueScrolls the sentence into view when it is out of view. Never when the user prefers reduced motion.
messagesPartial<KvirnMessages['readAloud']>–Overrides the readAloud messages for this player, such as { play: "Listen to the notice" }.
onStatusChange(status: 'idle' | 'preparing' | 'playing' | 'paused') => void–Called when the status changes.

Result

PropTypeDefaultDescription
status'idle' | 'preparing' | 'playing' | 'paused'–What the player is doing.
error'no-voice' | 'speech-error' | 'service-unavailable' | 'service-busy' | 'text-too-long' | null–Why reading stopped, or null.
voicesStatus'idle' | 'loading' | 'ready' | 'error'–Whether the voice list has arrived from the service.
loadVoices() => void–Fetches the voice list without playing, for a part that needs it before the first press (ReadAloud.Voice calls it on mount). Calling it again does nothing new.
stateReadAloudState–The full state of the reader.
hasVoiceboolean | null–Whether the content language has a voice on the service. null until the voice list has loaded, so a consumer can render no player for a language with none without flashing it first.
hasSelectionboolean–A selection inside the content is captured: Play reads it.
hasVoiceChoiceboolean–true with two or more voices for the language, which is when a Voice select is useful.
rootPropsReadAloudRootPartProps–Spread on the group’s element.
playPropsReadAloudPlayPartProps–Spread on the Play <button>.
previousPropsReadAloudButtonPartProps–Spread on the Previous <button>.
nextPropsReadAloudButtonPartProps–Spread on the Next <button>.
stopPropsReadAloudButtonPartProps–Spread on the Stop <button>.
ratePropsReadAloudSelectPartProps–Spread on the speed <select>.
rateLabelPropsReadAloudLabelPartProps–Spread on the speed <label>.
voicePropsReadAloudSelectPartProps–Spread on the voice <select>.
voiceLabelPropsReadAloudLabelPartProps–Spread on the voice <label>.
statusPropsReadAloudStatusPartProps–Spread on the status element.
notePropsReadAloudNotePartProps–Spread on the Note’s <p>.
noteTextstring | null–readAloud.note with the recipient’s name, or null when Root was given no name: there is nothing sensible to show without it.
isSelectionTriggerShownboolean–true after a selection made with a pointer in the content, until it is dismissed.
selectionTriggerPropsReadAloudSelectionTriggerPartProps–Spread on the <button> shown next to the selection.
playLabelstring–The Play message: Listen, Listen to selected text or Pause.
playIdleLabelstring–The Play message on its own, for building a custom idle label stack.
selectionLabelstring–The selection trigger’s name, and the Play message while a selection is captured.
pauseLabelstring–The Play message on its own, for building a custom pause label stack.
previousLabelstring–The Previous message.
nextLabelstring–The Next message.
stopLabelstring–The Stop message.
rateLabelstring–The speed label.
voiceLabelstring–The voice label.
howItWorksLabelstring–The Note part’s link text, for your own howItWorksHref link.
voicesLoadingLabelstring–Shown only while the Voice select’s options have not arrived yet.
statusTextstring–The visible status: the position, a wait, a skipped part, or the reason reading stopped. Empty when idle.
progressFractionnumber | null–The sentence meter’s fill, 0 to 1. null while idle, so a custom Progress part can render nothing.
rateOptionsReadAloudOption[]–The speeds, with formatted labels.
voiceOptionsReadAloudOption[]–The voices for the content language.
barLabelstring–readAloud.barLabel: the Bar’s own name for the group, used instead of readAloud.label while a Bar is mounted.
toolbarLabelstring–readAloud.toolbarLabel: the name of the Bar’s own toolbar, different from barLabel so a screen reader never hears the same phrase twice on entering the Bar.
settingsLabelstring–readAloud.settings: names the Settings button and its popup.
hidePropsReadAloudHidePartProps–Spread on the Hide <button>.
hideLabelstring–The Hide message.
hasEverPlayedboolean–true once reading has started at least once, and never resets. Lets a custom idle panel keep its transport open for the rest of the visit after the first press.

Strings

These are the default texts in @kvirn-ui/i18n.

For your whole app, pass messages to KvirnProvider. For one ReadAloud, pass its messages prop.

Message keyParametersDefault text in EnglishUsed for
label–Listen to this textThe name of the group.
play–ListenThe name of Play while idle.
playSelection–Listen to selected textThe name of Play while a selection is captured, and of the selection trigger.
pause–PauseThe name of Play while reading or getting the audio.
previous–Previous sentenceThe name of Previous.
next–Next sentenceThe name of Next.
stop–StopThe name of Stop.
rate–SpeedThe label of the speed select.
voice–VoiceThe label of the voice select.
rateOptionrate1.5×One speed in the select.
positioncurrent totalSentence 3 of 12The Status while reading.
positionPausedcurrent totalPaused at sentence 3 of 12The Status while paused.
preparing–Getting the audio…The Status while the first or next chunk's audio is on its way. Announced once, past a one-second wait.
errorServiceBusy–The listening service is busy. Press Listen to try again.The Status when the service is busy and the one automatic retry also failed. Also announced.
errorServiceUnavailable–The text can't be read aloud right now. Press Listen to try again, or read on.The Status when the service can't be reached. Also announced.
errorPlayback–This browser couldn't play the audio.The Status when the browser couldn't play the audio. Also announced.
errorNoVoicelanguageThere is no voice for English yet, so this page can't be read aloud.Shown beside the article where you choose to, for a language with no voice.
partSkipped–One part of the text was skipped.The Status after a passage with no voice, or too long for the service, was skipped. Shown only, never announced.
voicesLoading–Loading voices…Shown by the Voice select while the voice list has not arrived yet.
notenameListening sends this text to Kvirn’s voice service to make the audio. The text and the audio are not saved.The Note part's text, naming who receives the text.
howItWorks–How listening worksThe Note part's link text.
barLabel–Listen to this pageThe group's name while a Bar is mounted, instead of label.
settings–Listening settingsNames the Settings button and its popup.
hide–Hide the listening barThe name of the Hide button, Bar only.

Known issues#

  • Real speech is manual only. Tests use a fake engine; the docs site and Storybook never call the live voice service in CI. The iOS unlock, real voices and the Kvirn service's actual latency need a check with your own users and assistive technology.
  • Highlight needs the CSS Custom Highlight API. Without it, Status's position text is the only position cue, which is by design, not a gap.
  • fi, nb and nn strings: have a native speaker review them before you launch.
  • voice.kvirn.com is not deployed yet. Until it is, every environment but a local dev edge sees the "service unavailable" state.

Information: Did you know?

If an issue here affects your service, list it in your accessibility statement with its workaround.

Testing#

The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.

AT + browser + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespendingn/apendingread-aloud.stories.tsx, every story state, 4 themes (T7)
Markup and ARIA (roles, names, ids, states)pendingn/apendingread-aloud.test.tsx (T7)
Keyboard contract rows (Vitest browser)pendingn/apendingthe 10 rows above, each its own named test (T7)
Focus order and managementpendingn/apendingread-aloud.test.tsx (T7)
Display modes (forced colours, 320px reflow, text spacing, reduced motion)pendingn/apendingthe four sweep projects, run in CI once ReadAloud is added to sweepComponents (T7)
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpendingthe iOS unlock (the reused <audio> element) is unverified on a real device
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

What to check#

  • Tab through the panel: each control is named. Previous, Next and Stop are read as unavailable while idle.
  • Press Enter or Space on Listen: speech starts and focus stays on the button.
  • Press Escape while it reads: reading stops and focus stays where it was.
  • In the Bar, Tab once to reach the toolbar, then use the arrow keys: focus moves between Previous, Play, Next, Stop and Settings, wrapping at the ends.
  • Select text with Shift and the arrow keys, then Tab to Listen: only the selection is read.
  • With no voice for the content's language, no player ever appears, not even for a moment.