J Spen J Spen - 6 months ago 55
Python Question

Read Nist Wav File in TIMIT database into python numpy array

Is this possible?? I seem to be getting this error when using wavread from scikits.audiolab:

x86_64.egg/scikits/audiolab/pysndfile/matapi.pyc in basic_reader(filename, last, first)
93 if not hdl.format.file_format == filetype:
94 raise ValueError, "%s is not a %s file (is %s)" \
---> 95 % (filename, filetype, hdl.format.file_format)
97 fs = hdl.samplerate

ValueError: si762.wav is not a wav file (is nist)

I'm guessing it can't read NIST wav files but is there another way to easily read them into a numpy array? If not, what is the best way to go about reading in the data?

Possibly rewriting the audiolab wavread to recognize the nist header??


Answer my own question because figured it out but you can use the Sndfile class from scikits.audiolab which supports a multitude of reading and writing file formats depending on the libsndfile you have. Then you just use:

from scikits.audiolab import Sndfile, play
f = Sndfile(filename, 'r')
data = f.read_frames(10000)
play(data) # Just to test the read data