This project is an implementation of gesture-based controls for Spotify using hand tracking and machine learning. It leverages TensorFlow for gesture recognition, MediaPipe for hand tracking, and Spotipy for controlling Spotify.
- Project Overview
- Features
- Installation
- Configuration
- Usage
- Project Structure
- How It Works
- Troubleshooting
- License
The Spotify Gesture Control project allows users to control Spotify using hand gestures. For example, you can swipe left to skip to the previous track or swipe right to skip to the next track. The system uses computer vision and deep learning to recognize these gestures in real-time.
- Hand tracking using MediaPipe.
- Gesture recognition using a TensorFlow model.
- Gesture smoothing using Exponential Moving Average (EMA).
- Control Spotify playback (next/previous track) with gestures.
- Configurable parameters for fine-tuning performance.
- Python 3.8+
- Virtual environment (optional but recommended)
- Spotify Developer Account
-
Clone the repository:
git clone https://github.com/yourusername/spotify-gesture-control.git cd spotify-gesture-control
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up Spotify credentials:
Get your Spotify API credentials from the Spotify Developer Dashboard.
Set the following environment variables in your shell or
.env
file:export SPOTIPY_CLIENT_ID='your_client_id' export SPOTIPY_CLIENT_SECRET='your_client_secret' export SPOTIPY_REDIRECT_URI='your_redirect_uri'
Configuration options can be adjusted in config.py
:
MODEL_PATH = 'model_318.keras'
SEQUENCE_LENGTH = 25
SWIPE_THRESHOLD = 0.3
CONSISTENT_FRAMES = 5
FRAME_WIDTH = 640
FRAME_HEIGHT = 480
FPS = 30
Run the main script:
python main.py
gesture_control/
│
├── main.py # Entry point of the application
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── gesture_detector/
│ ├── __init__.py
│ ├── detector.py # Main gesture detection logic
│ ├── model_loader.py # Handles loading the TensorFlow model
│ ├── hand_tracker.py # Handles hand tracking using MediaPipe
│ ├── gesture_smoother.py # Smooths gesture predictions using EMA
│ └── spotify_controller.py # Controls Spotify playback using Spotipy
└── utils/
├── __init__.py
├── logger.py # Logging setup (optional)
└── warnings_handler.py # Suppresses unnecessary warnings
- Hand Tracking: The system uses MediaPipe to detect hand landmarks in real-time.
- Gesture Recognition: A TensorFlow model predicts gestures based on hand movement sequences.
- Gesture Smoothing: The Exponential Moving Average (EMA) technique is applied to filter out noise and make predictions more stable.
- Spotify Control: Based on the detected gesture, Spotify is controlled using the Spotipy library.
- TensorFlow Warnings: You might see some warnings from TensorFlow. You can suppress them using the included warning handler.
- Spotify Authentication Issues: Make sure your environment variables are set correctly. Double-check your Spotify API credentials.
- Performance Issues: If you experience lag, try adjusting the FPS or reducing the SEQUENCE_LENGTH in the configuration.
This project is licensed under the MIT License. See the LICENSE.md file for more information.
MIT License
Copyright (c) 2024 Hurska Veronika Andriivna