2012-04-17 25 views
1

这可能吗?我似乎使用wavread时从scikits.audiolab将收到此错误:将TIMIT数据库中的Nist Wav文件读入python numpy array

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) 

我猜它无法读取NIST的WAV文件,但有另一种方式来轻松地阅读它们放入一个numpy的阵列?如果不是,那么读数据的最好方法是什么?

可能重写audiolab wavread识别nist头?

回答

3

回答我自己的问题,因为找出了它,但您可以使用scikits.audiolab中的Sndfile类,它支持多种读取和写入文件格式,具体取决于您拥有的libsndfile。然后你只需使用:

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

要使用scikits.audiolab当在ĴSPEN的回答,扩大,如果你想阅读整个文件,而不仅仅是帧的指定号码,就可以使用Sndfile类的nframes参数阅读整个事情。例如:

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

我在文档中找不到任何对此的引用,但它在源代码中存在。