我正在寻找用 Python 编写一个小鼓机来获得乐趣。我用谷歌搜索了一些,找到了关于音乐和基本音频的 python 页面以及关于生成音频文件的 StackOverflow 问题,但我正在寻找的是一个体面的音乐创作库。有没有人在这里尝试过做这样的事情?如果是这样,您的解决方案是什么?什么,无论是我找到的,还是我没有找到的,将是一个体面的音频处理库?
至少,我希望能够在 python 中做类似于Audacity范围的事情,但如果有人知道可以做更多的库......我全都听好了。
仔细看看cSounds。有 Python 绑定允许您进行非常灵活的数字合成。也有一些非常完整的软件包可用。
有关软件包,请参见http://www.csounds.com/node/188。
有关cSounds 中 Python 脚本的信息,请参阅http://www.csounds.com/journal/issue6/pythonOpcodes.html 。
几年前我不得不这样做。我使用了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'
除了前面提到的,我还写了一个简单的 Python 音频编辑器。 http://code.google.com/p/yaalp/source/browse/#svn/trunk 见 main.py。
它还具有音频处理和一些效果。
Code 的 GPL,因此这可能是您的起点。