无法将文件 file.wav 作为 WAV 打开,原因是:文件不以 RIFF id 开头

Ale*_*lex 9 python wav riff mime-types

尝试在 python 中打开 RIFF 文件(据我所知它是一种 WAV)时出现此错误。

Failed to open file file.wav as a WAV due to: file does not start with RIFF id
Run Code Online (Sandbox Code Playgroud)

当我用各种工具检查它这使我相信,这一个真正的WAV / RIFF文件。

$ file file.wav 
file.wav: MBWF/RF64 audio, stereo 96000 Hz


$ file -i file.wav 
file.wav: audio/x-wav; charset=binary




$ mediainfo file.wav 
General
Complete name                            : file.wav
Format                                   : Wave
Format profile                           : RF64
File size                                : 4.10 GiB
Duration                                 : 2h 7mn
Overall bit rate mode                    : Constant
Overall bit rate                         : 4 608 Kbps

Audio
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : 1
Duration                                 : 2h 7mn
Bit rate mode                            : Constant
Bit rate                                 : 4 608 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 96.0 KHz
Bit depth                                : 24 bits
Stream size                              : 4.10 GiB (100%)
Run Code Online (Sandbox Code Playgroud)

kak*_*oon 6

如果你的音频没问题,并且你能够使用 librosa 或 scipy.io 读取该文件,我们可以简单地读取该文件,将其写回临时 wav 文件,然后再次使用 Wave 包读取它。

例子。下面,我们得到 RIFF id 错误。

>>> 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
Run Code Online (Sandbox Code Playgroud)

我们用 librosa 读入 numpy,用声音文件写回。

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>
Run Code Online (Sandbox Code Playgroud)


Ign*_*ams 5

您拥有的是64 位 RIFFwave不支持 64 位 RIFF 文件。