FluidSynth / fluidsynth

Software synthesizer based on the SoundFont 2 specifications
https://www.fluidsynth.org
GNU Lesser General Public License v2.1
1.82k stars 254 forks source link

A working code for Jupiter Notebooks/Google Colabs #664

Closed asigalov61 closed 4 years ago

asigalov61 commented 4 years ago

Hey guys,

I finally figured out how to use FluidSynth in Jupter Notebooks/Google Colabs so I wanted to share with you my tiny code for it as many people seem to not know.

This was tested on Windows 10 in Google Chrome and MS Edge. Works great :)

Thank you and I hope this is helpful.

Feel free to add it your your docs/faq.

!pip install pyFluidSynth
!apt install fluidsynth #Pip does not work for some reason. Only apt works
!pip install midi2audio

!cp /usr/share/sounds/sf2/FluidR3_GM.sf2 /content/font.sf2

from midi2audio import FluidSynth
from google.colab import output
from IPython.display import display, Javascript, HTML, Audio

FluidSynth("/content/font.sf2").midi_to_audio('output_midi.mid','output_wav.wav')
# set the src and play
Audio("output_wav.wav")
asigalov61 commented 4 years ago

Ohh, this is the error I get with your main code:

RuntimeError Traceback (most recent call last) src/_rtmidi.pyx in rtmidi._rtmidi.MidiOut.cinit()

RuntimeError: MidiOutAlsa::initialize: error creating ALSA sequencer client object.

During handling of the above exception, another exception occurred:

SystemError Traceback (most recent call last)

in () 3 import rtmidi 4 ----> 5 midiout = rtmidi.MidiOut() 6 available_ports = midiout.get_ports() 7 src/_rtmidi.pyx in rtmidi._rtmidi.MidiOut.__cinit__() SystemError: MidiOutAlsa::initialize: error creating ALSA sequencer client object.
derselbst commented 4 years ago

Thanks for the code. I currently don't quite know where to place it in our documentation though. Python/Jupyter Notebook is a bit out of scope for us. Perhaps pyfluidsynth would be a better place for that.

MidiOutAlsa::initialize: error creating ALSA sequencer client object

Regarding that error, I can tell you that it's not a fluidsynth error. To me, it seems like an error raised by rtmidi.

asigalov61 commented 4 years ago

You are welcome. I think it should be somewhere in your docs/site as a temporary fix until you guys figure out what to do. Fluidsynth is awesome when it does work, so I hope you can fix it properly even though it is hard, I know :)

Sure, I will re-post on pyfluidsynth if you think its a better place for the fix.

And sorry about the wrong error. I think copypasted the wrong one. But you can easily reproduce the error on a vanilla installation of python under Windows (not sure about other OSs).

And btw, rtmidi and timidity also do not work, so I know that its not really a fluidsynth issue but rather a Windows/Browsers compat. issue.

Thank you for your response though. Much appreciated.

Hope you guys are doing well in these difficult times.

Alex