Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a WAV file from TIMIT database in python

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

like image 654
okuoub Avatar asked Jun 25 '17 16:06

okuoub


People also ask

What library is used to read and write sound files Python?

The python-sounddevice and pyaudio libraries provide ways to record audio with Python. python-sounddevice records to NumPy arrays and pyaudio records to bytes objects.

How to read WAV files in Python?

The wave module in Python's standard library is an easy interface to the audio WAV format. The functions in this module can write audio data in raw format to a file like object and read the attributes of a WAV file.

How to work with audio files using Python?

So let’s see how to work with audio files using Python. Python provides a module called pydub to work with audio files. pydub is a Python library to work with only .wav files. By using this library we can play, split, merge, edit our . wav audio files. This module does not come built-in with Python.

How to read/write audio data from a file using Wave module?

The file is opened in 'write' or read mode just as with built-in open () function, but with open () function in wave module This function opens a file to read/write audio data. The function needs two parameters - first the file name and second the mode. The mode can be 'wb' for writing audio data or 'rb' for reading.

How to increase/decrease volume of audio file in Python?

1) Playing Audio File: This is done using play () method. Use Up/Down Arrow keys to increase or decrease volume. 2) Knowing about .wav file: for this we will use attributes of audio file object. 3) Increasing/Decreasing volume of the file: By using ‘ +’ and ‘ -‘ operator. Use Up/Down Arrow keys to increase or decrease volume.


1 Answers

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
like image 172
Warren Weckesser Avatar answered Sep 25 '22 17:09

Warren Weckesser