首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >wave.Error:文件不是以RIFF id开头

wave.Error:文件不是以RIFF id开头
EN

Stack Overflow用户
提问于 2016-06-20 23:20:44
回答 3查看 5.5K关注 0票数 2

我正在尝试使用SpeechRecognition库(https://pypi.python.org/pypi/SpeechRecognition/)。运行下面的示例代码(full example)时:

代码语言:javascript
复制
#!/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

我收到这个错误:

代码语言:javascript
复制
/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

如何解决这个问题?

EN

回答 3

Stack Overflow用户

发布于 2018-05-28 18:10:15

我有一段时间同样的问题,我的错误是下载的wav文件使用“另存为”。当我双击播放wav文件时,我无法使用任何播放器播放wav文件。克隆或下载整个zip文件后,我可以播放wav文件,错误消失了。

票数 1
EN

Stack Overflow用户

发布于 2020-10-01 04:42:48

您的wav文件可能已损坏。若要检查,请尽可能使用任何媒体播放器播放该文件。将音频文件正确下载到您的环境中,然后它就应该可以工作了。

当我以不正确的方式下载文件时,我就遇到了这个问题,我在google colab中使用以下命令下载了音频文件

代码语言:javascript
复制
[!wget 'https://github.com/mozilla/DeepSpeech/blob/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']

这抛出一个错误,因为音频文件已损坏(无法在下载时播放我的媒体播放器)。我通过以下方式解决了这个问题:

代码语言:javascript
复制
[!wget 'https://raw.githubusercontent.com/mozilla/DeepSpeech/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']
票数 0
EN

Stack Overflow用户

发布于 2021-02-09 05:59:54

无论如何,当我存储在存储库中的git LFS WAV文件没有被正确克隆时,我遇到了这个问题。它们的指针存在,但文件不存在。一个

git lfs pull

已修复此问题。

也就是说,当你指向的文件实际上不是一个“完整”的音频文件时,这种情况就会发生。希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37926160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档