PymidAI is a collection of simple Python scripts designed for generating MIDI files. It works by taking arrays of notes generated by Large Language Models (LLMs) like ChatGPT, Grok, Deepseek, Gemini, and others. Importantly, PymidAI does not require a direct API for interaction with LLMs.
PymidAI is built for simplicity and accessibility. Follow these steps to create your own MIDI melodies:
-
Get Note Arrays from an LLM: Use the example prompts provided in the
Examples AI Requestsfolder, or create your own, to generate sequences of notes. The LLM should output data in an array format similar to this:[ # Intro - tremolo motif (64, 0.125), (64, 0.125), (67, 0.25), (71, 0.5), # E-G-B (63, 0.333), (66, 0.333), (70, 0.333), # D#-F#-A triplet # A Section - ascending sequence (64, 0.25), (65, 0.25), (67, 0.25), (69, 0.25), # E-F-G-A (72, 0.75), (71, 0.125), (69, 0.125), # High B with grace notes # Chromatic bridge (76, 0.5), (75, 0.25), (74, 0.25), # E-F♯-G (73, 0.25), (72, 0.25), (71, 0.25), (70, 0.25), # Semi-tonal descent # ... continued for 160 beats (for example) ... ]Each tuple
(pitch, duration)represents a note:pitch: The MIDI note number (e.g., 64 for E4, 67 for G4).duration: The duration of the note in beats (e.g., 0.25 for a quarter note, 0.5 for a half note).
-
Paste the Array into the Script:
- For a single melody: Copy your generated array into the
mid_gen.pyfile in themelodyvariable. - For dual hands (treble/bass): Copy your respective arrays into
dual_hands_mid_gen.pyinto thetrebleandbassvariables.
- For a single melody: Copy your generated array into the
-
Run the Script: Execute the Python script from your command line:
python mid_gen.py
or
python dual_hands_mid_gen.py
Upon completion, the script will generate a MIDI file in the current directory.
-
Open Your MIDI File: You can open the created MIDI file in any Digital Audio Workstation (DAW) such as
Reaper,FL Studio,Ableton Live, or use music learning software likeSynthesia. Example MIDI files are available in theExampleMidifolder.
Notes_array: List of events where each event is:
(pitch, duration) -> Single note
([p1, p2, ...], duration) -> Chord
(None, duration) -> Rest
- Easy to Use: Quickly create short, simple melodies.
- Uses
midiutil: A robust library for MIDI file creation. - Clear Code: The code is very simple and ideal for learning MIDI manipulation in Python.
- Flexibility: You can generate single-hand or dual-hand melodies using different scripts.
- Quality Depends on LLM Prompts: The output is directly dependent on the quality of your prompts to the LLM. It's highly recommended to study the example prompts in the
Examples AI Requestsfolder. - No Direct API: PymidAI does not integrate directly with LLMs. You will need to generate your note arrays independently using web interfaces or other available tools.