Python 无法使用scipy.io.wavread.read()读取某些.wav文件
我正在尝试使用scipy.io.wavread读取.wav文件。它正确地读取一些文件。 对于某些文件,它给出以下错误Python 无法使用scipy.io.wavread.read()读取某些.wav文件,python,scipy,Python,Scipy,我正在尝试使用scipy.io.wavread读取.wav文件。它正确地读取一些文件。 对于某些文件,它给出以下错误 Warning (from warnings module): File "D:\project\cardiocare-1.0\src\scipy\io\wavfile.py", line 121 warnings.warn("chunk not understood", WavFileWarning) WavFileWarning: chunk not unders
Warning (from warnings module):
File "D:\project\cardiocare-1.0\src\scipy\io\wavfile.py", line 121
warnings.warn("chunk not understood", WavFileWarning)
WavFileWarning: chunk not understood
Traceback (most recent call last):
File "D:\project\cardiocare-1.0\src\ccare\plot.py", line 37, in plot
input_data = read(p.bitfile)
File "D:\project\cardiocare-1.0\src\scipy\io\wavfile.py", line 119, in read
data = _read_data_chunk(fid, noc, bits)
File "D:\project\cardiocare-1.0\src\scipy\io\wavfile.py", line 56, in _read_data_chunk
data = data.reshape(-1,noc)
ValueError: total size of new array must be unchanged
有谁能给我建议解决方案吗?我使用下面的代码来读取wav文件。我知道这并不能解决你的问题,但是maybee你可以用这段代码阅读你的wav文件,也许能找出问题所在 我的经验是,wav文件有时包含“奇怪”的东西,必须处理或删除 希望它能帮助你 Rgds 赛勒斯
导入波
导入结构
def wavRead(文件名):
波形文件=波形打开(文件'r')
NbChanels=waveFile.getnchannels()
数据=[]
对于范围内的x(NbChanels):
data.append([])
对于范围内的i(0,waveFile.getnframes()):
waveData=waveFile.readframes(1)
data[i%(NbChanels)].append(int(struct.unpack)(“您使用的是什么版本的scipy?我使用的是scipy 0.11.0,我认为这是与python 2.7兼容的版本,问题仍然没有解决..我尝试了最新版本的sicpy,但仍然是相同的问题。。
import wave
import struct
def wavRead(fileN):
waveFile = wave.open(fileN, 'r')
NbChanels = waveFile.getnchannels()
data = []
for x in range(NbChanels):
data.append([])
for i in range(0,waveFile.getnframes()):
waveData = waveFile.readframes(1)
data[i%(NbChanels)].append(int(struct.unpack("<h", waveData)[0]))
RetAR = []
BitDebth = waveFile.getsampwidth()*8
for x in range(NbChanels):
RetAR.append(np.array(data[x]))
RetAR[-1] = RetAR[-1]/float(pow(2,(BitDebth-1)))
fs = waveFile.getframerate()
return RetAR,fs