40

我正在寻找用 Python 编写一个小鼓机来获得乐趣。我用谷歌搜索了一些,找到了关于音乐基本音频的 python 页面以及关于生成音频文件的 StackOverflow 问题,但我正在寻找的是一个体面的音乐创作库。有没有人在这里尝试过做这样的事情?如果是这样,您的解决方案是什么?什么,无论是我找到的,还是我没有找到的,将是一个体面的音频处理库?

至少,我希望能够在 python 中做类似于Audacity范围的事情,但如果有人知道可以做更多的库......我全都听好了。

4

5 回答 5

14

仔细看看cSounds。有 Python 绑定允许您进行非常灵活的数字合成。也有一些非常完整的软件包可用。

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

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

于 2008-09-20T19:51:39.457 回答
8

几年前我不得不这样做。我使用了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'
于 2008-09-20T18:33:16.010 回答
4

有多种 Python 音乐软件,你可以在这里找到目录。

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

于 2008-09-20T18:01:39.707 回答
3

另请查看http://code.google.com/p/pyo/

于 2010-09-21T15:40:27.687 回答
2

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

它还具有音频处理和一些效果。

Code 的 GPL,因此这可能是您的起点。

于 2008-09-20T22:39:12.067 回答