在 Python 中合成音符(带有钢琴声音)

发布于 2024-11-17 09:46:52 字数 305 浏览 2 评论 0原文

我想要一个乐器库(例如,钢琴对象)的 python 实现,我可以用它来将音符列表和持续时间转换为声音。例如,类似这样的内容:

import Piano

pn = Piano()
pn.play([note, note, ..., note], duration)

Python 2.7 是否存在类似的内容?如果没有的话我想实现它。我目前有一些使用 audiere 的东西,但它只是正弦波,所以听起来很糟糕。有没有办法连接到 midi 钢琴或类似的东西 - 我使用的是 Windows 7?是否有任何我可能意想不到的实施步骤?

I would like to have a python implementation of a musical instrument library (for instance, a piano object) that I can use to convert a list of notes and a duration into sound. For instance, something like:

import Piano

pn = Piano()
pn.play([note, note, ..., note], duration)

Does something like this exist for python 2.7? I would like to implement it if it doesn't. I currently have something that uses audiere, but its just sine waves so it sounds horrible. Is there any way to hook into a midi piano or something like that- I am using windows 7? Are there any implementing steps that I might not expect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗心人 2024-11-24 09:46:52

我的一个学生刚刚开始使用 mingus 来做到这一点,所以这里有一个关于如何在 linux (ubuntu) 上进行操作的快速指南:

如果您还没有 Fluidsynth 和 mingus,请安装它们:

$ sudo apt-get install Fluidsynth

$ sudo easy_install mingus

现在你应该能够打开 python 并输入:

>>> from mingus.midi import fluidsynth   
>>> fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")

这将从 mingus 导入必要的内容并初始化 Fluidsynth通过 alsa 播放(不是默认的 jack)。然后:

>>> fluidsynth.play_Note(64,0,100)

...您应该听到钢琴上弹奏的音符(参数为:音符编号、通道编号和力度)。

如需了解更多信息,请访问此处:

https://code.google.com/p/mingus/wiki/tutorialFluidsynth

A student of mine has just started using mingus to do just this so here's quick guide on how to get going on linux (ubuntu):

Install fluidsynth and mingus if you don't have them already:

$ sudo apt-get install fluidsynth

$ sudo easy_install mingus

Now you should be able to open python and type:

>>> from mingus.midi import fluidsynth   
>>> fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")

This imports the necessary stuff from mingus and initialises fluidsynth to play through alsa (not jack which is the default). Then:

>>> fluidsynth.play_Note(64,0,100)

...and you should hear a note played on the piano (arguments are: note number, channel number and velocity).

For more information go here:

https://code.google.com/p/mingus/wiki/tutorialFluidsynth

冷血 2024-11-24 09:46:52

@Marcelos 答案的子集:http://code.google.com/p/mingus/

mingus 是一个 Python 包,程序员、音乐家、作曲家和研究人员使用它来制作和研究音乐。 mingus 的核心是音乐理论,其中包括音程、和弦、音阶和进行等主题

MIDI 包可以保存和加载 MIDI 文件,并且最后但并非最不重要的一点是为所有容器提供通用音序器和 FluidSynth 音序器子类。 这使您可以直接从 Python 中运行所有数据结构,只需几行。大多数棘手的计时和 MIDI 代码已被抽象出来,留下一个干净、相对简单的 API。

A subset of @Marcelos answer: http://code.google.com/p/mingus/

mingus is a package for Python used by programmers, musicians, composers and researchers to make and investigate music. At the core of mingus is music theory, which includes topics like intervals, chords, scales and progressions.

The MIDI package can save and load MIDI files, and -last but not least- provides a general purpose sequencer for all the containers and a FluidSynth sequencer subclass. This allows you to play all your data structures straight from Python in just a couple of lines. Most of the icky timing and MIDI code has been abstracted away for you, leaving a clean, relatively simple API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文