GetMoney_G5
GetMoney_G5

Reputation: 65

ImportError for FluidSynth library

The aim of this code was to create a button using QPushButton, which would then create a sound using the Pyfluidsynth library. I've imported time and pyfluidsynth but I have also tried to import fluidsynth (The option was there however I don't know the difference, both come with the one library I installed). Here is the code:

import sys
import time
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import pyfluidsynth

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 button - pythonspot.com'
        self.left = 10
        self.top = 10
        self.width = 320
        self.height = 200
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        button = QPushButton('PyQt5 button', self)
        button.setToolTip('This is an example button')
        button.move(100, 70)
        button.clicked.connect(self.PlayNote)

        self.show()

    def PlayNote(self):
        fs = pyfluidsynth.Synth()
        fs.start()

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

        fs.noteon(0, 60, 30)
        time.sleep(1.0)

        fs.delete()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

However when ran, the result is an ImportError:

Traceback (most recent call last):
  File "/Volumes/T7/MIDI Project/MIDI calculation.py", line 6, in <module>
    import pyfluidsynth
  File "/Users/ricochetnkweso/Library/Python/3.7/lib/python/site-packages/pyfluidsynth.py", line 43, in <module>
    raise ImportError("Couldn't find the FluidSynth library.")
ImportError: Couldn't find the FluidSynth library.

Upvotes: 1

Views: 3414

Answers (2)

lam vu Nguyen
lam vu Nguyen

Reputation: 641

what OS do you use

this may be what you forgot

enter image description here

sudo apt install fluidsynth

Upvotes: -1

DC Slagel
DC Slagel

Reputation: 586

It looks like you'll need to install the FluidSynth's shared library. This is because Pyfluidsynth is only bindings to FluidSynth's API.

So a version of FluidSynth needs to be installed on the machine running Pyfluidsynth. A shared library is a file that contains compiled-code that other programs can use.

You can use the links below to get the Fluidsynth release package for your machine.

https://github.com/nwhitehead/pyfluidsynth#requirements

REQUIREMENTS

FluidSynth 2.0.0 (or later version) (earlier versions are not supported. While they probably work, some features will be unavailble) http://www.fluidsynth.org/

    Windows/Android Binaries: https://github.com/FluidSynth/fluidsynth/releases
    MacOS/Linux Distributions: https://github.com/FluidSynth/fluidsynth/wiki/Download#distributions
    Building from Source: https://github.com/FluidSynth/fluidsynth/wiki/BuildingWithCMake

Additional install/compile information is at:
https://github.com/FluidSynth/fluidsynth/wiki/Download

Upvotes: 1

Related Questions