Overview
The audio visualizer creates a real-time visual representation of the audio frequency spectrum, displaying animated bars that respond to the recitation.The visualizer uses the Web Audio API to analyze audio in real-time and render frequency data as animated bars.
Enabling the Visualizer
The visualizer can be toggled on or off:- Desktop
- Mobile
Click the spectrum icon in the player controls to toggle the visualizer.The icon changes appearance:
- Colored icon - Visualizer is on
- Gray icon - Visualizer is off
Visualizer Component
The visualizer is implemented using react-audio-spectrum:Visualizer Features
Frequency Bars
Animated bars representing audio frequencies
Real-time Sync
Responds instantly to audio changes
Responsive Width
Adapts to screen size automatically
Color Customization
Blue theme (#0191e2) matching app design
Visual Specifications
Dimensions
- Height: 90 pixels (fixed)
- Width: Up to 400 pixels (responsive)
- Bar Width: 10 pixels
- Gap: 4 pixels between bars
Responsive Behavior
- Takes 80% of window width
- Maximum 400 pixels
- Recalculates on window resize
- Maintains aspect ratio
On mobile devices, the visualizer automatically shrinks to fit the screen while maintaining readability.
Color Scheme
- Bar Color
- Cap Color
#0191e2 - Bright blueThe main color of the frequency bars, chosen to match Open Tarteel’s brand colors.
Playback States
The visualizer responds to different playback states:When Visualizer is Disabled
When Paused
When Playing
Full visualizer renders with animated bars responding to audio frequencies.State Transitions
State Transitions
- Off → On: Visualizer fades in smoothly
- Paused → Playing: Bars animate from silence
- Playing → Paused: Bars drop to zero
- On → Off: Component unmounts, space collapses
Audio Analysis
The visualizer connects to the audio element:How It Works
- Audio Element - References the main audio player by ID
- Web Audio API - Creates an AnalyserNode to process audio
- FFT Analysis - Performs Fast Fourier Transform on audio data
- Frequency Data - Extracts frequency bins from analysis
- Visualization - Maps frequency data to bar heights
- Animation Loop - Updates at 60 FPS using requestAnimationFrame
The visualizer uses the Web Audio API’s AnalyserNode, which analyzes audio without affecting playback or quality.
Persistence
The visualizer setting is persisted across sessions:Storage Features
- LocalStorage Key:
show-visualizer - Default Value:
true(enabled by default) - Type: Boolean
- Persistence: Survives browser restarts
New users see the visualizer by default. Once toggled, the preference is remembered for all future sessions.
Integration with Player
The visualizer is integrated into the main player:- audioId: Reference to the audio element
- isPlaying: Current playback state
Player Layout
Visualizer appears:- Above player controls
- Below reciter selector (when visible)
- Centered horizontally
- With 0.5rem bottom margin
Toggle Control
The visualizer toggle button shows:Button States
Enabled
Colored spectrum icon, clickable
Disabled
Gray spectrum icon, clickable
While Playing
Reduced opacity, not clickable
Tooltip
Shows current state on hover
Performance
The visualizer is optimized for performance:Efficient Rendering
- Uses Canvas API for 60 FPS animation
- Minimal React re-renders
- Debounced resize handler
- Conditional rendering based on state
Resource Usage
- CPU: Low impact, uses GPU acceleration when available
- Memory: ~2-5 MB for audio analysis buffers
- Battery: Minimal impact on mobile devices
The visualizer automatically stops consuming resources when playback is paused or the visualizer is disabled.
Browser Compatibility
The visualizer requires Web Audio API support:- Supported
- Unsupported
- Chrome/Edge 35+
- Firefox 25+
- Safari 14.1+
- Opera 22+
- All modern mobile browsers
Customization
The visualizer appearance is controlled by props:Customizable Properties
Available Options
Available Options
- Height: Overall visualizer height in pixels
- Width: Overall visualizer width in pixels
- Cap Color: Peak indicator color (hex/rgb)
- Meter Width: Width of each frequency bar
- Meter Color: Color of frequency bars
- Gap: Spacing between bars in pixels
- Silent: Pause animation while maintaining display
To customize colors, modify the capColor and meterColor props in audio-bars-visualizer.tsx:51-52.
Accessibility
The visualizer is decorative and accessibility-friendly:- Hidden from screen readers (no semantic meaning)
- Doesn’t interfere with keyboard navigation
- Optional feature (can be disabled)
- No critical information displayed
- Color contrast not critical (decorative only)
Users who prefer reduced motion can disable the visualizer for a simpler, static interface.
Troubleshooting
Common Issues
Common Issues
Visualizer not showing?
- Check that it’s enabled in settings
- Verify audio is playing (not paused)
- Check browser Web Audio API support
- Try refreshing the page
- Ensure audio is actually playing
- Check audio source is valid
- Verify
silentprop is false - Look for console errors
- Try disabling visualizer on low-end devices
- Close other tabs consuming resources
- Update browser to latest version
- Check hardware acceleration is enabled