Read Nist Wav File in TIMIT database into python numpy array

流过昼夜 提交于 2019-12-11 13:51:16

问题


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)
     96 
     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??


回答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



回答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.



来源:https://stackoverflow.com/questions/10187043/read-nist-wav-file-in-timit-database-into-python-numpy-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!