Leônidas Augusto Amaro

The podcast that read its stage directions out loud

4 min readAIBackend

Books is my personal reading tool: it turns the books I study into structured chapter notes. On April 28 I added a button to every chapter: Generate podcast. It produces a short conversation about that chapter, with two voices: a curious host who asks real questions, and an expert who explains without lecturing.

The first version also said "thoughtful" out loud, in the middle of a sentence.

Two steps, two processes

Generating an episode is slow and costs money, so it never runs inside a web request. The button starts a small state machine that lives in a file next to the chapter:

  1. Scripting. An LLM agent reads the chapter notes and writes a dialogue, one turn per line, prefixed with HOST: or EXPERT:. A spec file sets the rules: a real conversation instead of a formal Q&A, no two turns in a row from the same speaker, names and numbers faithful to the notes, 6 to 12 minutes long.
  2. Synthesis. A detached worker parses the script, sends each turn to ElevenLabs with the right voice, stitches the clips together and writes the final MP3 and its metadata.

A script looks like this:

HOST: [thoughtful] Wait... so rereading the chapter doesn't really help?
EXPERT: It helps less than it feels like it does. That's the trap.

The clips are joined with ffmpeg -f concat -c copy, which glues the MP3s without re-encoding them: it's fast and lossless. The audio route supports HTTP range requests, so the player can seek without downloading the whole file.

Guardrails before the first real episode

Text-to-speech is billed per character, and the spec's target of 1,000 to 2,000 words is roughly 6,000 to 12,000 characters per episode. So the guardrails went in on the same afternoon as the feature:

  • A monthly cap. Every episode appends its character count to a log, and the button refuses to start once the month reaches the limit (200,000 characters). The limit lives in the product, not in my head.
  • A cheap smoke test. A test script runs the whole pipeline but sends only the first 200 characters of each turn. That's enough to prove that parsing, voices, concatenation and the player all work, for a fraction of the cost.
  • Typed errors. Failed calls come back as auth, quota, server or network, so a failed episode says why it failed instead of just "error".
  • Survive a restart. The state file records the worker's process ID. If the server restarts mid-episode, the next read sees the process is gone and marks the episode as failed (or as "scripted", if the script was already written) instead of spinning forever.
  • Know when it's stale. Each episode stores a hash of the chapter it came from. Line endings and trailing spaces are normalized first, so a cosmetic edit doesn't flag the episode as outdated.

The host who said "thoughtful"

The script spec asked for emotion tags like [laughs], [thoughtful] and [sighs]. Some ElevenLabs models perform those tags. The one I settled on that afternoon, eleven_multilingual_v2, does not: it reads them as words. So the host would say, literally, "thoughtful... wait, so rereading doesn't help?"

The fix had two parts. The parser strips the tags before calling the TTS, and keeps them in the script file, where they still help a human reading it:

// eleven_multilingual_v2 reads bracketed tags as words ("thoughtful", "laughs"),
// so strip them before TTS. Tags are kept in the script.md for debug/legibility.
const TAG_RE = /\s*\[[^\]]*\]\s*/g
 
const text = m[2].replace(TAG_RE, ' ').replace(/\s+/g, ' ').trim()

The other part matters more. The spec changed so that emotion has to live in the words themselves: interruptions with a dash, pauses with "...", reactions like "ah, that makes sense" or "wait...". A tag can be stripped. A sentence that sounds like a person can't.

What I took from it

  • Your model choice is part of the prompt's contract. The same script is fine for one TTS model and broken for another. When you swap models, check what the output format assumes.
  • Put cost limits in the product before the first real run. A monthly cap and a 200-character smoke test cost minutes to write and remove the fear of pressing the button.
  • For a single-user tool, a file and a process ID beat a queue. No broker and no database, and it still survives a restart.

Update, October 2026

Since that afternoon, Books has generated 14 episodes: about 3 hours and 13 minutes of audio from 163,406 characters. That's an average of roughly 11,700 characters and 14 minutes per episode, with episodes running 11 to 18 minutes: longer than the spec's 6-to-12-minute target. All 14 together still fit under a single month's 200,000-character cap.

All posts