MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度分析项目:mateogon/pdf-narrator

项目背景与痛点

在数字化内容日益丰富的情况下,如何将文字内容转化为触手可及的音频,成为了一个无法忽视的领域。PDF 和 EPUB 等格式的文件存储了大量的文本信息,但往往使用不便,难以进行快速阅读。mateogon/pdf-narrator 正是为了满足这一需求而开发的工具,它将 PDF 和 EPUB 文件转化为音频书籍,不仅解放了用户的双眼,还使得在忙碌的生活中能够随时随地获取信息。

核心技术揭秘

项目的核心在于从 PDF、EPUB 文件中智能提取文本内容,并将其通过语音合成转化为音频文件。这个过程中涉及到以下几个关键技术点:

  1. 文本提取:从 PDF 和 EPUB 文件中智能识别和抽取文本内容。对于 PDF,需要处理复杂的布局和格式,提取有效的信息。

  2. 文本到语音转换:将提取的文本信息通过 TTS(Text-to-Speech)技术转化为音频。

  3. 低资源系统优化:项目针对低资源系统做了大量优化工作,这表现为其出色地处理了处理信息量较大的文件。

架构图

graph TD A[用户上传文件] --> B[文件类型校验] B --> C[文本提取] B --> D[异常处理] C --> E{"初始化 TTS 引擎"} E -->|"成功"| F[合成音频] E -->|"失败"| G[异常处理] F --> H[输出文件] H --> I[自动/手动同步到用户客户端] G --> I D --> I

分析架构图,我们可以清楚地看到从用户上传文件开始,到最终音频文件的生成和存储整个过程。字符串提取与音频合成相互独立,又相互依赖,这是实现高质量音频输出的基础。

功能亮点与差异

项目提供了灵活的配置选项,允许用户根据需求调整文本转换和语音合成的设置。此外,其对低资源系统的适应性也是同类项目中的佼佼者,尤其是在高并发场景下的性能表现,拥有独特优势。与市面上的其他 PDF-语音转换工具相比,mateogon/pdf-narrator 集成了智能文本抽取与高效的音频生成机制,最终结果更为自然流畅。

应用场景与落地建议

在生产环境使用 mateogon/pdf-narrator,需要注意原文件质量的好坏直接影响到最终生成音频的质量。对于低质量扫描的PDF文档,文本提取可能会出现较大错乱。因此,需要前置审核原文件的清晰度与布局是否适合提取文本内容。该项目十分适用于学术论文与书籍的辅助阅读场景,特别是笔记整理与语言学习过程中的口述笔记环节。对于多媒体生产部门,它同样可以作为辅助工具用于音视频内容的快速生成。

综合评价

mateogon/pdf-narrator 在智能文本抽取与高质量音频生成的基础上,提供了灵活配置的 TTS 设置,极大满足了多场景应用需求。虽然其对 PDF 文件的处理能力具有较高门槛,但总体而言,这是一款实用性强、适应场景广,并且重点优化了低资源系统操作的工具。

纵观整个项目,它很好地权衡了转换效率与质量之间的关系,在减少系统资源占用的同时提高处理速度。称其为一款匠心之作,毫不为过。

关于

GitHub 原始描述(英文)

Convert your PDFs and EPUBs into audiobooks effortlessly. Features intelligent text extraction, customizable text-to-speech settings, and efficient processing for low-resource systems.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
297
价值分
142
活跃状态
活跃

语言占比

CSS
HTML
JavaScript
Python

README

PDF Narrator

PDF Narrator turns PDF, EPUB, TXT and HTML books into audiobooks. It uses Kokoro-82M, a speech model that runs on your computer. Your books do not go to the internet.

PDF Narrator creating an audiobook

For a reader that shows the text while the audio plays, see Cadence.

Contents

  1. Features
  2. Requirements
  3. Install
  4. Make an audiobook
  5. Where your files are
  6. Command line
  7. Optional setups
  8. Troubleshooting
  9. Development
  10. License

Features

  • Desktop app. A library of your books and a four-step flow: check the text, pick a voice, create the audio, export.
  • Local speech. Kokoro runs on the CPU, on an Apple GPU (MPS) or on an NVIDIA GPU (CUDA). The app selects the fastest one.
  • Fast. On an Apple M-series GPU, the app creates audio about 10 to 13 times faster than real time.
  • Clean text. The app skips covers, copyright pages, contents and Project Gutenberg license text. You can edit any chapter before you create audio.
  • 54 voices in 9 languages. You hear each voice read a paragraph from your own book. Each voice shows its quality grade from Kokoro.
  • Audiobook export. M4B with chapters, title, author and cover, or one MP3 file for each chapter.
  • Safe to stop. You can pause, stop and continue. Finished chapters stay finished. If you edit a chapter, the app creates only that chapter again.

