1

这可能吗??使用来自 scikits.audiolab 的 wavread 时,我似乎遇到了这个错误:

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 标头?

4

3 回答 3

4

回答我自己的问题,因为想通了,但是您可以使用 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
于 2012-04-17T07:58:33.437 回答
2

为了扩展 J Spen 的答案,在使用scikits.audiolab时,如果您想读取整个文件,而不仅仅是指定数量的帧,您可以使用类的nframes参数Sndfile来读取整个内容。例如:

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

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

于 2016-08-03T20:19:07.190 回答
0

与上述答案相比,还有另一种读取多种格式音频文件的替代方法,例如 .wav、.aif、.mp3 等。

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()

输出:

(88116, 2) 44100

在此处输入图像描述

于 2021-02-10T07:30:14.123 回答