A complete pipeline that automatically converts book PDFs into clean, readable websites with optional synchronized audio highlighting. Built collaboratively with Claude Code over ~1 month.
Live Demo: meremetaphor.com
An automated system that takes a raw PDF export from Apple Pages and generates a clean, readable website:
- Intelligent text extraction with proper paragraph detection
- Image extraction with transparency mask handling (14 illustrations)
- Chapter structure recognition and table of contents generation
- Typography optimization for web reading
Added synchronized word-by-word audio highlighting:
- 35+ minutes of voice memo recordings processed automatically
- 4,019 words transcribed with precise timestamps
- 94% automatic word matching with smart edge case handling
- Speed controls and mobile optimization
The Key Insight: Most of the complexity was in the PDF processing foundation. Audio was surprisingly straightforward once we had clean HTML structure.
PDF Processing: The Hidden Complexity
Converting a PDF to clean HTML turned out to be surprisingly complex:
Challenge 1: Text Structure Recognition
- PDFs have no semantic structure - just positioned text fragments
- Had to infer paragraphs, headings, and chapters from font sizes and positioning
- Solution: Heuristic analysis of line lengths and text patterns
Challenge 2: Image Extraction with Transparency
- PDF contains 14 illustrations with complex transparency masks
- Standard extraction tools failed or produced poor quality
- Solution: Custom pipeline preserving transparency and optimizing file sizes
Challenge 3: Chapter Detection
- No structural markers in PDF for chapter boundaries
- Needed to identify chapter titles, generate IDs, create navigation
- Solution: Pattern matching on title formatting and content analysis
Challenge 4: Typography for Web
- PDF formatting doesn't translate well to responsive web design
- Needed proper heading hierarchy, readable line lengths, mobile optimization
- Solution: CSS-based typography system with semantic HTML structure
Once we had clean HTML structure, audio became much simpler:
Sequential Word Mapping Innovation
Traditional: PDF → HTML → Audio → Try to Match (fails)
Our Approach: PDF + Audio → Generate HTML with Audio Spans (works)
Why This Works: We consume transcription words sequentially during HTML generation, avoiding complex alignment algorithms.
- PDF Processing:
pdf-parselibrary for text extraction - Audio Transcription: OpenAI Whisper API with word-level timestamps
- Audio Processing: FFmpeg with custom noise reduction pipeline
- Build System: Single Node.js script with sequential word mapping
- Deployment: GitHub Pages with automated builds
Raw .m4a recordings
↓ FFmpeg gentle gate filter
.mp3 files with noise reduction
↓ Combine with optimal bitrate
book_audio.mp3 (24MB, under API limits)
↓ OpenAI Whisper transcription
4,019 words with precise timestamps
↓ Sequential mapping during HTML generation
index.html with synchronized <span> elements
Problem: Whisper sometimes assigns identical timestamps to consecutive words Solution: Intelligent timestamp expansion based on word length (0.04s per character, 0.3s minimum)
Problem: "3rd" in text vs "third" in audio, name variations Solution: Custom normalization with special cases:
if (new_word === "rd") new_word = "third" // "3rd" → "third"
if (new_word.includes("steiner")) new_word = "bredensteiner"Problem: 35+ minutes of audio exceeded OpenAI's 26MB transcription limit Solution: Optimized bitrate (96k vs 128k) with negligible quality loss for speech
Problem: Speed toggle button triggered zoom on rapid tapping Solution: Comprehensive touch prevention:
speedBtn.addEventListener('touchstart', function(e) {
e.preventDefault();
e.stopPropagation();
}, {passive: false});Problem: Raw voice memos had background noise, inconsistent levels Solution: Standardized FFmpeg gentle gate filter:
ffmpeg -i input.m4a -af "agate=threshold=0.05:ratio=1.5:attack=5:release=200"
-codec:a libmp3lame -b:a 128k output.mp3- Starts with raw PDF export (not clean structured data)
- Automatically infers document structure from visual formatting
- Handles real-world messiness: inconsistent spacing, mixed fonts, embedded images
- Produces semantic HTML from visual-only input
- Zero manual intervention from PDF to finished website
- Handles both text extraction and image processing
- One command builds entire experience (with or without audio)
- Smart defaults with edge case handling
- Core functionality: Clean, readable website from PDF
- Enhancement layer: Synchronized audio highlighting
- Degrades gracefully: Works without JavaScript, works without audio
- Mobile-first design with speed controls and touch optimization
- Uses actual voice memo recordings (not studio quality)
- Handles background noise, breathing, natural speech patterns
- Still achieves 94% word matching accuracy
- Processes 35+ minutes of audio automatically
- Built through experiments, keeping what worked
- Frequent commits documenting problem-solving process
- Each iteration solved specific technical challenges
- Human insight + AI capability solving complex problems
pdf-parselibrary: Reliable text extraction from complex PDFs- Heuristic structure detection: Simple rules worked better than ML approaches
- Sequential word mapping: Much simpler than traditional forced alignment
- OpenAI Whisper: Excellent accuracy for natural speech
- Gentle gate audio filtering: Effective noise reduction without artifacts
- GitHub Pages: Zero-config deployment for static sites
- PDF structure inference: No semantic info, had to guess from visual formatting
- Image extraction complexity: Transparency masks and quality optimization
- Cross-browser compatibility: Especially iOS Safari touch handling
- API limits: Had to optimize for external service constraints (26MB)
- Word boundary edge cases: "3rd" vs "third", name variations
- Build-time processing: Generate static files rather than runtime processing
- Progressive enhancement: PDF→HTML works standalone, audio enhances
- Single combined audio file: Simpler than per-chapter synchronization
- Generate don't retrofit: Core insight for both PDF and audio processing
- Minimal dependencies: Only essential tools (pdf-parse, openai, ffmpeg)
scripts/build.js # Main build script with sequential mapping
scripts/transcribe-audio.js # OpenAI Whisper integration
meremetaphor.pdf # Source content
book_audio.mp3 # Combined audio (96k, 24MB)
book_audio_transcription.json # 4,019 words with timestamps
index.html # Generated synchronized webpage
npm installnpm run build- Open
index.html
The build process is completely automated - given the PDF and audio files, it generates the entire synchronized experience.
- PDF Structure Inference: Automatically extracts semantic meaning from visual-only PDFs
- Image Processing Pipeline: Handles complex transparency masks and optimization
- Audio-Text Synchronization: 94% accuracy with real-world voice recordings
- Cross-Platform Compatibility: Works on desktop, mobile, with accessibility considerations
- Simple solutions often work best: Heuristics beat complex algorithms for this domain
- Progressive enhancement: Build solid foundation first, add features second
- Real-world testing matters: iOS Safari taught us things desktop never would
- AI pair programming: Human domain knowledge + AI implementation = powerful combination
This approach could work for:
- Technical documentation (API docs → interactive guides)
- Educational content (textbooks → multimedia experiences)
- Legal documents (contracts → searchable, navigable formats)
- Any PDF-first content that needs web distribution
Built collaboratively with Claude Code - demonstrating how human creativity and AI capability can solve complex problems that neither could tackle alone.