import speech_recognition as sr
print(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
青春有我
相关分类