Failed to open file file.wav as a WAV due to: file does not start with RIFF id

和自甴很熟 提交于 2019-12-06 10:49:54

What you have is a 64-bit RIFF. wave does not support 64-bit RIFF files.

If your audio is okay, and you are able to read the file with librosa or scipy.io, we can simply read the file, write it back to a temporary wav file and then read it with the wave package again.

Example. Below, we get the RIFF id error.

>>> import wave
>>> wave.open('./SA1.WAV')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pytorch/anaconda3/lib/python3.6/wave.py", line 499, in open
    return Wave_read(f)
  File "/home/pytorch/anaconda3/lib/python3.6/wave.py", line 163, in __init__
    self.initfp(f)
  File "/home/pytorch/anaconda3/lib/python3.6/wave.py", line 130, in initfp
    raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id

We read into numpy with librosa, write back with soundfile.

import librosa
import soundfile as sf
>>> x,_ = librosa.load('./SA1.WAV', sr=16000)
>>> sf.write('tmp.wav', x, 16000)
>>> wave.open('tmp.wav','r')
<wave.Wave_read object at 0x7fbcb4c8cf28>

I have a word-around, I rename the file's suffix to "mp3" and convert it to "wav", then I could be able to read it.

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