Turn PDFs into Audiobooks with @hazeljs/pdf-to-audio
Convert PDF documents to high-quality audio with OpenAI TTS. Async job queue, AI summaries, summary-only mode, and CLI support—all in a single package.
Turn PDFs into Audiobooks
The @hazeljs/pdf-to-audio package converts PDF documents to high-quality audio using OpenAI TTS. Extract text, chunk it for optimal narration, generate speech per chunk, and merge into a single MP3 or Opus file—ideal for audiobooks, accessibility, or listening on the go.
Installation
npm install @hazeljs/pdf-to-audio @hazeljs/core @hazeljs/ai @hazeljs/queue @hazeljs/rag ioredisModule Setup
Register the module with Redis connection and optional output directory:
PdfToAudioModule.forRoot({
connection: { host: 'localhost', port: 6379 },
outputDir: './data/pdf-to-audio',
});REST API
Three endpoints power the async conversion flow:
- POST /api/pdf-to-audio/convert — Submit a PDF, receive a
jobId - GET /api/pdf-to-audio/status/:jobId — Poll until
completed - GET /api/pdf-to-audio/download/:jobId — Download the MP3
CLI
Convert from the command line against a running API:
hazel pdf-to-audio convert document.pdf --api-url http://localhost:3000 --wait -o audio.mp3Options
Choose voice (alloy, echo, fable, onyx, nova, shimmer), model (tts-1, tts-1-hd), and output format (mp3, opus). Enable includeSummary for an AI-generated intro, or summaryOnly for a short summary without full narration.
Learn More
For full documentation, API reference, and advanced usage, see the PDF-to-Audio package docs. Also check the v0.2.0-beta.27 release for physical file storage and summary-only mode.