Skip to content Skip to sidebar Skip to footer

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)

Solution 1:

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

Solution 2:

To expand upon J Spen's answer, when using scikits.audiolab, if you want to read the whole file, not just a specified number of frames, you can use the nframes parameter of the Sndfile class to read the whole thing. For example:

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

I couldn't find any references to this in the documentation, but it is there in the source.


Solution 3:

In contrast to the above answers, there is another alternative way to read audio files in multiple formats, e.g., .wav, .aif, .mp3 etc.

import matplotlib.pyplot as plt
import soundfile as sf
import sounddevice as sd
# https://freewavesamples.com/files/Alesis-Sanctuary-QCard-Crotales-C6.wav
data, fs = sf.read('Alesis-Sanctuary-QCard-Crotales-C6.wav')
print(data.shape,fs)
sd.play(data, fs, blocking=True)
plt.plot(data)
plt.show()

Output:

(88116, 2) 44100

enter image description here


Post a Comment for "Read Nist Wav File In TIMIT Database Into Python Numpy Array"