Sandbox
@tubone24/midi-agent-skill

Claude skill for MIDI and WAV generation

This repository defines a Claude skill that converts text-based music descriptions into MIDI files. The Python code in `skills/` handles generation, validation, refinement, and optional WAV export, while `midi_types/` and `resources/` provide the instrument and music theory data it needs.

30 stars3 forksPythonUpdated 6mo ago
Who it's for

Builders who want Claude to produce MIDI from music prompts and structured composition data.

What it delivers

You can turn a music idea into a MIDI file, and optionally a WAV file, without building the conversion logic yourself.

What it does

Generate MIDI from prompts

Creates `.mid` files from natural-language music descriptions or structured composition data.

General MIDI instrument support

Maps tracks to all 128 GM instruments, including simple aliases like piano, guitar, bass, strings, brass, and sax.

WAV export

Uses `convert_to_wav` with FluidSynth and `A320U.sf2` to render MIDI to audio.

Input normalization and refinement

Validates composition data with `normalize_composition` and adjusts track length with `refine_composition`.

Claude skill packaging

Uses `SKILL.md` so Claude can detect when to invoke the skill automatically.

How to get it

  1. 1Run
    pip install midiutil
  2. 2Or using requirements.txt
    pip install -r requirements.txt
  3. 3Run
    # macOS
    brew install fluidsynth
    
    # Linux
    apt-get install fluidsynth
  4. 4Simply ask Claude something related to music
    Added the “midi-generation” skill. Use it to create grand classical music. I look forward to bright, grand, and beautiful melodies layered together. Once you have the MIDI, please convert it to WAV.

README

MIDI Generation Skill

MIDI Generation Skill is a custom Agent Skill for Claude.ai that enables AI agents to generate MIDI files from natural language music descriptions, with full General MIDI instrument support optimized for the A320U.sf2 SoundFont.


Features

  • Generate MIDI from text prompts
  • 128 GM instruments - Full General MIDI support (A320U.sf2 compatible)
  • WAV export - Convert MIDI to audio using FluidSynth
  • Claude Skills compatible - Automatic skill invocation
  • Python implementation using midiutil

Repository Structure

/
├─ skills/                   # Skill implementation (Python)
│   ├─ generate_midi.py          # MIDI file generation
│   ├─ convert_to_wav.py         # MIDI to WAV conversion (FluidSynth)
│   ├─ normalize_composition.py  # Input validation
│   └─ refine_composition.py     # Adjust composition length
├─ midi_types/
│   ├─ music.py                  # Composition types
│   └─ gm_instruments.py         # 128 GM instruments list
├─ resources/                # Music theory references
│   ├─ music-theory.md
│   ├─ chord-progressions.md
│   ├─ voice-leading.md
│   ├─ counterpoint.md
│   ├─ modes-scales.md
│   ├─ rhythm-patterns.md
│   └─ orchestration.md
├─ soundfonts/               # Place A320U.sf2 here
├─ output/                   # Generated MIDI/WAV files
├─ SKILL.md                  # Claude Skill definition
├─ requirements.txt          # Python dependencies
└─ README.md

Supported Instruments

All 128 General MIDI instruments are supported. Common examples:

CategoryInstruments
Pianoacoustic-grand-piano, electric-piano-1, harpsichord
Guitaracoustic-guitar-nylon, electric-guitar-clean, distortion-guitar
Bassacoustic-bass, electric-bass-finger, synth-bass-1
Stringsviolin, cello, string-ensemble-1, orchestral-harp
Brasstrumpet, trombone, french-horn, brass-section
Woodwindflute, clarinet, oboe, alto-sax
Synthlead-1-square, pad-1-new-age, synth-strings-1

Simple aliases like piano, guitar, bass, strings, brass, sax are also supported.

See midi_types/gm_instruments.py for the full list.


Installation

1. Install Python dependencies

pip install midiutil

Or using requirements.txt:

pip install -r requirements.txt

2. Download SoundFont (for WAV conversion)

  1. Download A320U.sf2 from Musical Artifacts
  2. Place it in soundfonts/A320U.sf2

3. Install FluidSynth (for WAV conversion)

# macOS
brew install fluidsynth

# Linux
apt-get install fluidsynth