Requirements

Item Requirement
Operating system macOS, Windows 10/11 or Linux
Tools uv and Git
Disk space About 2 GB for Python packages, plus about 350 MB for the speech model
Internet Only for the first install and the first use of each voice
M4B export (optional) FFmpeg
Scanned PDFs (optional) Tesseract and Poppler. See Scanned PDFs

You do not need to install Python, CUDA, eSpeak, Java or DeepSpeed. uv installs the correct Python version and all packages.

Install

  1. Install uv.
    • macOS and Linux:
      curl -LsSf https://astral.sh/uv/install.sh | sh
      
    • Windows (PowerShell):
      powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
      
  2. Linux only: install the system web view and the tools to build its Python bindings (Ubuntu or Debian):
    sudo apt install gir1.2-webkit2-4.1 libgirepository-2.0-dev libcairo2-dev pkg-config python3-dev
    
    On Linux, start the app with uv run --with "pywebview[gtk]" pdf-narrator in step 5. macOS and Windows already include a web view.

    Note: The desktop app is not yet tested on Linux. The command line works without these packages.

  3. Optional: install FFmpeg for M4B export.
    • macOS: brew install ffmpeg
    • Windows: winget install Gyan.FFmpeg
    • Ubuntu or Debian: sudo apt install ffmpeg
  4. Download PDF Narrator.
    git clone https://github.com/mateogon/pdf-narrator.git
    cd pdf-narrator
    
  5. Start the app.
    uv run pdf-narrator
    

The first start takes a few minutes, because uv downloads the packages. Later starts take a few seconds.

To update PDF Narrator later, run git pull in the pdf-narrator folder.

Make an audiobook

Library

Step 1: Add a book

  1. Drag a PDF, EPUB, TXT or HTML file into the window, or click Choose file.
  2. Wait a few seconds. The app reads the book and finds its chapters, title, author, cover and language.

To add many books, click Add a folder. The app adds all supported files in that folder to the library.

Step 2: Check the text

Check the text

  1. Look at the chapter list. Sections without a check mark are skipped. The app skips covers, contents, copyright pages and very short sections.
  2. Click a chapter to read its text.
  3. Correct the text if necessary. The app saves your changes automatically.
  4. If the app finds a repeated page header, click Remove all to delete it from the chapter.
  5. Click Continue to voice.

Step 3: Pick a voice

Pick a voice

  1. Make sure that the language is correct. The voices change with the language.
  2. Click the play button on a voice. You hear that voice read a paragraph from your book.
  3. Click a voice card to select it.
  4. Optional: move the Reading speed slider.
  5. Click Create audiobook.

The first sample takes about 10 seconds, because the app loads the speech model. Later samples are faster.

Step 4: Create the audio

  1. Wait while the app creates each chapter. The page shows the time remaining and the speed.
  2. Optional: click the play button on a finished chapter to listen to it.
  3. To stop for now, click Pause or Stop. Finished chapters stay finished. Click Create again to continue.

Note: The first time, the app downloads the speech model (about 350 MB). This can take a few minutes.

Step 5: Export

Export

  1. Select a format:
    • Audiobook (M4B): one file with chapters, title, author and cover. Use it with Apple Books and most audiobook apps. M4B needs FFmpeg.
    • MP3 per chapter: one MP3 file for each chapter. It plays on all devices.
  2. Click Export audiobook.
  3. Click Show file to open the folder.

The app also has a dark mode. To use it, open Settings and select Dark or System.

Dark mode

Where your files are

The app keeps a library in ~/Audiobooks/PDF Narrator. To change this folder, open Settings > General > Library folder.

Each book has its own folder:

Folder or file Content
book.json Title, author, language, voice and chapter status
source/ A copy of the file that you added. The app does not change your original file
text/ The text of each chapter
chapters/ The audio of each chapter (WAV)
export/ The finished audiobook (M4B or MP3)

To delete a book, open the book, click Book details, then click Remove from library. This deletes the library copy only.

Command line

You can also make an audiobook without the window:

uv run pdf-narrator book.epub --voice af_heart --format m4b

More examples:

