No sound using fluidsynth and mingus except in she

2019-07-13 14:30发布

I am trying to emulate a piano in python using mingus as suggested in this question. I am running Ubuntu 14.04, and have already created an audio group and added myself to it. I am using alsa.

I ran the code given in one of the answers to the aforementioned question and it ran fine in shell mode. However, when I wrote a python script and tried to run it, I did not get any sound whatsoever. Here is my code:

#!/usr/bin/env python

from mingus.midi import fluidsynth
DEF_FONT_PATH = '/usr/share/sounds/sf2/FluidR3_GM.sf2'

def main():
    fluidsynth.init(DEF_FONT_PATH, 'alsa')
    fluidsynth.play_Note(80, 0, 80)

if __name__ == '__main__':
    main()

I have checked many other answers, and I cannot seem to find a solution.

标签: python alsa
2条回答
霸刀☆藐视天下
2楼-- · 2019-07-13 14:54

I managed to solve it.

It seems the problem was, as I had previously suspected, that it was necessary to wait for some time after calling fluidsynth.init. However, since a simple time.sleep() had not been able to fix this, I had discarded this possibility.

After prompting the user to provide some input to trigger the playing of the note, the sounds play fine.

I am, however, still unsure as to why a delay is required.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-07-13 15:02

I am on a Mac and I ran into the same problem.

Using time.sleep() is indeed the correct answer but it does not seem to me that it has to do with waiting for fluidsynth.init to finish, instead use time.sleep() after a fluidsynth.play_Note() or a fluidsynth.play_NoteContainer() call and it should play.

While I wish this was mentioned somewhere in the mingus documentation at, https://bspaans.github.io/python-mingus/, they do have examples in GitHub that show that this is exactly what they are doing in order to play the notes.

This example is particularly helpful being that just about every call to fluidsynth.play_Note() is followed up by a time.sleep() call:

https://github.com/bspaans/python-mingus/blob/master/mingus_examples/play_progression/play-progression.py

查看更多
登录 后发表回答