// Project
Multi-voice audiobook generator
PDF or text in, one MP3 out, with a different voice for every character.
What it does
Give it a PDF, text or markdown file and it writes one MP3. The narrator reads the prose; every character's quoted dialogue is read in a voice of their own. A local language model, run through Ollama, works out who is speaking each line, and edge-tts renders the voices.
The rewrite
The first version was about 11,000 lines of modular architecture, and it never produced audio. In June 2026 I threw it away and wrote five files that do. This page used to describe the old one in more impressive words. It was less impressive to run.
How the speaker is chosen
- Narration is free. Prose never goes to the model; only quoted speech is ambiguous.
- Rules first. Script-style lines with an explicit name resolve on the spot at full confidence.
- Structured output. The model answers against a JSON schema, so a reply is valid by construction. That deleted six parsing strategies from the old system.
- Cast, then context. One pass collects the cast; a second attributes lines in overlapping windows of 50 with the resolved lines shown as context.
- The model may say unknown. An unknown line falls back to the narrator's voice, which is safe. A confident wrong voice is the worst error in audio.
- Aliases merge. "Dokja", "Kim Dokja-ssi" and "Kim" become one character with one voice.
Measured
Benchmark: 80 dialogue lines from a real novel, audited line by line.
| configuration | exact | wrong-character voice | abstentions |
|---|---|---|---|
| qwen2.5:14b + deterministic rules | 76 / 80 (95.0%) | 0 | 4 |
The lesson was to leave the prompt conservative. Adding broad rules about alternating speakers or preferring unknown made the results worse; the narrow, tested rules belong in a post-pass.