Skip to content

Instantly share code, notes, and snippets.

@arunaugustine
Created May 9, 2013 23:39
Show Gist options
  • Select an option

  • Save arunaugustine/5551446 to your computer and use it in GitHub Desktop.

Select an option

Save arunaugustine/5551446 to your computer and use it in GitHub Desktop.
Converting aifc file into python numpy array Also pickling in python
import aifc
import numpy
import scipy
import scipy.fftpack
import cPickle
# Program to picke the whale data
datafolder = "../data/smalldata/"
filename = "train28.aiff"
filename2 = "train1.aiff"
label = 1
s = aifc.open(datafolder + filename)
s2 = aifc.open(datafolder + filename)
#s = aifc.open("../data/small_data_sample/right_whale/train28.aiff")
nframes = s.getnframes()
nframes2 = s2.getnframes()
strsig = s.readframes(nframes)
strsig2 = s2.readframes(nframes2)
y = numpy.fromstring(strsig, numpy.short).byteswap()
y2 = numpy.fromstring(strsig2, numpy.short).byteswap()
audiolist = []
audiolist.append(y)
audiolist.append(y2)
x = numpy.array(audiolist)
labellist = [1,0]
xlabel = numpy.array(labellist)
ourtuple = (x,xlabel)
print xlabel.shape
print x.shape
wf = open("myFile.pkl","wb")
cPickle.dump(ourtuple, wf)
wf.close()
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment