我正在使用Python中的语音识别包对某些音频文件进行转码,并且在记录文件时遇到KeyError(io.BufferedReader)。我不太确定这是什么意思或如何解决。任何帮助将不胜感激。
下面是我的代码和错误。
import speech_recognition as sr
r = sr.Recognizer()
AudioFile = sr.AudioFile('/Users/USERNAME/Audio_file.wav')
with AudioFile as source:
audio = r.record(source)
预期结果:
带有音频记录的字符串变量。
实际结果:以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in <module>
File "/Users/USERNAME/anaconda2/envs/python_sr/lib/python3.7/site-packages/speech_recognition/__init__.py",line 295, in __exit__ self.audio_reader.close()
File "/Users/USERNAME/anaconda2/envs/python_sr/lib/python3.7/wave.py", line 194, in close file.close() File "<string>", line 131, in close
KeyError: <_io.BufferedReader name='/Users/USERNAME/Audio_file.wav'>