简体   繁体   English

wave.Error: file does not start with RIFF id

[英]wave.Error: file does not start with RIFF id

I am trying to use the SpeechRecognition library (https://pypi.python.org/pypi/SpeechRecognition/). When running the example code (full example) below:

#!/usr/bin/env python3

import speech_recognition as sr

# obtain path to "english.wav" in the same folder as this script
from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav")
#AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
#AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")

# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
    audio = r.record(source) # read the entire audio file

I receive this error:

/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/adamg/te/Polli/ASR/SpeechRecognitionTest0.py
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 174, in __enter__
    self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 497, in open
    return Wave_read(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 163, in __init__
    self.initfp(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 130, in initfp
    raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 179, in __enter__
    self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 887, in open
    return Aifc_read(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 340, in __init__
    self.initfp(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 305, in initfp
    raise Error('file does not start with FORM id')
aifc.Error: file does not start with FORM id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/adamg/te/Polli/ASR/SpeechRecognitionTest0.py", line 13, in <module>
    with sr.AudioFile(AUDIO_FILE) as source:
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 199, in __enter__
    self.audio_reader = aifc.open(aiff_file, "rb")
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 887, in open
    return Aifc_read(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 340, in __init__
    self.initfp(f)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 303, in initfp
    chunk = Chunk(file)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/chunk.py", line 63, in __init__
    raise EOFError
EOFError

Process finished with exit code 1

How can this be fixed?

I had the same problem for a while, my mistake is to download the wav file using "save as". When I double click to play the wav file, I am not able to play the wav file using any player. After cloning or downloading the entire zip file, I am able to play the wav file and the error disappears.

Your wav file is probably corrupted. To check try to play the file using any media player if possible. Download the audio file into your environment correctly and then it should work.

I have faced this issue when I did a mistake by downloading the file the incorrect way, I downloaded the audio file using the following command in the google colab:

[!wget 'https://github.com/mozilla/DeepSpeech/blob/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']

This threw an error as the audio file was corrupted(could not be played my media player when downloaded). I was able to correct the issue by downloading the following way:

[!wget 'https://raw.githubusercontent.com/mozilla/DeepSpeech/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']

For what it's worth, I ran into this problem when git LFS WAV files I had stored in a repo were not cloned properly. Their pointers were present, but the files were not. A

git lfs pull

fixed the problem.

That being said, this might just happen any time you a file is pointed to that isn't actually an audio file that is "complete". Hopefully that helps!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:文件不以 RIFF id 开头 - Error: file does not start with RIFF id pyglet.media.codecs.wave.WAVEFormatException:文件不是以RIFF ID开头 - pyglet.media.codecs.wave.WAVEFormatException: file does not start with RIFF id 无法将文件 file.wav 作为 WAV 打开,原因是:文件不以 RIFF id 开头 - Failed to open file file.wav as a WAV due to: file does not start with RIFF id wave.Error: unknown format: 3 尝试在 Python 中将 wav 文件转换为文本时出现 - wave.Error: unknown format: 3 arises when trying to convert a wav file into text in Python 由 PyDub AudioSegment.split_on_silence() 产生的 .WAV 音频在使用 wave.open 读取时没有 RIFF ID - .WAV Audio Produced by PyDub AudioSegment.split_on_silence() has no RIFF ID when reading with wave.open 将 mp3 转录为文本 (python) --&gt; “RIFF id”错误 - Transcribing mp3 to text (python) --> “RIFF id” error librosa 不规范 [-1, 1] 之间的波形文件 - librosa does not normalize wave file between [-1, 1] 使用python下采样WAV RIFF文件 - Downsample wav RIFF file using python 我收到无法理解的文件格式 b'\x1aE\xdf\xa3'。 当我想读取 wav 格式的音频文件时,只有 'RIFF' 和 'RIFX' 支持错误 - I'm getting File format b'\x1aE\xdf\xa3' not understood. Only 'RIFF' and 'RIFX' supported error when I want to read a wav format audio file tensorflow 音频识别错误“标题不匹配:预期 RIFF 但找到” - tensorflow audio recognition error 'Header mismatch: Expected RIFF but found '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM