PDF to audiobook: OCR first, then a free voice
0
words heard from a scanned PDF, before OCR
OCR brings the words back
10 scanned book pages, 1,976 words. Piper read each text aloud, and Whisper wrote down what it heard.
| Text read aloud | Words heard | Page heads and numbers heard |
|---|---|---|
| The scan as it is | 0.0% | none: no text to read |
| OCRmyPDF text | 95.2% | 20 of 20 |
| OCRmyPDF text, then clean.py | 95.2% | 0 of 20 |
| The proofread text | 96.2% | 0 of 20 |
pdftotext and PDFKit (what Preview uses) found no text in the scan. Even the proofread text lost 3.8%, as the voice or Whisper slips. So OCR cost about 1 point.
Cut the page heads and numbers
OCR keeps all that is printed on the page, so the voice reads each running head and page number, often mid-sentence. Listen:
OCR also read one head, A NEIGHBOUR'S LANDMARK, as EANDMARK. Whisper heard "a neighbor's ean mark".
clean.py drops a short first line with a page number or in capitals, and lines that hold only a number. It also joins 12 words split at line ends, like delib- erately.
See the code in clean.py
import re
import sys
out = []
for page in open(sys.argv[1], encoding="utf-8").read().split("\f"):
lines = page.strip().split("\n")
head = lines[0].split() if lines else []
# A running head: a short first line with a page number, or in capitals ("86 The Boy Scouts of the Air").
if head and len(head) <= 8 and (re.fullmatch(r"\d+", head[0]) or re.fullmatch(r"\d+", head[-1]) or lines[0].upper() == lines[0]):
lines = lines[1:]
lines = [x for x in lines if not re.fullmatch(r"\s*\d+\s*", x)] # page numbers on their own line
text = "\n".join(lines).strip()
text = re.sub(r"(\w)-\n(?=[a-z])", r"\1", text) # "con-\ntinued" -> "continued"
text = re.sub(r"(?<!\n)\n(?!\n)", " ", text) # unwrap lines, keep blank lines between paragraphs
out.append(text)
print("\f".join(out), end="")
It expects one running head at the top of each page, and it also drops a short title in capitals there. It joins a real hyphen at a line end too: old-fashioned became oldfashioned. Check a few pages of its output on your own book.
Make the audiobook in 8 commands
On a Mac with Homebrew. scan.pdf is your scanned book:
brew install ocrmypdf ffmpeg
ocrmypdf --sidecar book.txt scan.pdf scan-ocr.pdf
curl -fLO https://brasspage.com/pdf-to-audiobook/clean.py
python3 clean.py book.txt > clean.txt
python3 -m venv piper && piper/bin/pip install piper-tts
piper/bin/python -m piper.download_voices en_US-ljspeech-high
piper/bin/piper -m en_US-ljspeech-high -i clean.txt -f book.wav
ffmpeg -i book.wav -c:a aac -b:a 64k book.m4b
book.m4b is the audiobook, about 0.5 MB a minute. Piper took 6.6 to 8.2 minutes for 10 pages, at low priority on this Mac.
A PDF that already has text? Skip the OCR line and run
pdftotext book.pdf book.txt, from
brew install poppler.
Pick a voice with a clear license
Each Piper voice learned from a set of recordings, and each set has its own license:
| Voice | Recordings | Recordings license |
|---|---|---|
| en_US-ljspeech | LJ Speech | Public domain |
| en_US-lessac | Lessac, Blizzard 2013 | Research only |
| en_US-ryan | RyanSpeech | CC BY-NC-SA 4.0, no commercial use |
Piper's own help names en_US-lessac-medium as its example voice. On a
Mac, say -f clean.txt reads aloud too, but Apple allows
its voices for personal, non-commercial use only.
Apps that OCR for you
What their own pages say. I did not test these:
| App | On a scanned PDF | Cost of OCR |
|---|---|---|
| Preview (Mac) | Export with Embed Text, then Edit, Speech | Free |
| NaturalReader | Offers OCR, up to 50 pages at a time | Paid plans: $13.90 a month or $79 a year and up |
| Speechify | The web app runs OCR on uploads | Free plan: 5 files, scans included |
| ebook2audiobook | Lists OCR for pages that are images | Free, open source |
Our Actor OCRs big scans
Our pdf-ocr Actor on the Apify Store turns scanned PDFs into Markdown or plain text. On these 10 pages, its code kept 99.5% of the true words as text, against 98.9% for OCRmyPDF. It keeps page heads and numbers too: cut them before you listen.
- Pages with their own text: free. Scanned pages: $0.006 each, plus a $0.00005 start fee a run at the default 1 GB.
- Apify's free plan stops at 20 pages a run and 50 a month, so a whole book needs a paid plan.
How I tested it
- Pages: 10 proofread English Wikisource pages from two public domain books, the same scan as my open source OCR test. The true text leaves out page heads and numbers. It is 1,976 words here and 1,955 there, as this scorer splits words at hyphens and dashes.
- Text: OCRmyPDF 17.13.0 with Tesseract 5.5.4 (English), Apple Vision, the Actor's code, pdftotext 26.03.0, and PDFKit (what Preview uses) on macOS 26.6.
- Voice: piper-tts 1.8.0, en_US-ljspeech-high, one audio file a page. About 10 minutes of audio per text.
- Ears: mlx-whisper 0.4.3 with whisper-large-v3-turbo, English, condition_on_previous_text off. With it on, Whisper made up sentences after the last word of some pages.
- Score: true words heard in order, lower case, no punctuation. A page head or number counts as heard if it is at the page's start or end.
- Apple Vision was scored as text, not read aloud: 99.4% of the true words. It kept all 10 running heads and 7 of 10 page numbers.
What I did not test
- The Mac's say voices, for their license.
- A whole book, two-column pages, footnotes, tables.
- Paid voices and the apps in the table above. Kokoro and other free voices.
Sources
Questions people ask
How do I turn a PDF into an audiobook for free?
If it is a scan, run OCRmyPDF with --sidecar to get its text. Then read the text aloud with Piper, a free voice, and make an m4b file with ffmpeg. On our 10 scanned pages, 95.2% of the words were heard.
Why will my PDF not read aloud?
It is probably a scan: pictures of pages with no text in them. pdftotext and Preview found 0 words in our scanned PDF. Run OCR first, then read it aloud.
Can I sell an audiobook made with the Mac's built-in voices?
Apple's macOS license allows its system voices for personal, non-commercial use only. It rules out recording or publishing them in a profit, non-profit, public sharing or commercial context. Pick a voice whose license allows your use.