Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save output in music21 as a MIDI file?

How do I save audio output in Python using the music21 module? I have read the entire [user's guide](http://music21.readthedocs.org/en/latest/usersGuide/index.html] of said module, but I couldn't find any information about saving output as an audio file that can be recognised by windows without any additional software (MIDI for example).

like image 563
Ignas Juodžbalis Avatar asked Dec 20 '15 14:12

Ignas Juodžbalis


2 Answers

If s is your Stream, just call:

fp = s.write('midi', fp='pathToWhereYouWantToWriteIt')

or to hear it immediately

s.show('midi')

like image 199
Michael Scott Asato Cuthbert Avatar answered Oct 01 '22 04:10

Michael Scott Asato Cuthbert


Somewhere in this User's Guide Chapter 8, there is some important information about opening and saving file in many formats: http://web.mit.edu/music21/doc/usersGuide/usersGuide_08_installingMusicXML.html

if you have made your own music called 'stream1', you can easily save it as MIDI file like this:

stream1.write("midi", "blah.mid")

I am still new to this, but I think that's simpler than having to open file, etc.

like image 36
user2153553 Avatar answered Oct 01 '22 03:10

user2153553