Step 4: Extracting Audio Data with Python

Picture of Extracting Audio Data with Python
Processing has a library for dealing with audio called Minim, it is included with the more recent versions of Processing IDE.  Unfortunately, this library is set up for real time audio applications and does not appear give you an easy way of extracting all the data from an audio file at once (it makes you load it in small buffers piece by piece).  Since I could not find an easy way to load my wav files into Processing directly (although I'm sure this must be possible), I've been importing stereo audio in the wav format into Python using the wav library, adding the left and right channels together, centering the data around zero, and exporting the resulting array of int's (separated by commas) to a txt file.  Here is my wav to txt Python script (I'm running this in Python 2.5.4):

Once I create a text file, I can import the data into Processing and convert it into an STL.  I would like to streamline my code so that audio files (wav/mp3) can be loaded directly into Processing, but I have not found a solution yet, any suggestions would be appreciated!
Win951 year ago
I can record two channels in the file?
This line says 2 channels, but only half of the file:
frameOneChannel[i] = frameInt[2*i+1]*2**8+frameInt[2*i]
amandaghassaei (author)  Win951 year ago
this line is supposed to merge the two channels together into one mono channel - frameOneChannel. However, there is a bug in my program that is not mixing these together properly. I haven't had a chance to address it, for now the workaround is to make your audio mono in audacity and then copy it and export a stereo track consisting of two identical mono channels. Sorry about that!