Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioFile does not support mp3 #784

Open
ftnext opened this issue Nov 3, 2024 · 0 comments
Open

AudioFile does not support mp3 #784

ftnext opened this issue Nov 3, 2024 · 0 comments

Comments

@ftnext
Copy link
Collaborator

ftnext commented Nov 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant