错误:文件不是以RIFF ID开头(Wav)

时间:2019-05-02 15:37:00

标签: python wav google-colaboratory wave riff

我正在尝试将.wav文件从Google驱动器拆分为多个块,但是会引发错误“文件不是以RIFF ID开头”。有没有解决此问题的简单方法?我使用的整个代码-> https://github.com/wiseman/py-webrtcvad/blob/master/example.py

import collections
import contextlib
import sys
import wave

import webrtcvad

path = 'drive/My Drive/Garsynas/D05/Z020/Z005Mf_020_01.wav'
def read_wave(path):
    """Reads a .wav file.
    Takes the path, and returns (PCM audio data, sample rate).
    """
    with contextlib.closing(wave.open(path, 'rb')) as wf:
        num_channels = wf.getnchannels()
        assert num_channels == 1
        sample_width = wf.getsampwidth()
        assert sample_width == 2
        sample_rate = wf.getframerate()
        assert sample_rate in (8000, 16000, 32000, 48000)
        pcm_data = wf.readframes(wf.getnframes())
        return pcm_data, sample_rate

...

def main(args):
    if len(args) != 2:
        sys.stderr.write(
            'Usage: example.py <aggressiveness> <path to wav file>\n')
        sys.exit(1)
    audio, sample_rate = read_wave(args[1])
    vad = webrtcvad.Vad(int(args[0]))
    frames = frame_generator(30, audio, sample_rate)
    frames = list(frames)
    segments = vad_collector(sample_rate, 30, 300, vad, frames)
    for i, segment in enumerate(segments):
        path = 'chunk-%002d.wav' % (i,)
        print(' Writing %s' % (path,))
        write_wave(path, segment, sample_rate)


if __name__ == '__main__':
    main(sys.argv[1:])
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-19-4915635d1696> in <module>()
    146 
    147 if __name__ == '__main__':
--> 148     main(sys.argv[1:])

4 frames
/usr/lib/python3.6/wave.py in initfp(self, file)
    128         self._file = Chunk(file, bigendian = 0)
    129         if self._file.getname() != b'RIFF':
--> 130             raise Error('file does not start with RIFF id')
    131         if self._file.read(4) != b'WAVE':
    132             raise Error('not a WAVE file')

Error: file does not start with RIFF id

0 个答案:

没有答案