Skip to content

finbar001/AudioBookAuto2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AudioBook Auto - Just-in-Time EPUB Narrator

A static web application that converts EPUB books into audiobooks using OpenAI's TTS-1 model with intelligent just-in-time chunk generation.

Features

  • 📚 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

How It Works

The app uses a three-chunk pipeline:

  1. Chunk N (Currently Playing): The audio you're currently hearing
  2. Chunk N+1 (Generating): Being generated in the background while N plays
  3. 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.

Usage

1. Get Your OpenAI API Key

  1. Go to OpenAI API Keys
  2. Create a new API key
  3. Copy it for use in the app

2. Open the Application

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

3. Upload an EPUB

  1. Enter your OpenAI API key in the field at the bottom
  2. Click "Choose File" and select your EPUB file
  3. Wait for the app to parse the book

4. Select Starting Point

  • Choose which chapter/section to start from
  • This lets you skip title pages, table of contents, etc.
  • Click "Start Narration"

5. Listen and Control

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

Cost Estimation

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)

Technical Details

Dependencies

The app loads one external library:

  • JSZip (for EPUB parsing) - loaded from CDN when needed

Browser Compatibility

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)

File Structure

AudioBookAuto2/
├── index.html      # Main HTML structure
├── app.js          # Application logic
├── styles.css      # Styling
└── README.md       # This file

How EPUB Parsing Works

The app:

  1. Unzips the EPUB file (which is just a ZIP archive)
  2. Finds all HTML content files
  3. Extracts text from <h1>, <h2>, <p> and other content tags
  4. Filters out navigation, metadata, and other non-content files
  5. Combines into a linear reading flow

Chunking Algorithm

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

Audio Generation Pipeline

User clicks Play
    ↓
Generate Chunk N (wait)
    ↓
Play Chunk N → Start generating N+1
    ↓
N ends → Play N+1 → Start generating N+2
    ↓
Repeat...

Customization

You can easily modify:

Voice Selection (in app.js, TTSClient class):

voice: 'alloy' // Options: alloy, echo, fable, onyx, nova, shimmer

Speaking Speed (in app.js, TTSClient class):

speed: 1.0 // Range: 0.25 to 4.0

Chunk Duration (in app.js, AudioBookApp.startNarration):

const chunker = new TextChunker(fullText, 30); // Change 30 to desired seconds

Troubleshooting

"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

Privacy & Security

  • 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

License

This is a personal project. Feel free to modify and use as needed.

Future Enhancements

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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published