Installing pyfluidsynth on windows

Viewed 5106

I'm trying to install pyfluidsynth on windows. I used pip install pyfluidsynth in the command prompt, but when I tried to import fluidsynth in my python code I get:

 ModuleNotFoundError: No module named 'FluidSynth'

When I tried to install FluidSynth (by using pip install fluidsynth) another binding package was installed with FluidSynth 0.2 from several years ago.

Can anybody help with specific details on how to install pyfluidsynth on windows and use it?

import FluidSynth

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'FluidSynth'
4 Answers

For recent FluidSynth versions there do not seem to be pre-built binaries for ms-windows available. (Note that development is now done on github; the sourceforge site is stale.) The latest source code releases are here.

But the FluidSynth wiki has instructions for building it on ms-windows.

Note: FluidSynth (more precisely, its shared library) is a requirement for using pyfluidsynth. See the README.

For me the following worked:

  1. Go to the following link and download the pre-compiled (?) fluidsynth dll.
  2. Add the directory of your fluidsynth dll to the path environment variable.
  3. In the pyfluidsynth package. find the "fluidsynth.py" file, and edit the part where it's looking for the library "lib = find_library('fluidsynth')..." to search for the dll name, which was "libfluidsynth64" for the 64 bit version.
  4. For whatever reason, (maybe version mismatch), the functions "fluid_synth_set_reverb_full" and "fluid_synth_set_chorus_full" are not supported, so comment those lines out from "fluidsynth.py".
  5. And that's it. Save "fluidsynth.py" launch cmd, go into python, and import fluidsynth.

I haven't tested all the functionality of fluidsynth, but using pretty_midi, I was able to at least play midi through instrument soundfonts.

Hope this helps!

Installing fluidsynth on Windows

Download fluidsynth binaries from github: https://github.com/FluidSynth/fluidsynth/releases

Add extracted zip file’s bin to the path: Eg: C:\Users*Your Username Here**** YOUR path to extracted zip ***\fluidsynth-2.1.6-win10-x64\bin

Download fluidsynth python library: the repository for python fluidsynth is: https://github.com/nwhitehead/pyfluidsynth. https://github.com/nwhitehead/pyfluidsynth/archive/master.zip

Once extracted, it must be installed:

python setup.py install

The extracted master.zip has fluidsynth.py This python file is the file to “import” into the python code. In the test folder it has example.sf2 which is used in an installation test: paths to these two files need to be set to your own locations.

import time
import fluidsynth

fs = fluidsynth.Synth()
fs.start()

sfid = fs.sfload("example.sf2")
fs.program_select(0, sfid, 0, 0)

fs.noteon(0, 60, 30)
fs.noteon(0, 67, 30)
fs.noteon(0, 76, 30)

time.sleep(1.0)

fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)

time.sleep(1.0)

fs.delete()

The above python code sample plays a single note. Getting this to work confirms everything is working.

For me, next works:

  1. Call pip install --upgrade pyfluidsynth
  2. Download precompiled DLL from: https://zdoom.org/downloads#Support
  3. If you use 64x version rename file from libfluidsynth64.dll to libfluidsynth.dll
  4. Place it into C:\Windows\System32
Related