Usage with Claude.ai

1. Enable Skills in Claude

  1. Open Claude Settings
  2. Enable Skills
  3. Upload this repository as a ZIP file
  4. Turn the skill ON

2. Use the Skill

Simply ask Claude something related to music:

Added the “midi-generation” skill. Use it to create grand classical music. I look forward to bright, grand, and beautiful melodies layered together. Once you have the MIDI, please convert it to WAV.

Claude will automatically:

  1. Detect that the request matches this skill
  2. Use the provided Python scripts in skills/ directory
  3. Generate MIDI with proper GM instruments (each track on different channel)
  4. Optionally convert to WAV

Demo

https://github.com/user-attachments/assets/34f018e5-6354-40a9-9426-15d2ccc7c39a


Composition Format

The skill uses a structured JSON format:

{
  "title": "My Song",
  "bpm": 120,
  "tracks": [
    {
      "instrument": "acoustic-grand-piano",
      "notes": [
        { "pitch": "C4", "duration": "4" },
        { "pitch": "E4", "duration": "4" },
        { "pitch": "G4", "duration": "2" }
      ]
    },
    {
      "instrument": "acoustic-bass",
      "notes": [
        { "pitch": "C2", "duration": "1" }
      ]
    }
  ]
}

Note Duration Values

ValueDuration
"1"Whole note (4 beats)
"2"Half note (2 beats)
"d2"Dotted half (3 beats)
"4"Quarter note (1 beat)
"d4"Dotted quarter (1.5 beats)
"8"Eighth note (0.5 beats)
"16"Sixteenth note (0.25 beats)

API Reference

generate_midi(composition: Composition) -> str

Generate a MIDI file from a Composition object.

  • Input: Composition object with title, bpm, and tracks
  • Output: Path to the generated .mid file

generate_midi_from_dict(data: dict) -> str

Generate a MIDI file from a dictionary.

  • Input: Dictionary with title, bpm, and tracks
  • Output: Path to the generated .mid file

convert_to_wav(midi_path: str, options: ConvertOptions) -> str

Convert a MIDI file to WAV using FluidSynth and A320U.sf2.

  • Input: Path to MIDI file
  • Output: Path to the generated .wav file

normalize_composition(data: Any) -> Composition

Validate and normalize user input into a proper Composition object.

refine_composition(composition: Composition, min_notes: int) -> Composition

Adjust composition length (ensures minimum notes per track).

resolve_instrument(name: str) -> int

Convert instrument name to GM program number (0-127).


Example Prompts

Create a calm ambient piece with pad synths and strings
Generate a rock song with distortion guitar and drums at 140 BPM
Compose a classical piece with violin, cello, and harpsichord

Development Notes

  • SKILL.md defines when and how Claude should use this skill
  • The skills/ directory contains pre-built Python scripts that Claude must use
  • Claude should NOT write custom code - it should use the provided functions
  • All instruments are GM-compatible for A320U.sf2 playback
  • Each track is assigned to a different MIDI channel for proper multi-instrument playback

License

MIT License

See LICENSE.txt for details including third-party licenses.


References

Files in the repo

Repository payload10 top-level entries
  • midi_types
  • output
  • resources
  • skills
  • soundfonts
  • .gitignore
  • LICENSE.txt
  • README.md
  • requirements.txt
  • SKILL.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More skills

obra/
superpowers

An agentic skills framework & software development methodology that works.

285k
1 add

Turn any codebase, with its docs, SQL schemas, configs, and PDFs, into a queryable knowledge graph. A /graphify skill for Claude Code, Cursor, Codex, and Gemini CLI: local deterministic AST parsing, every edge explained, no vector store.

117k
1 add
Vincentwei1021/
anything2explainer

Topic in, narrated explainer video out. A Claude Code / Codex skill that turns any topic into a black-canvas motion-graphics explainer video with TTS voiceover, subtitles and a chapter progress bar. Chinese or English; every frame drawn in code with Remotion.

666

Open-source AI job search: scan job portals, evaluate listings into a structured A-H report with a global 1-5 score, tailor your CV, track applications — runs locally in your AI coding CLI (Claude Code, Codex, OpenCode, Antigravity…)

71k