uv run pdf-narrator book.pdf --voice ef_dora --lang e --output-dir ./audio
uv run pdf-narrator book.txt --device cpu --format mp3
uv run pdf-narrator book.epub --format m4b --title "My book" --author "An author"
uv run pdf-narrator book.epub --resume
uv run pdf-narrator --help
Option Values Default
--voice A Kokoro voice ID, for example af_heart, bf_emma, ef_dora af_heart
--lang a US English, b UK English, e Spanish, f French, h Hindi, i Italian, j Japanese, p Brazilian Portuguese, z Mandarin First letter of the voice
--device auto, cpu, mps, cuda auto
--speed Reading speed, for example 0.9 or 1.2 1.0
--format wav, mp3, m4b wav
--resume Use chapters that are already finished, if the text, settings and audio did not change Off

Rules:

  • The voice must match the language. Voices that start with a or b are English; voices that start with e are Spanish.
  • With --format m4b, the .m4b file goes to the output folder. The chapter WAV files stay in chapters/ inside that folder, so that --resume can use them again.
  • uv run pdf-narrator --ui classic opens the previous Tk window. It needs a Python build with Tk.

Optional setups

NVIDIA GPU (Windows and Linux)

  1. Make sure that you have a current NVIDIA driver. You do not need the CUDA Toolkit.
  2. Run the app or the command line with the CUDA packages:
    uv run --no-default-groups --extra cuda pdf-narrator
    
  3. Use the same flags each time. Without them, uv installs the CPU packages again.

This option is not for macOS. On a Mac, the app uses the Apple GPU (MPS) automatically.

Scanned PDFs (OCR)

A scanned PDF has images of pages, not text. To read it, the app needs optical character recognition (OCR).

  1. Install Tesseract and Poppler:
    • macOS: brew install tesseract poppler
    • Ubuntu or Debian: sudo apt install tesseract-ocr poppler-utils
    • Windows: install Tesseract and Poppler. Then add their program folders to PATH.
  2. Start the app with the OCR packages:
    uv run --extra ocr pdf-narrator
    
  3. Check the text in Check text before you create the audio. OCR can make mistakes.

OCR uses the default Tesseract language and removes the top and bottom 10% of each page.

Languages

Kokoro has voices for US and UK English, Spanish, French, Hindi, Italian, Brazilian Portuguese, Japanese and Mandarin. Japanese and Mandarin need extra packages that the default install does not include. See Kokoro’s documentation. Kokoro does not support Indonesian.

For English books, the app changes numbers and abbreviations into words. For other languages, the app keeps them as they are.

Troubleshooting

Problem Cause What to do
The first sample or the first chapter is slow The app downloads and loads the speech model Wait. This occurs only the first time
Couldn’t read on a book The file has no text, or the file is damaged For a scanned PDF, set up OCR. Then click Try again
A chapter contains page headers or page numbers PDF layouts are different from book to book Edit the text in Check text, or click Remove all on the suggestion
Audiobook (M4B) is not available FFmpeg is not installed Install FFmpeg, or export MP3
The window does not open on Linux The web view or its Python bindings are missing Do step 2 of Install, then start with uv run --with "pywebview[gtk]" pdf-narrator
Something else — Open Settings > About > Show diagnostics, then copy the text into a GitHub issue

To see what the app is doing, click Activity at the top right. The Details tab shows technical messages.

Development

  1. Install the development packages:
    uv sync --locked --group dev
    
  2. Run the tests:
    uv run --locked --group dev pytest -q
    

The code has these parts:

Part Files Job
Text extraction extract.py Read PDF, EPUB, TXT and HTML; split chapters; clean the text
Speech generate_audiobook_kokoro.py Send text to Kokoro in paragraph blocks; write audio while it is created
Export audiobook_export.py Make M4B files with FFmpeg
Library library.py, voices.py Keep books on disk; track the status of each chapter
Jobs jobs.py Run import, create and export jobs in the background
Desktop app webui/ Window (pywebview), local server and interface
Command line cli.py Make audiobooks without the window

Notes:

  • pyproject.toml declares the dependencies. uv.lock records the exact versions.
  • The preshed pin prevents a spaCy failure that occurs with newer versions on macOS.
  • The desktop window loads its interface from a local server on 127.0.0.1. The server uses a random port and a session token, and it only serves files from the library folder.
  • PDF_NARRATOR_CONFIG_DIR changes the settings folder. Use it for tests or a portable setup.

What has been tested

Platform Tested
Ubuntu, Windows, macOS Automatic tests on CPU in CI, including real OCR on Ubuntu
macOS, Apple M-series Desktop app from start to export; speech on CPU and MPS
Windows 11, RTX 3050 Command line on CPU and CUDA. The new desktop app is not yet tested on Windows

License

MIT. Kokoro and its model weights use the Apache 2.0 license.

评论

暂无评论