0

I'm at very beginning in programming, and I'm studying Python. I want to make a little piece of software who looks into a directory with audio files, and merge them into a single audio file. Here is my current code:

import glob
#import os
import wave

fil = raw_input("Qual o diretorio ?")
#files = os.listdir(fil)
files = glob.glob(fil)

infiles = files
outfile = "merged.wav"

data= []
for infile in range(len(infiles)):
    w = wave.open(infile, 'rb')
    data.append([w.getparams(), w.readframes(w.getnframes())])
    w.close()

output = wave.open(outfile, 'wb')
output.setparams(data[0][0])
output.writeframes(data[0][1])
output.writeframes(data[1][1])
output.close()

I've based the code on this post merging two wav files. My idea was to use glob to populate an array, and iterate to get all the files but I'm getting an attribute error. What could I do?

Community
  • 1
  • 1
  • You should always post the whole error with all the lines that could help us. – User Nov 02 '14 at 03:36
  • Hi, thanks for your advice. This is what i've got : Traceback (most recent call last): File "merger.py", line 17, in w = wave.open(infile, 'rb') File "C:\Python27\lib\wave.py", line 509, in open return Wave_read(f) File "C:\Python27\lib\wave.py", line 164, in __init__ self.initfp(f) File "C:\Python27\lib\wave.py", line 129, in initfp self._file = Chunk(file, bigendian = 0) File "C:\Python27\lib\chunk.py", line 61, in __init__ self.chunkname = file.read(4) – Welington E. Alves Nov 03 '14 at 13:09
  • The error is missing. And it would be good if that is in your question since we look specifically for this and formatting makes it easier. Something like "AttributeError: xxx has no attribute yyy" – User Nov 03 '14 at 16:15

1 Answers1

1

The first thing that looks wrong is this:

for infile in range(len(infiles)):

You want to use this instead:

for infile in infiles:

I recommend using a debugger, like pudb (for Linux/Mac) or winpdb (Windows.

Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107