gpt4 book ai didi

python - 在 Python 中从 MIDI 到扬声器(声音合成)的真实音频的最简单方法是什么?

转载 作者:行者123 更新时间:2023-11-28 17:38:21 25 4
gpt4 key购买 nike

我正在着手开发一个应用程序,该应用程序需要从大量预加载的“.mid”文件中创建声音。

我正在使用 Python 和 Kivy 创建一个应用程序,因为我已经使用这些工具制作了一个应用程序,而且它们是我唯一知道的代码。我制作的另一个应用程序没有使用任何声音。

当然,我想确保我编写的代码能够跨平台工作。

现在,我只是想证明我可以从 MIDI 音符创建任何真实的声音。

我使用 FluidSynth 和 Mingus 从另一个对类似问题的回答中建议了这段代码:

from mingus.midi import fluidsynth

fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
fluidsynth.play_Note(64,0,100)

但我什么也没听到并收到此错误:

fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.

为什么会出现此错误,如何修复它,这是最简单的方法还是正确的方法?

最佳答案

我可能是错的,但我不认为有一个“0” channel ,它是您作为第二个参数传递给 .play_Note() 的 channel 。试试这个:

fluidsynth.play_Note(64,1,100)

或(来自一些 documentation )

from mingus.containers.note import Note
n = Note("C", 4)
n.channel = 1
n.velocity = 50
fluidSynth.play_Note(n)

更新:

该方法的源代码中仅引用了 channel 1-16,默认 channel 设置为 1:

def play_Note(self, note, channel = 1, velocity = 100):
"""Plays a Note object on a channel[1-16] with a \
velocity[0-127]. You can either specify the velocity and channel \
here as arguments or you can set the Note.velocity and Note.channel \
attributes, which will take presedence over the function arguments."""
if hasattr(note, 'velocity'):
velocity = note.velocity
if hasattr(note, 'channel'):
channel = note.channel
self.fs.noteon(int(channel), int(note) + 12, int(velocity))
return True

关于python - 在 Python 中从 MIDI 到扬声器(声音合成)的真实音频的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28031600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com