Reading WAV file from TIMIT database in python

I am trying to read a wav file from TIMIT database in python, but I am getting an error:

When I use wave:

wave.Error: file does not start with RIFF id

      

When I use scipy:

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

      

and when i use librosa the program gets 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 the scikits.audiolab package, but it looks like it is no longer supported.

How can I read this file to get an ndarray of data?

thank

+3


source to share


3 answers


Your file is not a WAV file. Apparently this is the NIST SPHERE file. From the LDC web page : "Many LDC corporations contain NIST SPHERE speech files." According to the NIST File Format , the first four characters of a NIST

. This is what scipy tells you: it doesn't know how to read a file that starts with NIST

.

I suspect that you need to convert the file to WAV if you want to read the file from any of the libraries you've tried.To force the conversion to WAV using a program sph2pipe

, use the command -f wav

(or, equivalently, -f rif

), for example



sph2pipe -f wav input.sph output.wav

      

+3


source


issue this from command line to check its wav file ... or not

xxd -b myaudiofile.wav | head

      

if its wav format looks something like

00000000: 01010010 01001001 01000110 01000110 10111100 10101111  RIFF..
00000006: 00000001 00000000 01010111 01000001 01010110 01000101  ..WAVE
0000000c: 01100110 01101101 01110100 00100000 00010000 00000000  fmt ..
00000012: 00000000 00000000 00000001 00000000 00000001 00000000  ......
00000018: 01000000 00011111 00000000 00000000 01000000 00011111  @...@.
0000001e: 00000000 00000000 00000001 00000000 00001000 00000000  ......
00000024: 01100100 01100001 01110100 01100001 10011000 10101111  data..
0000002a: 00000001 00000000 10000001 10000000 10000001 10000000  ......
00000030: 10000001 10000000 10000001 10000000 10000001 10000000  ......
00000036: 10000001 10000000 10000001 10000000 10000001 10000000  ......

      

Please note that the wav file starts with RIFF characters which is a mandatory indicator, the file uses wav codec ... if your system (I'm on linux) does not have the above command line utility: xxd then use any hex editor like wxHexEditor to similarly examine your wav file to confirm that you see RIFF ... if there is no RIFF then its just not a wav file

Here are the details of the wav format specifications

http://soundfile.sapp.org/doc/WaveFormat/

http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html



http://unusedino.de/ec64/technical/formats/wav.html

http://www.drdobbs.com/database/inside-the-riff-specification/184409308

https://www.gamedev.net/articles/programming/general-and-gameplay-programming/loading-a-wave-file-r709

http://www.topherlee.com/software/pcm-tut-wavformat.html

http://www.labbookpages.co.uk/audio/javaWavFiles.html

http://www.johnloomis.org/cpe102/asgn/asgn1/riff.html

http://nagasm.org/ASL/sound05/

+1


source


If you want generic code that works for every wav file inside a folder:

forfiles /s /m *.wav /c "cmd /c sph2pipe -f wav @file @fnameRIFF.wav"

      

It searches every wav file it can find and create a wav file that both scipy and wave can read with the name <base_name> RIFF.wav

0


source







All Articles