除了外壳,使用fluidsynth和mingus没有声音 [英] No sound using fluidsynth and mingus except in shell

查看:152
本文介绍了除了外壳,使用fluidsynth和mingus没有声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照这个问题。我正在运行Ubuntu 14.04,并且已经创建了一个音频组并将自己添加到其中。
我正在使用alsa。

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.

我运行了上述问题的答案之一中给出的代码,并且在shell模式下运行良好。但是,当我编写一个python脚本并尝试运行它时,我什么都听不到。这是我的代码:

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.

推荐答案

我在Mac上,遇到了同样的问题。

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

使用 time.sleep()确实是正确的答案,但在我看来,这与等待 fluidsynth.init 完成无关,而是使用 fluidsynth.play_Note() fluidsynth.play_NoteContainer() c>通话,它应该可以播放。

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.

虽然我希望在mingus文档的某个地方提到此内容,网址为 https://bspaans.github.io/python-mingus/ ,他们在GitHub上确实有一些示例,表明它们正是按顺序进行的操作

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.

此示例特别有用,因为几乎每次调用 fluidsynth.play_Note()接下来是 time.sleep()调用:

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

这篇关于除了外壳,使用fluidsynth和mingus没有声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