A Node.js + Express application that creates an automatic AI DJ that can mix tracks from SoundCloud (no API credentials required) and your own uploaded music.
- No Authentication Required: Use SoundCloud music without needing API credentials
- User Registration: Simple signup with just name and email
- File Upload Support: Add your own music files to the mix
- AI Mixing: Intelligent track ordering and transition points based on BPM and other factors
- Mix Saving: Save your favorite mixes (Free tier: up to 5 mixes)
- Profile Management: Track your mixes and uploads
- Responsive Design: Works on desktop and mobile devices
- Dark/Light Theme: Switch between light and dark modes
- Backend: Node.js + Express
- Database: MongoDB for user data and session storage
- Audio Processing: music-metadata for file analysis
- SoundCloud Integration: Client ID extraction technique (no API required)
- Frontend: Vanilla JavaScript with EJS templating
- Styling: CSS with light/dark theming
- File Handling: Multer for file uploads
- Node.js (v14 or higher)
- npm or yarn package manager
- MongoDB (local or remote)
Use the all-in-one deployment script to setup and start the application:
./deploy.shThis script will:
- Run the setup process (install dependencies, configure environment)
- Start the server with network access enabled
Alternatively, you can run the setup and start processes separately:
./setup.shThe setup script will:
- Check for Node.js and npm installation
- Install or fix missing dependencies
- Create an .env file from sample.env (or create one if missing)
- Generate a random session secret
- Verify all required directories exist
For network access (recommended):
./network-start.shOr for local-only access:
npm startIf you prefer to set up manually:
- Clone the repository
git clone https://github.com/yourusername/djai.git
cd djai- Install dependencies
npm install- Create environment variables
Copy the sample.env file to .env:
cp sample.env .envEdit the .env file:
# MongoDB connection string
MONGODB_URI=mongodb://localhost:27017/djai
# Session secret (change this to a random string for security)
SESSION_SECRET=your_random_secret_string_change_this
# Port (optional, defaults to 3000)
PORT=3000
# File upload options
MAX_UPLOAD_SIZE=50 # In megabytes
- Run the application
Local development mode:
npm run devProduction mode:
npm startNetwork access mode (accessible from other devices on your LAN):
./network-start.shThe server will start at:
- Local access: http://localhost:3000
- Network access: http://YOUR_LOCAL_IP:3000 (displayed when using network-start.sh)
- Visit the homepage and enter your name and email
- No password is required - we keep it simple!
- You'll be immediately logged in and can start using the application
DJAI offers two ways to add music to your mix:
-
SoundCloud Search
- Search for tracks by name, artist, etc.
- Add SoundCloud tracks via direct URL
- No SoundCloud account or API credentials required
-
Upload Your Music
- Upload MP3, WAV, FLAC and other audio files
- Files are analyzed for BPM and other metadata
- Mix your uploaded tracks with SoundCloud tracks
- Add at least 2 tracks to your mix (from SoundCloud, your uploads, or both)
- Click "Generate AI Mix"
- The AI will analyze and arrange the tracks in an optimal order based on BPM
- View detailed information about the mix including transition points
- Use the advanced player to listen to your mix with automatic transitions
- Save your mix if you want to access it later
The DJAI player includes sophisticated audio mixing capabilities:
- Automatic Crossfading: Smooth transitions between tracks at optimized points
- Audio Visualizer: Real-time frequency visualization of the currently playing track
- Precise Controls: Play/pause, previous/next track controls, and seek functionality
- Track Progress: Visual progress bar with transition point markers
- Playlist Navigation: Easily navigate between tracks in your mix
- Track Highlighting: Currently playing track is highlighted in the track list
- Unified Audio Sources: Seamless mixing between uploaded files and SoundCloud tracks
- Unlimited saved mixes (Free tier: 5 mixes)
- Higher quality audio processing
- Advanced mixing options
- AI-generated continuous mixes
The application uses a technique to access SoundCloud's public API without requiring official API credentials:
- Client ID Extraction: Automatically extracts the client ID from SoundCloud's web player
- Search & Streaming: Enables searching and streaming tracks from SoundCloud
- URL Resolution: Allows adding tracks via SoundCloud URLs
- Caching: Client ID is cached and refreshed as needed
For uploaded audio files:
- Storage: Files are stored in user-specific directories
- Metadata Extraction: Tags, BPM, and other metadata are extracted
- Range Requests: Support for seeking within audio files
- Format Support: Multiple audio formats supported (MP3, WAV, FLAC, etc.)
The AI mixing algorithm:
- Track Analysis: Analyzes BPM and other characteristics
- Ordering: Arranges tracks in an optimal sequence
- Transition Points: Calculates where tracks should blend together
- BPM Matching: Orders tracks to minimize BPM differences between consecutive tracks
The DJAI player uses advanced Web Audio API techniques for professional-quality mixing:
- Web Audio API: Creates a dynamic audio graph with multiple sources and gain nodes
- Crossfading Engine: Implements precise volume curves for smooth transitions
- Audio Analysis: Real-time frequency analysis for visualization
- Multi-source Management: Handles both local uploads and streaming sources seamlessly
- Error Resilience: Robust error handling for network interruptions and streaming issues
- Range Requests: Supports seeking within audio files using HTTP range requests
- Adaptive Buffering: Pre-loads upcoming tracks to ensure smooth transitions
/api/user/register- Register new user (POST)/api/user/profile- Get user profile (GET)/api/user/saved-mixes- Get user's saved mixes (GET)/api/user/save-mix- Save a new mix (POST)/api/user/logout- Log out (POST)
/api/upload/track- Upload a new track (POST)/api/upload/tracks- List user's uploaded tracks (GET)/api/upload/stream/:trackId- Stream an uploaded track (GET)
/api/soundcloud/search- Search for tracks (GET)/api/soundcloud/resolve- Resolve a SoundCloud URL (GET)/api/soundcloud/stream/:trackId- Stream a SoundCloud track (GET)/api/soundcloud/generate-mix- Generate a mix from track IDs (POST)
DJAI can be run on your local network, allowing other devices (phones, tablets, computers) to access the DJ application:
-
Run the provided network script:
./network-start.sh
-
The script will:
- Display all available network IP addresses for your machine
- Start the server on all network interfaces
- Show the URLs you can use to access the app
-
Access from other devices:
- Use the displayed network URL (e.g.,
http://192.168.1.5:3000) from any device on your LAN - Works with phones, tablets, and other computers
- Use the displayed network URL (e.g.,
The DJAI player uses a custom AudioMixer class that handles all aspects of audio playback and visualization. Here's how you can customize or extend the player:
-
AudioMixer Class: Located in the main
index.ejsfile, this class handles:- Audio element creation and management
- Web Audio API node creation and connection
- Transitions and crossfading
- Visualization
- UI updates and controls
-
Initialization:
// Initialize with mix data function initializeMixPlayer(mixData) { if (!mixer) { mixer = new AudioMixer(); } mixer.initialize(mixData); // Auto-start mixer.play(); }
-
Crossfade Configuration:
- Modify the
transitionTimeproperty (default: 5000ms) to adjust crossfade duration
// In the AudioMixer constructor this.transitionTime = 5000; // Crossfade duration in ms
- Modify the
-
Visualizer Customization:
- The
drawVisualizer()method can be modified to change the appearance - Adjust the canvas dimensions, bar colors, animation style, etc.
- The
-
Adding Effects:
- Add audio effects by modifying the
createAudioElements()method - Insert additional AudioNodes in the connection chain
// Example: Adding a compressor effect const compressor = this.audioContext.createDynamicsCompressor(); source.connect(compressor); compressor.connect(gainNode);
- Add audio effects by modifying the
The streaming routes include robust error handling that you can further extend:
- Client-side: In the
AudioMixerclass, error handlers are attached to audio elements - Server-side: Both upload and SoundCloud streaming routes include:
- Range request validation
- Stream error handling
- Client disconnect handling
- Timeout handling
MIT