Created
May 9, 2013 23:39
-
-
Save arunaugustine/5551446 to your computer and use it in GitHub Desktop.
Converting aifc file into python numpy array
Also pickling in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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