Basically, this takes a MIDI input file (I just googled and grabbed one of Maroon 5's "Animal" – I know, I know) and generates a WAV file.
NOTE: This is the slowest midi rendering program I have ever seen!
Dependencies:
- Pydub (pydub.com)
pip install pydub
- mido (http://mido.readthedocs.org/en/latest/)
pip install mido
In this example I an rendering a MIDI file of Maroon 5's "Animals" from http://www.free-midi.org
Here is the output my program generated (converted to mp3):
Obvious issues:
- Tempo is hard-coded
- All instruments are rendered using a Sine wave, including drums. Would be better to use different signal generators depending which instrument is being rendered (Sine is fine for flute, square is closer to saxaphone, etc)
- This is REALLLY SLOWWW. I haven't looked at performance at all, but it took almost an hour (2014, 2.8 GHz i7, Macbook Pro) to render the wav file with the code above. LOL
One way to improve performance is to use a Mixer class like this one instead of just overlaying every note onto a silent "output" audio segment.
I added on the top of the script:
and it worked. Thanks!