在Python中为Pydub模块查询对象列表

时间:2015-05-13 01:09:14

标签: python object pydub

我正在尝试将wav文件列表连接到一个音频文件中。到目前为止,这就是我所拥有的。 我无法围绕如何将对象加在一起,但因为它们都是对象。

import glob, os
from pydub import AudioSegment

wavfiles = []
for file in glob.glob('*.WAV'):
    wavfiles.append(file)

outfile = "sounds.wav"

pydubobjects = []

for file in wavfiles:
    pydubobjects.append(AudioSegment.from_wav(file))


combined_sounds = sum(pydubobjects) #this is what doesn't work of course

# it should be like so
# combined_sounds = sound1 + sound2 + sound 3
# with each soundX being a pydub object

combined_sounds.export(outfile, format='wav')

1 个答案:

答案 0 :(得分:3)

var response = { ok: function(result, res) { if (!result) { return false; } response.json(result); }, error: function (error) { if (!error) { return false; } console.log('Error: ' + error); } }; module.exports = response; 函数失败,因为它是starting value defaults to 0,您无法添加sum和整数。

您只需要添加一个起始值:

AudioSegment

此外,如果您只想组合文件(并且不需要文件名或combined_sounds = sum(pydubobjects, AudioSegment.empty()) 对象的中间列表),则实际上不需要单独的循环:

AudioSegment