Open
Description
Thanks to #778, I learned that AudioFile
does not support mp3. (related issues: #475, #704)
It may be a good idea to think about a feature extension that supports mp3 files. (related PR: #507)
Steps to reproduce
$ ffmpeg -i tests/english.wav -vn -ac 2 -ar 44100 -ab 256k -acodec libmp3lame -f mp3 english.mp3
>>> import speech_recognition as sr
>>> with sr.AudioFile("tests/english.wav") as source:
... ...
...
Ellipsis
>>> with sr.AudioFile("english.mp3") as source:
... ...
...
Expected behaviour
No error
Actual behaviour
Traceback (most recent call last):
File "/.../ftnext_speech_recognition/speech_recognition/__init__.py", line 233, in __enter__
self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
File "/.../.pyenv/versions/3.10.9/lib/python3.10/wave.py", line 509, in open
return Wave_read(f)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/wave.py", line 163, in __init__
self.initfp(f)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/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 "/.../ftnext_speech_recognition/speech_recognition/__init__.py", line 238, in __enter__
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 917, in open
return Aifc_read(f)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 352, in __init__
self.initfp(file_object)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 316, 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 "/.../ftnext_speech_recognition/speech_recognition/__init__.py", line 264, in __enter__
self.audio_reader = aifc.open(aiff_file, "rb")
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 917, in open
return Aifc_read(f)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 358, in __init__
self.initfp(f)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/aifc.py", line 314, in initfp
chunk = Chunk(file)
File "/.../.pyenv/versions/3.10.9/lib/python3.10/chunk.py", line 63, in __init__
raise EOFError
EOFError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../ftnext_speech_recognition/speech_recognition/__init__.py", line 266, 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
System information
My system is macOS Sonoma.
My Python version is 3.10.9
My Pip version is 23.3.1
My SpeechRecognition library version is 3.11.0