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

JSONDecodeError with AudioSegment when reading from bytesio #770

Open
Bloctans opened this issue Jan 2, 2024 · 0 comments
Open

JSONDecodeError with AudioSegment when reading from bytesio #770

Bloctans opened this issue Jan 2, 2024 · 0 comments

Comments

@Bloctans
Copy link

Bloctans commented Jan 2, 2024

Steps to reproduce

put this code in a script:

from pydub import AudioSegment
from io import BytesIO

real_audio = BytesIO(open("a.mp3", "rb").read())
real_audio.seek(0)

audio = AudioSegment.from_file(real_audio)

make sure to put the attached audio file in the same folder
and run the script

Expected behavior

The script should not error??

Actual behavior

When i run the script i get this:

Traceback (most recent call last):
  File "C:\Users\MYUSERNAME\Documents\GitHub\WZBot\tests\pydubtest.py", line 7, in <module>
    audio = AudioSegment.from_file(real_audio)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python12\Lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python12\Lib\site-packages\pydub\utils.py", line 279, in mediainfo_json
    info = json.loads(output)
           ^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python12\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python12\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python12\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Your System configuration

  • Python version: 3.12.0
  • Pydub version: 0.25.1
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version: ffmpeg-2024-01-01-git-e1c1dc8347-essentials_build

Is there an audio file you can include to help us reproduce?

You can include the audio file in this issue - just put it in a zip file and drag/drop the zip file into the github issue.
a.zip

my workaround would be to take the raw bytes and put them into a temp folder as file, running it and then removing the file
I have tried just inputting the file directly and it works, however i cannot do this for my use case of pydub (unless there is no choice but to use the workaround i listed above)
(most likely not an issue with ffmpeg)

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

No branches or pull requests

1 participant