AI-powered mixtape creator that analyzes audio files and crafts perfect track sequences
Project description
๐ต Mixtaper
AI-powered mixtape creator that turns a directory of music files into a flowing track sequence, suitable for a personal mixtape. Using advanced audio analysis and machine learning, it arranges tracks based on musical characteristics like tempo, key, energy, and rhythm to create flowing mixtapes.
Features
- ๐ต Audio Analysis: Extracts tempo, key, energy, brightness, and rhythm complexity from MP3, FLAC, WAV, M4A, and OGG files
- ๐ฏ Smart Ordering: Uses weighted transition scoring to create optimal track sequences
- ๐จ AI Artwork: Generate album artwork using OpenAI DALL-E based on musical analysis
- ๐ Multi-CD Support: Automatically splits large collections across multiple CDs with natural break points
- ๐ท๏ธ Metadata Management: Updates ID3v2/FLAC tags with album info, track numbers and ReplayGain
- ๐ญ Genre Detection: Looks up accurate genres using MusicBrainz database
- โก Multithreaded: Fast analysis using parallel processing
- ๐ฅ๏ธ Rich UI: Beautiful command-line interface with progress indicators
Rationale and Overview
This project was created using Claude Code. I wanted to quickly whip up something that will formalize and automate how I created "mixtapes" for myself. I prefer creating my own compilation albums versus creating playlist files (e.g. m3u). I do so by creating a new subdirectory under my Music directory, dumping a dozen or so pre-selected music files into it, ordering them, generating cover art with an AI image generator, updating their ID3 tags and renaming them in the chosen order. I mostly create mixtapes based on certain moods, so that I can quickly choose a playlist based on what I want to hear. I find that music collection managers that have "mood" as a filter work terribly.
The only problem is choosing a good order for the songs. It always takes too
long and I don't want every mixtape to turn into some ridiculous project. So I
created mixtaper to make this process quicker. I can now just dump the files
into a directory and let the program do everything for me:
- Analyze the songs for things like tempo, key, energy, etc.
- Choose an ordering for the songs that will "flow well" based on the analysis.
- Generate cover art via OpenAI DALL-E (or select an existing
^(cover|front)\.(png|jpg)$image in the directory). - Calculate ReplayGain values for the tracks individually and the album as a whole.
- Set relevant ID3 tags for the files.
- Rename the files with the format "<TRACK_NUMBER>. - <TITLE>".
I also added support for multi-CD mixtapes. mixtaper will recommend a number of
CDs if it finds that the directory contains "more songs than common in albums",
and prefix the files with the disc number, so, "<DISC_NUMBER><TRACK_NUMBER>. - <TITLE>".
This is an early release. I decided to let Claude Code implement this and see
how it goes. For now, it seems to work quite nicely. My biggest issue right now
is how to craft a good prompt for the cover art generation. The current prompt
generator isn't good, but prompts can be edited. The ordering mixtaper creates
could be better, but I'm fine with it for now. I can always tinker with the
parameters and re-run.
By default, mixtaper works interactively, asking you questions and also for
confirmation. You can pre-answer questions via command line flags, or opt for
completely automatic, non-interactive execution. Information later on.
Installation
mixtaper is a command line utility written in Python and distributed via PyPI.
It is recommended to install it via a utility such as pipx:
pipx install mixtaper
You can also install it directly through pip:
python3 -m pip install mixtaper
Usage
Basic Usage
# Interactive mode - prompts for configuration
mixtaper /path/to/music
# Automatic mode with smart defaults
mixtaper /path/to/music --auto
# Preview without making changes
mixtaper /path/to/music --dry-run
Advanced Options
# Generate AI artwork (requires OpenAI API key)
export OPENAI_API_KEY="your-api-key"
mixtaper /path/to/music --ai-art
# Preset album information
mixtaper /path/to/music --title "My Mixtape" --artist "DJ Name" --year 2024
# Preselect number of CDs
mixtaper /path/to/music --num-cds 2
# Predefine AI artwork prompt
mixtaper /path/to/music --ai-art --ai-prompt "Abstract digital art with neon colors"
# Performance tuning
mixtaper /path/to/music --threads 8
Command-Line Options
| Option | Description |
|---|---|
--title |
Album title (default: directory name) |
--artist |
Album artist (default: Various Artists) |
--year |
Release year (default: current year) |
--num-cds |
Number of CDs to create (default: auto-suggest) |
--ai-art |
Generate AI artwork using DALL-E |
--ai-prompt |
Custom prompt for AI artwork generation |
--auto |
Automatic mode - no interactive prompts |
--dry-run |
Preview operations without making changes |
-y, --yes |
Automatically confirm all prompts |
--threads |
Number of analysis threads (default: 4) |
How It Works
1. Audio Analysis
The tool analyzes each audio file to extract:
- Tempo: BPM detection for rhythmic continuity
- Key: Chromatic feature analysis for harmonic compatibility
- Energy: RMS levels for dynamic flow management
- Brightness: Spectral centroid for tonal continuity
- Rhythm Complexity: Onset density analysis
2. Track Optimization
Uses a weighted scoring algorithm for track transitions:
- Tempo similarity: 30%
- Key compatibility: 20%
- Energy flow: 25%
- Brightness continuity: 15%
- Rhythm complexity: 10%
3. Metadata Enhancement
- Reads existing Artist/Title from file metadata
- Looks up accurate genres via MusicBrainz API
- Updates all files with consistent album information
- Adds ReplayGain tags for volume normalization
- Embeds album artwork in file metadata
4. File Organization
- Renames files to format: "01. Artist - Title.ext"
- For multi-CD sets: "201. Artist - Title.ext" (CD 2, Track 1)
- Safe renaming with conflict resolution
- Preserves original files if errors occur
Directory Structure
The project uses a modular architecture for maintainability:
mixtaper/
โโโ __init__.py # Package exports
โโโ config.py # Configuration and data classes
โโโ audio_analyzer.py # Audio analysis using librosa
โโโ metadata_manager.py # ID3v2/FLAC metadata handling
โโโ musicbrainz_client.py # MusicBrainz API integration
โโโ artwork_generator.py # AI artwork generation
โโโ mixtape_optimizer.py # Track ordering algorithms
โโโ tui.py # Rich-based user interface
โโโ cli.py # Command-line interface
Development
Running Tests
# Install development dependencies
uv sync --dev
# Run all tests
uv run python run_tests.py
# Or use pytest directly
uv run pytest tests/ -v
Code Quality
# Format code
uv run ruff format .
# Lint code
uv run ruff check .
Testing with Sample Files
# Test with audio files
uv run mixtaper.py /path/to/test/audio/files
# Test AI artwork (requires OpenAI API key)
export OPENAI_API_KEY="your-api-key"
uv run mixtaper.py /path/to/music --ai-art --dry-run
Requirements
System Dependencies
- Python 3.8+
- FFmpeg (for audio format support)
Python Dependencies
- librosa: Audio analysis and feature extraction
- mutagen: Audio metadata reading/writing
- rich: Beautiful command-line interface
- numpy/scipy: Numerical computations
- openai: AI artwork generation (optional)
- requests: HTTP client for API calls
Optional
- OpenAI API Key: For AI artwork generation
- MusicBrainz: Free genre lookup (no API key required)
Examples
Example Output
โโโ Mixtaper โโโ
Processing: /music/Various Artists - 2024 - New Wave Mix
โโโ Audio Analysis โโโ
[1/13] Analyzing: 04. The Cure - Boys Don't Cry.flac
[2/13] Analyzing: 03. Don Henley - The Boys Of Summer.flac
...
โโโ Genre Lookup โโโ
[1/13] The Cure - Boys Don't Cry
Genre: alternative rock
[2/13] Don Henley - The Boys Of Summer
Genre: classic rock
...
โโโ Suggested Track Order โโโ
01. Crowded House - Don't Dream It's Over [alternative rock] (82 BPM, Energy: 0.17)
02. A-Ha - Take on Me [dance-pop] (85 BPM, Energy: 0.18)
03. Don Henley - The Boys Of Summer [classic rock] (89 BPM, Energy: 0.16)
...
โ Mixtape organization complete!
โข 13 tracks processed
โข 1 CD created
โข Metadata and ReplayGain tags updated
โข Album artwork preserved
Directory Structure Example
Various Artists - 2024 - New Wave Mix/
โโโ cover.jpg # Album artwork
โโโ 01. Crowded House - Don't Dream It's Over.flac
โโโ 02. A-Ha - Take on Me.flac
โโโ 03. Don Henley - The Boys Of Summer.flac
โโโ ...
License
Apache License 2.0 - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
uv run python run_tests.py - Submit a pull request
Support
- Report issues: GitHub Issues
- Documentation: See
CLAUDE.mdfor development details - Examples: Check the
tests/directory for usage examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mixtaper-0.1.0.tar.gz.
File metadata
- Download URL: mixtaper-0.1.0.tar.gz
- Upload date:
- Size: 178.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73405874b3de07a3155cb014c54b9ffd34862c953f44f69038326e97f4850ebc
|
|
| MD5 |
10564d06a1133fe155e2626e8f8ca268
|
|
| BLAKE2b-256 |
4b2c5dbcc65f0c0d812049da1cdfe1d39259f73539d78dcfe8e0cc7663844165
|
File details
Details for the file mixtaper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mixtaper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 200.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86ed4d6e6d1719b6e82992d5a5197ba0b3c9ff51635bb0a11d202a418c4818c2
|
|
| MD5 |
be226060ad845be705e398e8d3c84771
|
|
| BLAKE2b-256 |
5974d374bf681f8e3c0fce292650a264f89d2ed660b4e3547bc9d2ab54304aaa
|