A sophisticated web application that converts PDF documents into interactive audiobooks with click-to-play functionality. Upload any PDF, and click on any word to start listening from that position with high-quality text-to-speech.
- Smart PDF Text Extraction: Dual-engine text extraction using both
pdfplumberandPyPDF2for maximum compatibility - Interactive Click-to-Play: Click any word in the extracted text to start audio playback from that exact position
- On-Demand Audio Generation: Audio is generated in real-time using Microsoft Edge TTS as you navigate through the text
- Pattern Detection & Filtering: Automatically detect and optionally skip repeated headers, footers, and page numbers during playback
- Multiple High-Quality Voices: Choose from 6 different neural voices including Andrew, Jenny, Aria, Guy, and Christopher
- Real-Time Visual Feedback: Current word highlighting and chunk-based progress tracking during playback
- Modern Web Interface: Beautiful, responsive UI built with Tailwind CSS and Lucide icons
- Drag & Drop Upload: Easy PDF upload with visual feedback
- Floating Audio Controls: Sticky audio player that follows you as you scroll
- Smart Content Filtering: Toggle to skip repetitive content like headers and footers
- Large File Support: Handles PDFs up to 100MB in size
- Word-Level Navigation: Precise control over audio playback position
- RESTful API: Clean API endpoints for PDF processing and audio generation
- Chunked Processing: Intelligent text chunking for optimal performance (100-word chunks)
- Base64 Audio Streaming: Efficient audio delivery without file storage
- Docker Support: Complete containerization with Docker and docker-compose
- Environment Configuration: Flexible configuration via environment variables
- Python 3.7 or higher
- pip (Python package installer)
-
Clone and Navigate
git clone <your-repo-url> cd ebook-reader
-
Set Up Virtual Environment
For Fish shell users:
python -m venv venv source venv/bin/activate.fishFor Bash/Zsh users:
python -m venv venv source venv/bin/activate -
Install Dependencies
pip install -r requirements.txt
-
Configure Environment (Optional) Create a
.envfile in the project root:# .env DEBUG=True HOST=0.0.0.0 PORT=8000 SECRET_KEY=your-secret-key-here -
Run the Application
python app.py
Access the application at:
http://localhost:8000
docker-compose up --builddocker build -t ebook-reader .
docker run -p 8000:8000 ebook-reader- Upload PDF: Drag and drop or click to select a PDF file
- Choose Voice: Select from 6 available neural voices (Andrew is recommended)
- Configure Settings: Toggle "Skip Headers/Footers" to filter out repetitive content
- Interactive Reading: Click any word to start audio playbook from that position
- Control Playback: Use the floating audio controls to pause, resume, or navigate
The application includes intelligent pattern detection to improve the listening experience:
- Automatic Detection: Identifies repeated headers, footers, and page numbers across the document
- Smart Filtering: Uses spatial analysis and frequency detection to find patterns that appear on multiple pages
- Optional Feature: Toggle on/off via the "Skip Headers/Footers" control in the audio player
- Conservative Approach: Only filters content that appears consistently across multiple pages to avoid removing important text
- Real-time Feedback: Shows how many words were filtered when the feature is enabled
Pattern Types Detected:
- Headers: Text in the top 15% of pages that repeats across multiple pages
- Footers: Text in the bottom 15% of pages that repeats across multiple pages
- Page Numbers: Numeric text in corner positions
- Running Headers: Consistent text in the same position across consecutive pages
Premium Quality:
- Heart (Female) β - Grade A: Premium American English female voice
- Bella (Female) - Grade A-: High-quality warm female voice
High Quality:
- Nicole (Female) - Grade B-: Headphone-optimized female voice
Good Quality:
- Sarah (Female) - Grade C+: Natural female voice
- Aoede (Female) - Grade C+: Smooth female voice
- Kore (Female) - Grade C+: Clear female voice
- Michael (Male) - Grade C+: Strong male voice
- Fenrir (Male) - Grade C+: Deep male voice
- Puck (Male) - Grade C+: Energetic male voice
Additional Voices:
- Alloy, Nova, Sky, Jessica, River (Female)
- Echo, Eric, Liam, Onyx, Santa, Adam (Male)
High Quality:
- Emma (Female) - Grade B-: High-quality British English female voice
Good Quality:
- Isabella (Female) - Grade C: Refined British English female voice
- George (Male) - Grade C: Distinguished British English male voice
- Fable (Male) - Grade C: Narrative British English male voice
Additional Voices:
- Alice, Lily (Female)
- Lewis, Daniel (Male)
All voices support phoneme-based generation with proper EN-US or EN-GB pronunciation.
Endpoint: POST /api/upload
Request: Multipart form data with PDF file
curl -X POST -F "file=@document.pdf" http://localhost:8000/api/uploadResponse:
{
"text": "Extracted text content...",
"filename": "document.pdf",
"text_length": 12345
}Endpoint: POST /api/generate-audio
Request:
{
"text": "Text to convert to speech",
"model": "kokoro-af-heart"
}Response:
{
"success": true,
"audio_data": "base64-encoded-audio-data",
"sample_rate": 24000,
"duration": 5.23,
"text": "Original text",
"voice_used": "Andrew (Neural)"
}| Variable | Default | Description |
|---|---|---|
DEBUG |
True |
Enable debug mode |
HOST |
0.0.0.0 |
Server host address |
PORT |
8000 |
Server port |
SECRET_KEY |
Auto-generated | Flask secret key |
- Max PDF Size: 100MB
- Max Text Length: 2 million characters
- Audio Chunk Size: 100 words
- Sample Rate: 24kHz
ebook-reader/
βββ app.py # Main Flask application
βββ config.py # Configuration and voice models
βββ requirements.txt # Python dependencies
βββ templates/
β βββ index.html # Web interface
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ README.md # This file
- Flask: Web framework and API server
- pdfplumber: Primary PDF text extraction
- PyPDF2: Fallback PDF text extraction
- Kokoro: High-quality neural Text-to-Speech
- soundfile: Audio file processing
- numpy: Numerical operations for audio
Edit config.py and add new voice configurations to AVAILABLE_MODELS:
'new-voice-key': {
'name': 'Voice Name',
'description': 'Voice description',
'voice_id': 'kokoro-voice-id',
'lang_code': 'a', # Language code (a=American English)
'speed': 'Real-time streaming',
'sample_rate': 24000,
'type': 'kokoro'
}MIT License - see LICENSE file for details
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
- Audio not playing: Check browser audio permissions and volume
- PDF upload fails: Ensure PDF is not corrupted and under 100MB
- Voice not loading: Verify internet connection for Edge TTS service
- Virtual environment issues: Make sure you're using the correct activation script for your shell
For issues and questions, please create an issue in the repository with:
- Operating system and version
- Python version
- Error messages or logs
- Steps to reproduce the problem