import speech_recognition as srprint(sr.__version__)r = sr.Recognizer()file_audio = sr.AudioFile('damn1.mp3')with file_audio as source: audio_text = r.record(source)print(type(audio_text))print(r.recognize_google(audio_text))我运行这个程序时遇到问题。我得到的输出如下:Traceback (most recent call last): File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__ self.audio_reader = wave.open(self.filename_or_fileobject, "rb") File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 510, in open return Wave_read(f) File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 164, in __init__ self.initfp(f) File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 131, in initfp raise Error('file does not start with RIFF id')wave.Error: file does not start with RIFF id在处理上述异常的过程中,又出现了一个异常:Traceback (most recent call last): File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__ self.audio_reader = aifc.open(self.filename_or_fileobject, "rb") File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 917, in open return Aifc_read(f) File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 352, in __init__ self.initfp(file_object) File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 316, in initfp raise Error('file does not start with FORM id')aifc.Error: file does not start with FORM id
1 回答
青春有我
TA贡献1784条经验 获得超8个赞
MP3 是一种压缩格式。操作音频时切勿使用它,因为大多数处理音频的工具都是在非压缩音频流上进行操作的。因此,即使此类工具接受您的文件,它也可能会首先对其进行转换,这会消耗时间和空间。此外,从事音频工作的专业人士(音乐家、工程师等)从不使用 MP3:避免将其与对您的工作具有一定重要性的音频材料一起使用(即使是存档,因为压缩是不可逆的),总是更喜欢使用非压缩格式作为 WAV 或 AIF 代替(这里库似乎期望 AIF)。
添加回答
举报
0/150
提交
取消