Skip to content

UbaidullahWaheed/CodeAlpha_MusicGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽต AI Music Generator โ€” CodeAlpha Internship

Python PyTorch CustomTkinter License

A professional AI-powered music generation desktop application built with LSTM Deep Learning

CodeAlpha AI Internship โ€” Task 3


๐Ÿ“Œ About The Project

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.


๐ŸŽฌ Demo

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

โœจ Features

๐Ÿค– AI & Machine Learning

  • 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

๐ŸŽจ Professional GUI

  • Modern dark/light theme with CustomTkinter
  • Animated splash screen on launch
  • Dark/Light mode toggle
  • Scrollable, responsive layout

๐ŸŽต Music Generation Controls

  • 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

๐Ÿ“Š Training Dashboard

  • Live loss graph updates during training
  • Training progress bar with epoch counter
  • Detailed training logs

โ–ถ๏ธ Playback & Export

  • Animated waveform visualizer while playing
  • Play / Stop controls
  • Copy file path to clipboard
  • Open output folder directly
  • Delete generated files

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“ Project Structure

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

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.10, 3.11, or 3.14
  • pip package manager
  • Windows / Mac / Linux

Installation

1. Clone the repository

git clone https://github.com/YourUsername/CodeAlpha_MusicGenerator.git
cd CodeAlpha_MusicGenerator

2. Create virtual environment

python -m venv venv
venv\Scripts\activate        # Windows
source venv/bin/activate     # Mac/Linux

3. Install dependencies

pip install torch music21 pretty_midi pygame-ce customtkinter pillow numpy

4. Download MAESTRO Dataset

5. Run the app

python App.py

๐ŸŽฎ How To Use

Step 1 โ€” Train The Model

  1. Open the app โ†’ click Train Model tab
  2. Set epochs (20 recommended) and MIDI files (10 recommended)
  3. Click ๐Ÿš€ Start Training
  4. Watch the live loss graph update
  5. Wait for "Training Complete!" message

โš ๏ธ Training is a one-time process. The model saves automatically.

Step 2 โ€” Generate Music

  1. Click Generate Music tab
  2. Adjust your settings:
    • Choose instrument, genre, key, BPM
    • Set creativity level
    • Enter output filename
  3. Click ๐ŸŽผ Generate Music
  4. Wait a few seconds for generation

Step 3 โ€” Play & Export

  1. Click Playback tab
  2. Click ๐Ÿ”„ Refresh to load your file
  3. Select your generated file
  4. Click โ–ถ๏ธ Play and enjoy the waveform visualizer!

๐ŸŽต Recommended Settings For Best Results

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

๐Ÿ“ธ Screenshots

image

๐Ÿค– How The AI Works

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.


๐Ÿ‘จโ€๐Ÿ’ป Developer

Ubaidullah Waheed


๐Ÿข About CodeAlpha

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


๐Ÿ“„ License

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

About

๐ŸŽต AI-powered music generation desktop app using LSTM deep learning trained on the MAESTRO dataset. Features live training dashboard, customizable generation settings (BPM, instrument, genre, key, creativity), waveform playback visualizer, and a modern CustomTkinter GUI. CodeAlpha AI Internship Task 3.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages