Skip to content Skip to sidebar Skip to footer

How To Fix 'incomplete Wav Chunk' Error When Reading Wav With Scipy

My problem I'm trying to fit a (machine-learning) model that takes in an audiofile (.wav) and predicts the emotion from it (multi-label classification). I'm trying to read the samp

Solution 1:

I don't know why scipy.io.wavfile can't read the file--there might be an invalid chunk in there that other readers simply ignore. Note that even when I read a "good" file with scipy.io.wavfile, a warning (WavFileWarning: Chunk (non-data) not understood, skipping it.) is generated:

In [22]: rate, data = wavfile.read('fearful_song_strong_dogs_act10_f_1.wav')                              
/Users/warren/mc37/lib/python3.7/site-packages/scipy/io/wavfile.py:273: WavFileWarning: Chunk (non-data) not understood, skipping it.
  WavFileWarning)

I can read 'fearful_song_strong_dogs_act06_f_0.wav' using wavio (source code on github: wavio), a package I created that wraps Python's standard wave library with functions that understand NumPy arrays:

In [13]: import wavio                                                                                     

In [14]: wav = wavio.read('fearful_song_strong_dogs_act06_f_0.wav')                                       

In [15]: wav                                                                                              
Out[15]: Wav(data.shape=(198598, 1), data.dtype=int16, rate=48000, sampwidth=2)

In [16]: plot(np.arange(wav.data.shape[0])/wav.rate, wav.data[:,0])                                       
Out[16]: [<matplotlib.lines.Line2D at 0x117cd9390>]

plot

Solution 2:

I solve the problem by changing this number "4" to "1" in the file wavefile.py file, in this condition of the code: - len(chunk_id) < 1

ifnot chunk_id:
            raise ValueError("Unexpected end of file.")
        eliflen(chunk_id) < 1:
            raise ValueError("Incomplete wav chunk.")

but it was by just intuition and good luck, now i wonder why this works and what are the possible reasons? image

Post a Comment for "How To Fix 'incomplete Wav Chunk' Error When Reading Wav With Scipy"