A professional AI-powered music generation desktop application built with LSTM Deep Learning
CodeAlpha AI Internship โ Task 3
AI Music Generator is a fully GUI-based desktop application that uses Long Short-Term Memory (LSTM) neural networks to learn music patterns from the MAESTRO dataset and generate original music compositions. The app allows users to train the AI model, generate music with customizable settings, and play it back โ all from a beautiful, modern interface.
This project was built as part of the CodeAlpha AI Internship Program to demonstrate real-world application of deep learning in creative AI.
Train the model โ Generate music โ Play it back instantly!
The app features:
- ๐ Train Tab โ Train LSTM model with live loss graph
- ๐ผ Generate Tab โ Generate music with custom settings
โถ๏ธ Playback Tab โ Play generated music with waveform visualizer
- LSTM-based deep learning model built with PyTorch
- Trained on MAESTRO Dataset (1,276 professional piano MIDI files)
- Extracts and learns note sequences and chord patterns
- Generates completely original music compositions
- Modern dark/light theme with CustomTkinter
- Animated splash screen on launch
- Dark/Light mode toggle
- Scrollable, responsive layout
- Notes to Generate โ slider (50 to 500 notes)
- Creativity (Temperature) โ controls randomness (0.1 to 2.0)
- BPM (Tempo) โ slider (60 to 200 BPM)
- Instrument Selector โ Piano, Violin, Guitar, Flute, Cello, Choir and more
- Genre Style โ Classical, Jazz, Ambient, Pop, Cinematic
- Key / Scale โ C Major, A Minor, D Minor and more
- Live loss graph updates during training
- Training progress bar with epoch counter
- Detailed training logs
- Animated waveform visualizer while playing
- Play / Stop controls
- Copy file path to clipboard
- Open output folder directly
- Delete generated files
| Technology | Purpose |
|---|---|
| Python 3.14 | Core programming language |
| PyTorch | LSTM model training & inference |
| music21 | MIDI parsing and note extraction |
| pretty_midi | MIDI file generation |
| CustomTkinter | Modern GUI framework |
| pygame-ce | MIDI playback |
| NumPy | Numerical computations |
| Pillow | Image processing |
CodeAlpha_MusicGenerator/
โ
โโโ ๐ gui/
โ โโโ main_window.py # Main app window + splash screen
โ โโโ train_tab.py # Training UI + loss graph
โ โโโ generate_tab.py # Music generation UI
โ โโโ playback_tab.py # Playback + waveform visualizer
โ
โโโ ๐ model/
โ โโโ train.py # LSTM model + training logic
โ โโโ generate.py # Music generation logic
โ โโโ music_model.pth # Saved trained model (after training)
โ โโโ notes.pkl # Extracted notes cache
โ
โโโ ๐ data/
โ โโโ ๐ 2004/ # MAESTRO MIDI files by year
โ โโโ ๐ 2006/
โ โโโ ๐ 2008/
โ โโโ ...
โ
โโโ ๐ output/ # Generated MIDI files saved here
โโโ App.py # Entry point โ run this!
โโโ requirements.txt # All dependencies
- Python 3.10, 3.11, or 3.14
- pip package manager
- Windows / Mac / Linux
1. Clone the repository
git clone https://github.com/YourUsername/CodeAlpha_MusicGenerator.git
cd CodeAlpha_MusicGenerator2. Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Mac/Linux3. Install dependencies
pip install torch music21 pretty_midi pygame-ce customtkinter pillow numpy4. Download MAESTRO Dataset
- Go to: https://magenta.tensorflow.org/datasets/maestro
- Download MIDI only version (~57MB)
- Extract and place year folders (2004, 2006...) inside
data/
5. Run the app
python App.py- Open the app โ click Train Model tab
- Set epochs (20 recommended) and MIDI files (10 recommended)
- Click ๐ Start Training
- Watch the live loss graph update
- Wait for "Training Complete!" message
โ ๏ธ Training is a one-time process. The model saves automatically.
- Click Generate Music tab
- Adjust your settings:
- Choose instrument, genre, key, BPM
- Set creativity level
- Enter output filename
- Click ๐ผ Generate Music
- Wait a few seconds for generation
- Click Playback tab
- Click ๐ Refresh to load your file
- Select your generated file
- Click
โถ๏ธ Play and enjoy the waveform visualizer!
| Style | BPM | Creativity | Instrument | Key |
|---|---|---|---|---|
| Classical | 72 | 0.7 | Acoustic Grand Piano | A Minor |
| Drama OST | 65 | 0.7 | Violin | D Minor |
| Jazz | 110 | 1.3 | Vibraphone | D Minor |
| Ambient | 60 | 0.9 | Choir Aahs | C Major |
| Cinematic | 85 | 1.0 | Violin | E Minor |
| Pop | 128 | 1.2 | Electric Piano | G Major |
MIDI Files โ Note Extraction โ Sequence Preparation
โ
LSTM Neural Network Training
โ
Pattern Learning (notes, chords, rhythms)
โ
Music Generation (new sequences)
โ
MIDI File Output
The LSTM model learns the statistical patterns in music โ which notes typically follow which other notes, chord progressions, and musical phrases. During generation, it uses these learned patterns to create new, original compositions.
Ubaidullah Waheed
- ๐ CodeAlpha AI Internship
- ๐ผ LinkedIn: [https://www.linkedin.com/in/ubaidullah-waheed-a119ba383/]
- ๐ GitHub: [https://github.com/UbaidullahWaheed]
CodeAlpha is a leading software development company dedicated to driving innovation and excellence across emerging technologies. This project was built as part of their AI internship program.
๐ Website: www.codealpha.tech
This project is licensed under the MIT License โ feel free to use and modify it!
โญ If you found this project helpful, please give it a star! โญ
Built with โค๏ธ by Ubaidullah Waheed โ CodeAlpha AI Internship 2026
