Python音乐库?

时间:2020-03-06 14:29:22  来源:igfitidea点击:

我正在寻找用Python编写一台小鼓机的乐趣。我已经在Google上进行了搜索,找到了关于音乐和基本音频的python页面,以及关于生成音频文件的StackOverflow问题,但是我正在寻找的是一个不错的音乐创作库。有人在这里尝试过做类似的事情吗?如果是这样,解决方案是什么?我发现的或者未发现的东西,会是一个不错的音频处理库?

至少,我希望能够在python中完成与Audacity的作用域类似的操作,但是如果有人知道一个可以做更多事情的库……我非常高兴。

解决方案

有各种各样的Python音乐软件,我们可以在这里找到目录。

如果向下滚动链接的页面,则会发现有关Python音乐编程的部分,描述了几个音乐创作包,包括MusicKit和PySndObj。

我几年前不得不做。我用了pymedia。我不确定它是否仍然存在,这是我在使用它时编写的一些测试代码。虽然大约3岁。

编辑:示例代码播放一个MP3文件

import pymedia
import time

demuxer = pymedia.muxer.Demuxer('mp3') #this thing decodes the multipart file i call it a demucker

f = open(r"path to \song.mp3", 'rb')

spot = f.read()
frames = demuxer.parse(spot)
print 'read it has %i frames' % len(frames)
decoder = pymedia.audio.acodec.Decoder(demuxer.streams[0]) #this thing does the actual decoding
frame = decoder.decode(spot)
print dir(frame)
#sys.exit(1)
sound = pymedia.audio.sound
print frame.bitrate, frame.sample_rate
song = sound.Output( frame.sample_rate, frame.channels, 16 ) #this thing handles playing the song

while len(spot) > 0:
    try:
        if frame: song.play(frame.data)
        spot = f.read(512)
        frame = decoder.decode(spot)
    except:
        pass

while song.isPlaying(): time.sleep(.05)
print 'well done'

仔细看看cSounds。有Python绑定使我们可以进行非常灵活的数字合成。也有一些相当完整的软件包。

有关软件包,请参见http://www.csounds.com/node/188.

有关cSounds中Python脚本编写的信息,请参见http://www.csounds.com/journal/issue6/pythonOpcodes.html。

除了前面提到的内容外,我还编写了一个简单的Python音频编辑器。
http://code.google.com/p/yaalp/source/browse/#svn/trunk
参见main.py。

它还具有音频操作和某些效果。

代码的GPL,因此这可能是起点。

还要查看http://code.google.com/p/pyo/