reading a WAV file from TIMIT database in python

okuoub picture okuoub · Jun 25, 2017 · Viewed 9.1k times · Source

I'm trying to read a wav file from the TIMIT database in python but I get an error:

When I'm using wave:

wave.Error: file does not start with RIFF id

When I'm using scipy:

ValueError: File format b'NIST'... not understood.

and when I'm using librosa, the program got stuck. I tried to convert it to wav using sox:

cmd = "sox " + wav_file + " -t wav " + new_wav
subprocess.call(cmd, shell=True)

and it didn't help. I saw an old answer referencing to the package scikits.audiolab but it looks like it is no longer supported.

How can I read these file to get a ndarray of the data?

Thanks

Answer

Warren Weckesser picture Warren Weckesser · Jun 26, 2017

Your file is not a WAV file. Apparently it is a NIST SPHERE file. From the LDC web page: "Many LDC corpora contain speech files in NIST SPHERE format." According to the description of the NIST File Format, the first four characters of the file are NIST. That's what the scipy error is telling you: it doesn't know how to read a file that begins with NIST.

I suspect you'll have to convert the file to WAV if you want to read the file with any of the libraries that you tried. To force the conversion to WAV using the program sph2pipe, use the command option -f wav (or equivalently, -f rif), e.g.

sph2pipe -f wav input.sph output.wav