How whiskeycoder/qwen3-audiobook-converter works
Purpose and Entry Point
This is a local Python batch converter that turns documents into MP3 audiobooks through a locally running Qwen3 TTS Gradio service. The CLI entry point is audiobook_converter.py; it processes all supported source files placed under book_to_convert/ and writes finished audio to audiobooks/.
Paths: audiobook_converter.py, book_to_convert/input_here.txt, audiobooks/output_here.txt
Runtime and Dependencies
The application requires Python 3.8+, FFmpeg for audio encoding/assembly, and a Qwen Voice/Gradio server reachable locally at http://127.0.0.1:7860. Python dependencies support Gradio API calls, document parsing, and audio composition.
Paths: requirements.txt, config.py, audiobook_converter.py
CLI Mode Selection and Configuration
The converter operates in default custom-speaker narration mode or optional voice-clone mode, enabled with --voice-clone and a reference WAV via --voice-sample. Configuration centralizes Qwen endpoint/model and fixed audiobook-oriented settings such as speaker, language, chunk size, retries, sequential processing, MP3 format, and bitrate.
Paths: audiobook_converter.py, config.py
Input Discovery and Text Extraction
The batch pipeline discovers files in the input directory and extracts readable text based on extension. Supported boundaries are TXT, PDF, EPUB, DOCX, and legacy DOC; image-only or corrupted documents are expected to fail extraction rather than receive OCR. Extraction dependencies include PyPDF2, EbookLib/BeautifulSoup, python-docx, and docx2txt.
Paths: audiobook_converter.py, book_to_convert/input_here.txt, requirements.txt
Chunking and Synthesis Boundary
Extracted text is split into roughly 1,200-word units while preserving sentence boundaries. Chunks are processed sequentially (MAX_WORKERS=1) to avoid overloading or rate-limiting the local model. Each chunk crosses the principal external boundary: a Gradio client request to Qwen’s 1.7B TTS model; clone mode additionally relies on Qwen transcription of the reference audio.
Paths: audiobook_converter.py, config.py
Audio Assembly, Caching, and Recovery
Generated chunk audio is cached to avoid repeating identical synthesis work, retried on transient failures, then concatenated and encoded as a 128 kbps MP3 through pydub/FFmpeg. The final artifact is written per input book; intermediate chunk files are intended to be cleaned up even if a conversion fails.
Paths: audiobook_converter.py, audiobooks/output_here.txt, requirements.txt
Operational Outputs
The repository ships placeholder input/output directories and a sample text-to-MP3 artifact for validation. Runtime-created cache, chunk, and log directories are described by the project but are not present in this tree, so they are ephemeral operational state rather than versioned application components.
Paths: sample/test_audio.txt, sample/test_audio.mp3, README.md
Components 17
Runtime & Configuration
- Converter CLI · Batch-converts every supported input document.
audiobook_converter.py - TTS Configuration · Defines endpoint, model, narration, chunking, retry, and MP3 settings.
config.py - Python Dependencies
requirements.txt - Operational Documentation · Documents ephemeral cache, chunk, and log state.
README.md
Conversion Pipeline
- File Discovery · Finds supported source files in the input directory.
audiobook_converter.py - Text Extraction · Extracts TXT, PDF, EPUB, DOCX, and DOC text without OCR.
audiobook_converter.py - Sentence-Aware Chunking · Splits text into roughly 1,200-word units.
audiobook_converter.py - Narration Mode · Uses custom speaker by default or reference-WAV voice cloning.
audiobook_converter.py - Chunk Cache & Retries · Reuses synthesized chunks and retries transient failures.
audiobook_converter.py - Sequential Synthesis · Processes one chunk at a time to protect the local model.
audiobook_converter.py - Audio Assembly · Concatenates chunk audio and cleans intermediate files.
audiobook_converter.py
Inputs & Outputs
- Book Input Directory · Place supported books here for batch processing.
book_to_convert/input_here.txt - Audiobook Output Directory · Receives per-book 128 kbps MP3 outputs.
audiobooks/output_here.txt - Sample Text
sample/test_audio.txt - Sample MP3
sample/test_audio.mp3
Local Services & Tools
- Qwen3 TTS Gradio Server · Local Qwen 1.7B synthesis endpoint; clone mode also transcribes reference audio.
- FFmpeg · Encodes final audiobook audio.
Connections 18
- Converter CLI → TTS Configuration: loads
- Converter CLI → File Discovery: starts batch
- Book Input Directory → File Discovery: scans
- File Discovery → Text Extraction: supported files
- Text Extraction → Sentence-Aware Chunking: readable text
- TTS Configuration → Sentence-Aware Chunking: chunk settings
- Sentence-Aware Chunking → Narration Mode: text chunks
- Narration Mode → Chunk Cache & Retries: synthesis request
- Chunk Cache & Retries → Sequential Synthesis: cache miss or retry
- TTS Configuration → Sequential Synthesis: endpoint and model
- Sequential Synthesis → Qwen3 TTS Gradio Server: Gradio API request
- Qwen3 TTS Gradio Server → Sequential Synthesis: chunk audio
- Sequential Synthesis → Audio Assembly: generated chunks
- Audio Assembly → FFmpeg: MP3 encode
- FFmpeg → Audiobook Output Directory: 128 kbps MP3
- Sample Text → Sample MP3: example conversion
- Python Dependencies → Converter CLI: provides libraries
- Operational Documentation → Converter CLI: documents operation