play MIDI files in python?

YeJiabin picture YeJiabin · May 17, 2011 · Viewed 20.9k times · Source

I'm looking for a method to play midi files in python. It seems python does not support MIDI in its standard library. After I searched, I found some python midi librarys such as pythonmidi. However, most of them can only create and read MIDI file without playing function. I would like to find a python midi library including playing method. Any recommendations? Thanks!

Answer

Vijay picture Vijay · May 17, 2011

The pygame module can be used to play midi files.

http://www.pygame.org/docs/ref/music.html

See the example here:

http://www.daniweb.com/software-development/python/code/216979

a whole bunch of options available at:

http://wiki.python.org/moin/PythonInMusic

and also here which you can modify to suit your purpose: http://xenon.stanford.edu/~geksiong/code/playmus/playmus.py