A static web application that converts EPUB books into audiobooks using OpenAI's TTS-1 model with intelligent just-in-time chunk generation.
- 📚 EPUB Parsing: Automatically extracts and parses EPUB content
- 🎯 Smart Chunking: Splits text into ~30-second chunks at natural paragraph breaks
- 🔊 OpenAI TTS-1: High-quality text-to-speech narration
- ⚡ Just-in-Time Generation: Only generates audio for chunks you actually listen to
- 💾 Intelligent Caching: Generated audio is cached to avoid re-generation
- 🎮 Seamless Playback: N, N+1, N+2 chunk pipeline ensures no gaps in playback
- 📱 Responsive Design: Works on desktop and mobile devices
- 🔒 Privacy-First: Your API key is stored locally and never sent anywhere except OpenAI
The app uses a three-chunk pipeline:
- Chunk N (Currently Playing): The audio you're currently hearing
- Chunk N+1 (Generating): Being generated in the background while N plays
- Chunk N+2 (Waiting): Queued up next
When chunk N finishes:
- Chunk N+1 immediately starts playing (already generated)
- Chunk N+2 begins generating
- The cycle continues seamlessly
This means you only pay for the audio you actually listen to, with no perceivable gaps in playback.
- Go to OpenAI API Keys
- Create a new API key
- Copy it for use in the app
Simply open index.html in a web browser. No server required!
You can also host it on any static site hosting service:
- GitHub Pages
- Netlify
- Vercel
- AWS S3
- Or even run it locally on your phone
- Enter your OpenAI API key in the field at the bottom
- Click "Choose File" and select your EPUB file
- Wait for the app to parse the book
- Choose which chapter/section to start from
- This lets you skip title pages, table of contents, etc.
- Click "Start Narration"
Use the playback controls:
▶️ Play/⏸️ Pause: Start or pause narration- ⏮️ Previous: Go back to previous chunk
- ⏭️ Next: Skip to next chunk
- ⏹️ Stop: Stop playback and reset
The UI shows:
- 🔊 Currently Playing: The chunk being narrated now
- ⚙️ Generating: The next chunk being prepared
- ⏳ Up Next: The following chunk in queue
- Full text below with current position highlighted
OpenAI TTS-1 pricing: $15.00 per 1M characters
For a typical novel:
- Average novel: ~300,000 words = ~1.5M characters
- Cost to narrate entire book: ~$22.50
- Cost per 30-second chunk: ~$0.03-0.05
Since you only pay for what you listen to, you can:
- Sample different books without committing to full narration
- Skip sections you don't want to hear
- Resume later without re-generating previous chunks (they're cached)
The app loads one external library:
- JSZip (for EPUB parsing) - loaded from CDN when needed
Works in all modern browsers that support:
- ES6+ JavaScript
- Web Audio API
- File API
- Local Storage
Tested on:
- Chrome/Edge
- Firefox
- Safari
- Mobile browsers (iOS Safari, Chrome Mobile)
AudioBookAuto2/
├── index.html # Main HTML structure
├── app.js # Application logic
├── styles.css # Styling
└── README.md # This file
The app:
- Unzips the EPUB file (which is just a ZIP archive)
- Finds all HTML content files
- Extracts text from
<h1>,<h2>,<p>and other content tags - Filters out navigation, metadata, and other non-content files
- Combines into a linear reading flow
Text is split into chunks based on:
- Target duration: 30 seconds (configurable)
- Speaking rate: ~2.5 words per second (150 words/minute)
- Natural breaks: Always splits at paragraph boundaries
- Never breaks mid-paragraph
User clicks Play
↓
Generate Chunk N (wait)
↓
Play Chunk N → Start generating N+1
↓
N ends → Play N+1 → Start generating N+2
↓
Repeat...
You can easily modify:
Voice Selection (in app.js, TTSClient class):
voice: 'alloy' // Options: alloy, echo, fable, onyx, nova, shimmerSpeaking Speed (in app.js, TTSClient class):
speed: 1.0 // Range: 0.25 to 4.0Chunk Duration (in app.js, AudioBookApp.startNarration):
const chunker = new TextChunker(fullText, 30); // Change 30 to desired seconds"Invalid API Key" error
- Make sure your OpenAI API key is correct
- Check that your OpenAI account has available credits
Audio not playing
- Check browser console for errors
- Ensure your browser allows audio playback
- Try clicking play again after the first chunk generates
EPUB not loading
- Make sure the file is a valid EPUB format
- Try a different EPUB file to test
- Check browser console for parsing errors
Chunks not generating in background
- Check your internet connection
- Verify your OpenAI API key has sufficient credits
- Look for rate limiting messages in console
- Your OpenAI API key is stored in browser Local Storage only
- No data is sent to any server except OpenAI's TTS API
- Generated audio is cached in browser memory (cleared on page refresh)
- All processing happens client-side in your browser
This is a personal project. Feel free to modify and use as needed.
Potential improvements:
- Save playback position (resume where you left off)
- Export generated audio chunks as MP3 files
- Adjust voice and speed on the fly
- Bookmarks and notes
- Multiple voice support for dialogue
- Persistent audio cache (IndexedDB)
- Background audio generation (Service Worker)