Converting audio (music) to notes

There’s Notey. It can detect notes and transcribe them on screen. It’s GPL, so you should be able to extract and adapt the detection/conversion routines.

enter image description here

Another options is music scribe kit which:

Is a toolkit for transcribing a music audio file to common music notation. This is done by manually annotating a spectrogram or something similar and converting it to a MIDI file and to a abc music notation file.

The proprietary program Transcribe! has an extensive list of other music-transcription tools, including some that are open-source. You can also check SourceForge for other open-source music-transcription programs.