Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Melody Autocorrect

Hum a melody, get a cleaned-up ("autocorrected") MIDI back--plus optional similarity search against a local melody DB.

Features

  • Audio → f0 with librosa.pyin
  • Note segmentation and quantization to key/tempo grid
  • Simple autocorrect: scale/key snapping + smoothing
  • MIDI export via pretty_midi
  • Lightweight melody embeddings + cosine similarity search

This project is intentionally small so you can extend it (e.g., train a PyTorch model for smarter correction).

Quickstart

# 1) Create & activate a venv (recommended)
python -m venv .venv && source .venv/bin/activate   # (Windows: .venv\Scripts\activate)

# 2) Install deps
pip install -r requirements.txt

# 3) Run CLI help
python -m melody_autocorrect.cli --help

# Example: Convert a WAV to autocorrected MIDI in C major
python -m melody_autocorrect.cli hum2midi --audio path/to/hum.wav --out out.mid --key C --mode major

# Example: Build a tiny DB, then search
python -m melody_autocorrect.cli index --midi_dir examples/midi --db melodies.json
python -m melody_autocorrect.cli search --query out.mid --db melodies.json --topk 5

Project layout

src/melody_autocorrect/
  ├── audio_io.py       # load/record audio
  ├── f0.py             # pitch tracking (pyin)
  ├── theory.py         # scales, quantization helpers
  ├── midi.py           # note building + MIDI I/O
  ├── autocorrect.py    # end-to-end pipeline
  ├── embed.py          # melody embeddings + similarity
  └── cli.py            # command line interface

Notes

  • Default key is C major. Pass --key / --mode to change; or use --auto_key for a naive key guess.
  • For real projects, consider better note segmentation, HMM/Viterbi decoding, and a trained corrector (Transformer/LSTM). The hooks are here.
  • Recording from mic uses sounddevice if available; otherwise load WAVs.

License

None. :)

About

Testing some things out I had locally.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages