Tirsvad 96b021c4ab
TirSystem/git-workflows: CD / changes (push) Successful in 10s
TirSystem/git-workflows: CI / secret-scan (push) Successful in 12s
TirSystem/git-workflows: CI / validate (push) Successful in 18s
TirSystem/git-workflows: CI / opengrep (push) Successful in 58s
TirSystem/git-workflows: CI / release-check (push) Successful in 6s
TirSystem/git-workflows: CD / wait-for-ci (push) Successful in 1m35s
TirSystem/git-workflows: CD / release (push) Skipped
TirSystem/git-workflows: CD / publish-wiki (push) Skipped
TirSystem/git-workflows: CD / sync-metadata (push) Successful in 6s
TirSystem/git-workflows: CD / sync-milestones (push) Successful in 42s
Merge pull request 'Record the review of the updated reflection' (#74) from wiki-reflection-review into main
2026-11-23 04:14:52 +01:00
2026-11-23 11:12:14 +08:00
2026-11-20 23:29:11 +08:00
2026-11-20 22:18:57 +08:00
2026-11-20 22:18:57 +08:00
2026-11-20 14:40:41 +01:00
2026-11-20 23:29:11 +08:00

🚀 PDF to Audiobook

A small Python program that reads a PDF file and turns its text into speech, so you get a free audiobook. It is the Day 91 assignment of the Udemy course 100 Days of Code: The Complete Python Pro Bootcamp, for course participants and anyone who browses the repository for ideas.

📚 Table of Contents

🧭 Overview

The program extracts the text of a PDF with pypdf, splits it into pieces of at most 400 characters and speaks each piece with Coqui TTS, an open source speech engine that runs on your own machine. No paid service and no account are needed. The assignment's function is convert_pdf_to_audiobook.

Folder What it holds
src/pdf_to_audiobook/ The program, in layers: domain, application, infrastructure, presentation. All constants are in constants.py
tests/ pytest tests
docs/ Business case, plan, milestones, reviews, images and the wiki sources (docs/wiki/)
scripts/ The opengrep security scan and the window test in a container
docker/ The image and the script of the window test
tools/ capture_step.py, which renders command output as an SVG image for the documentation

The project is built in seven lecture steps. Each step has a screenshot below and a page in the wiki (English, Danish and Bahasa Malaysia) that explains what we gained.

Step 1: Environment

Step 1: create the .venv and upgrade pip

Step 2: Read the PDF

Step 2: read the PDF and split the text

Step 3: Speak with Coqui TTS

Step 3: speak a sentence with Coqui TTS

Step 4: Convert and command line

Step 4: convert a PDF to an audiobook

Step 5: Tests and quality

Step 5: run the tests

Step 6: The speak text window

Step 6: the speak text window

Step 7: Open a PDF in the window

Step 7: open a PDF in the window

📋 Requirements

  • Python 3.13 or newer, because the project targets it.
  • git, to clone the repository.
  • About 2 GB of free disk space and a few minutes: the project installs pypdf, Coqui TTS, PyTorch and sounddevice, and downloads a voice model (about 110 MB) on the first run. The speech engine runs on your own machine; no account and no paid service are needed.
  • Optional for development: opengrep (~/.opengrep/cli/latest/opengrep.exe) for the security scan, and Doxygen for the API documentation.

🛠️ Setup

Create a local virtual environment, upgrade pip and install the project with the development tools.

Windows PowerShell:

git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/091-assignment-convert-pdf-to-audiobook.git
cd 091-assignment-convert-pdf-to-audiobook
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

Linux and macOS:

git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/091-assignment-convert-pdf-to-audiobook.git
cd 091-assignment-convert-pdf-to-audiobook
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

The folder .venv/ is ignored by git. Leave the environment with deactivate.

▶️ Run

With the virtual environment active, convert the sample PDF into a WAV file:

python -m pdf_to_audiobook tests/data/sample.pdf -o build/sample.wav

The same program is installed as a command:

pdf-to-audiobook my-book.pdf
pdf-to-audiobook my-book.pdf -o audio/my-book.wav --model tts_models/en/ljspeech/tacotron2-DCA

The speech library prints a lot of text while it works; the program hides it. Add --verbose to see it again, for example when you diagnose a problem. This works for the command and for the window.

Without -o the audio is written next to the PDF with the suffix .wav. Exit code 0 means success, 1 an error (the message is on stderr) and 2 a wrong command line.

In Python the assignment's function is available as convert_pdf_to_audiobook(pdf_path, output_path, engine, extract_text); see the wiki for the design.

Speak typed text or a PDF

Open a window, type text and press Speak, or press Open PDF to pick a PDF file, and hear it through the speakers. Stop ends the speech:

pdf-to-audiobook-window

While the voice model loads, the status line says Loading voice.... It uses the same voice model as the converter and plays the sound with sounddevice. On Linux install the system library libportaudio2 first.

🧪 Tests

With the virtual environment active:

python -m pytest

The real speech engine is tested by one slow test that is skipped by default and downloads the voice model on first use:

python -m pytest -m slow

Check the code style and the types:

python -m ruff check src tests
python -m mypy

The window is tested in a Linux container on a virtual display, never on your desktop (Docker is needed). The log and a screenshot go to build/gui-results:

pwsh scripts/gui-test.ps1

Run the security scan before every push:

pwsh scripts/scan.ps1

📄 License

GNU Affero General Public License v3, see LICENSE.

📎 Appendix: Project documents

The documents a newcomer needs, in reading order.

Document What it tells you
Business Case Why the project exists, its scope and success criteria
Stakeholder Analysis Who is involved; the stakeholder IDs used for owners and reviewers
Project Plan The gateways and their schedule
Milestones One document per gateway: Go/No-Go criteria and tasks
Artifact registry Where each artifact type lives, the next version, the PO language and domain
Traceability matrix How the artifacts link and when each was last reviewed
Framework README The framework this project uses
Framework changelog What changed in each framework release

S
Description
Python 3.13 script that converts a PDF file into an audiobook: extracts the text with pypdf and speaks it with Coqui TTS. Day 91 of 100 Days of Code.
Readme AGPL-3.0
593 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 97.7%
PowerShell 1.5%
Dockerfile 0.4%
Shell 0.4%