No sound using fluidsynth and mingus except in shell

♀尐吖头ヾ 提交于 2019-12-24 00:52:41

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/34254594/no-sound-using-fluidsynth-and-mingus-except-in-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!