Building a website with AI that reads itself aloud
Pages that narrate themselves with an open text-to-speech model while the words light up as they are spoken — built with AI agents, served as static pages.
Some things are better heard than read. I wanted the old Norse myths on Kvöldvaka to be told the way they were once told — aloud, by the fire. So the pages read themselves: press play, and a voice tells the story while the words light up as they are spoken.
I built it with AI agents doing most of the typing. Here is how it works, and what I learned.
The shape: everything at build time
The most important choice was to do the hard work once, when the site is built — not in the visitor’s browser and not on a server per request.
- The story is plain text, kept with the site.
- At build time, a text-to-speech model turns it into an audio file.
- A speech-recognition model listens to that audio and writes down when each word is spoken.
- The page ships the text, the audio and the timings. The browser only plays the audio and follows along.
The result is a static site. No voice server has to stay up, nothing is generated while someone waits, and the pages load as fast as any other.
The voice: an open model
For the narration I use Kokoro, an open text-to-speech model that is small enough to run on an ordinary machine and sounds natural enough to listen to for a whole story. Because it runs locally, I can regenerate a chapter whenever the text changes, as often as I like, at no cost.
A few things make a real difference to how it sounds:
- Write for the ear. Long sentences that read well can be hard to follow aloud. Shorter sentences and clear breaks help the voice — and the listener.
- Names need help. Old Norse names trip up any voice. Each story carries a short list of spellings for the voice only — the page still shows the real name, but the voice is handed a spelling it can say.
- Generate in pieces. Each paragraph and each heading is its own recording, so the pacing stays steady and one changed paragraph is cheap to redo.
- Name the file by what it says. Each recording is named by a hash of its text. An unchanged paragraph is never recorded again, and a changed one gets a new name that no phone can have cached.
The timing: let a listener write it down
To light up each word as it is spoken, the page needs to know exactly when each word starts. The narration model does not tell you that reliably. So I turned the problem around: after the audio is made, Whisper, an open speech-recognition model (run locally with whisper.cpp), listens to it and returns the words with their times.
Then the heard words are matched back to the words shown on the page — so punctuation, spelling and names come from the story, and only the timing comes from Whisper. A word Whisper did not hear clearly is placed between its neighbours. The timings are saved beside each recording, named by the same hash, so they never go stale.
The page: following the voice
In the browser, the work is small. As the audio plays, a short script reads its current time, finds the word being spoken, and lights it gold. The paragraph being read is at full light; the others dim. When a new paragraph starts, the page brings it into view — but only if it is not already comfortably on screen, so the text does not jump about while you read along.
One detail matters for everyone, not only for people who listen: the text is real text. Search engines, screen readers and AI assistants read the story as normal HTML. The voice is an addition, never a replacement.
Building it with agents
I did not hand-write most of this. I wrote the plan — what the page should do, how it should look, what must never break — and AI coding agents built the pieces, each in its own branch, each change reviewed before it went live. The build steps that call the voice and the listener are small scripts the agents wrote and I checked.
What the agents could not do was listen. Every chapter was played and heard by a person before it was published. A model can tell you the audio file exists. Only you can tell whether the story sounds right.
Try it
Open Kvöldvaka, press play, and watch the words follow the voice. If you want to give your own pages a voice, it is one of the courses I plan: voice for the web, from text to narration to words that light up.