DJGPT is an interactive AI music assistant that uses OpenAI's GPT-4 to recommend music on Spotify based on natural language requests. Simply tell DJGPT what you're in the mood for, and it will suggest and play tracks that match your request, creating a personalized DJ experience right from your command line.
With DJGPT, you can:
- Request music using natural language (e.g., "Play me something that feels like a summer road trip")
- Get contextual music recommendations with explanations of why each track was selected
- Control playback through voice commands
- Discover new music tailored to your specific preferences or mood
DJGPT combines several powerful technologies to create a seamless music discovery experience:
- Uses OpenAI's GPT-4 to understand your music requests and generate contextually relevant recommendations
- Integrates with Spotify to search for and play the recommended tracks
- Provides a voice interface using speech recognition and text-to-speech for hands-free interaction
- Offers a rich CLI experience with Typer and Rich libraries
- Python 3.11+
- Spotify Premium account
- OpenAI API key
- macOS, Linux, or Windows (best experience on macOS)
Clone the repository:
git clone https://github.com/MattOates/djgpt.git cd djgpt
Set up the environment using pixi (recommended) or conda:
Using pixi:
pixi install
Using conda:
conda env create --file=environment.yml -n djgpt conda activate djgpt
Create a
.env
file in the project root with your API credentials:SPOTIPY_CLIENT_ID=your_spotify_client_id SPOTIPY_CLIENT_SECRET=your_spotify_client_secret OPENAI_API_KEY=your_openai_api_key
To obtain these credentials:
- Spotify: Create an app in the Spotify Developer Dashboard and copy the Client ID and Client Secret
- OpenAI: Generate an API key at OpenAI API Keys
Start the application:
# If using pixi
pixi run start
# If using conda
python -m djgpt
On first run, you'll be prompted to authorize the application with Spotify in your browser.
Once running, DJGPT will:
- Ask what kind of music you want to listen to
- Wait for your voice response (or you can type if speech recognition fails)
- Process your request through GPT-4
- Present a list of recommended tracks with explanations
- Ask which track(s) you'd like to play
- Play your selection on your active Spotify device
- Voice Commands:
- Say "all" to play all recommended tracks
- Say "none" to skip and make a new request
- Say "stop" to exit the application
djgpt/
├── src/djgpt/ # Main package
│ ├── __main__.py # Entry point
│ ├── cli.py # CLI interface
│ ├── prompt.py # GPT prompt handling
│ ├── speech.py # Speech recognition and synthesis
│ ├── spotify.py # Spotify API integration
│ └── utils.py # Utility functions
├── tests/ # Unit tests
├── environment.yml # Conda environment definition
└── pyproject.toml # Project metadata and task definitions
- CLI Module (cli.py): Handles the command-line interface and user interaction flow
- Prompt Module (prompt.py): Manages OpenAI GPT interactions with custom prompt engineering
- Speech Module (speech.py): Provides cross-platform speech recognition and text-to-speech
- Spotify Module (spotify.py): Handles Spotify API integration for search and playback
The project uses pixi for task management and includes a Makefile for common operations:
# Run the application
pixi run start
# or
make run
# Run tests
pixi run test
# or
make test
# Check test coverage
pixi run coverage
# Run linters
make lint
# Setup environment
make setup
This project uses GitHub Actions for continuous integration. The CI pipeline:
- Runs on both Ubuntu and macOS environments
- Sets up Python 3.11 and pixi
- Installs system dependencies
- Configures the cross-platform speech support
- Runs linters and tests
You can see the build status in the badge at the top of this README.
DJGPT is designed to work across platforms, with fallbacks for different text-to-speech engines:
- macOS: Uses the native NSSpeechSynthesizer for optimal performance
- Windows/Linux: Falls back to pyttsx3 for text-to-speech functionality
- Fork the repository and create a feature branch
- Implement your changes with appropriate tests
- Run the test suite to ensure compatibility
- Submit a pull request with a description of your changes
DJGPT integrates several powerful technologies:
- OpenAI GPT-4: Powers the music recommendation engine with sophisticated prompt engineering
- Spotipy: Python client for the Spotify Web API (documentation)
- OpenAI Whisper: Provides speech recognition via SpeechRecognition
- AppKit/pyttsx3: Cross-platform text-to-speech capabilities
- Typer/Rich: Creates an elegant and interactive command-line interface
This project is licensed under the terms of the included LICENSE file.
DJGPT was initially created as a hack-day project to explore the capabilities of GPT-4 in music recommendation contexts. Special thanks to all the open-source projects that made this possible.