Python 读取 mp3 文件时遇到问题
Python having problem with reading mp3 file
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
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
self.audio_reader = aifc.open(aiff_file, "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 358, in __init__
self.initfp(f)
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 314, in initfp
chunk = Chunk(file)
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\chunk.py", line 63, in __init__
raise EOFError
EOFError
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\kubar\OneDrive\Pulpit\men.py", line 7, in <module>
with file_audio as source:
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 236, in __enter__
raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format")
ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
MP3 是一种压缩格式。处理音频时切勿使用它,因为大多数处理音频的工具都是在非压缩音频流上进行的。因此,即使此类工具接受了您的文件,它也可能从转换文件开始,这会消耗时间和空间。此外,MP3 从未被从事音频工作的专业人员(音乐家、工程师等)使用:避免将其与对您的工作有一定重要性的音频材料一起使用(即使用于存档,因为压缩是不可逆的),总是喜欢使用非压缩格式改为 WAV 或 AIF(这里的图书馆似乎期望 AIF)。
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
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 234, in __enter__
self.audio_reader = aifc.open(aiff_file, "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 358, in __init__
self.initfp(f)
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 314, in initfp
chunk = Chunk(file)
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\chunk.py", line 63, in __init__
raise EOFError
EOFError
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\kubar\OneDrive\Pulpit\men.py", line 7, in <module>
with file_audio as source:
File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 236, in __enter__
raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format")
ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
MP3 是一种压缩格式。处理音频时切勿使用它,因为大多数处理音频的工具都是在非压缩音频流上进行的。因此,即使此类工具接受了您的文件,它也可能从转换文件开始,这会消耗时间和空间。此外,MP3 从未被从事音频工作的专业人员(音乐家、工程师等)使用:避免将其与对您的工作有一定重要性的音频材料一起使用(即使用于存档,因为压缩是不可逆的),总是喜欢使用非压缩格式改为 WAV 或 AIF(这里的图书馆似乎期望 AIF)。