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

flac returning ValueError: array is too big #361

Open
AnkS4 opened this issue Dec 14, 2022 · 9 comments
Open

flac returning ValueError: array is too big #361

AnkS4 opened this issue Dec 14, 2022 · 9 comments

Comments

@AnkS4
Copy link

AnkS4 commented Dec 14, 2022

I'm receiving ValueError on reading 'flac'.

with open("123.flac", 'rb') as f:
    _, _ = sf.read(f)

ErrorLog:

ValueError                                Traceback (most recent call last)
/tmp/ipykernel_17098/1860618875.py in <module>
      1 with open("123.flac", 'rb') as f:
----> 2     data, samplerate = sf.read(f)
      3     print(data)
      4     print(samplerate)

~/miniconda3/envs/stealth/lib/python3.8/site-packages/soundfile.py in read(file, frames, start, stop, dtype, always_2d, fill_value, out, samplerate, channels, format, subtype, endian, closefd)
    283                    subtype, endian, format, closefd) as f:
    284         frames = f._prepare_read(start, stop, frames)
--> 285         data = f.read(frames, dtype, always_2d, fill_value, out)
    286     return data, f.samplerate
    287 

~/miniconda3/envs/stealth/lib/python3.8/site-packages/soundfile.py in read(self, frames, dtype, always_2d, fill_value, out)
    886         if out is None:
    887             frames = self._check_frames(frames, fill_value)
--> 888             out = self._create_empty_array(frames, always_2d, dtype)
    889         else:
    890             if frames < 0 or frames > len(out):

~/miniconda3/envs/stealth/lib/python3.8/site-packages/soundfile.py in _create_empty_array(self, frames, always_2d, dtype)
   1318         else:
   1319             shape = frames,
-> 1320         return np.empty(shape, dtype, order='C')
   1321 
   1322     def _check_dtype(self, dtype):

ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.

@bastibe
Copy link
Owner

bastibe commented Dec 19, 2022

What does f.frames contain? It sounds like it contains an unreasonable number.

@Fretless14
Copy link

also getting this error for a flac file

@bastibe
Copy link
Owner

bastibe commented Jun 10, 2023

What does f.frames contain? It sounds like it contains an unreasonable number.

@Fretless14
Copy link

For me it looks like I just made a bad flac file. I used VNC to convert a wav into flac and I must have done something wrong, because I tried another converter and it worked.

@bastibe
Copy link
Owner

bastibe commented Jun 11, 2023

Interesting! I have seen another issue where a malformed file caused similar confusion. That's perhaps good to keep in mind.

@incidentist
Copy link

I'm seeing this error on FLACs generated by tuberipper.com . I don't know what TubeRipper uses to generate FLACs, unfortunately. I can't speak to whether these files are technically malformed, but this file opens in Audacity and VLC but fails with soundfile on Python 3.11:

>>> with open("/Users/incidentist/Desktop/temp/Now Get Busy.flac", "rb") as f:
...     _,_ = soundfile.read(f)
... 
Traceback (most recent call last):
  File "<console>", line 2, in <module>
  File "/Users/incidentist/Library/Caches/pypoetry/virtualenvs/the-tuul-NYeGoq9V-py3.11/lib/python3.11/site-packages/soundfile.py", line 285, in read
    data = f.read(frames, dtype, always_2d, fill_value, out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/incidentist/Library/Caches/pypoetry/virtualenvs/the-tuul-NYeGoq9V-py3.11/lib/python3.11/site-packages/soundfile.py", line 888, in read
    out = self._create_empty_array(frames, always_2d, dtype)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/incidentist/Library/Caches/pypoetry/virtualenvs/the-tuul-NYeGoq9V-py3.11/lib/python3.11/site-packages/soundfile.py", line 1320, in _create_empty_array
    return np.empty(shape, dtype, order='C')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.

@qmeeus
Copy link

qmeeus commented Nov 20, 2023

Hi,

I got the same issue with a flac file recorded with gnome-sound-recorder. Converting it to wav with ffmpeg works though

ffmpeg -i <flac> <wav>

Looks like a bug in pysoundfile

[EDIT]: After some digging, I found out that when a Soundfile instance is created from a flac file, self.frames is set to 9223372036854775807, although I have no clue why

@bastibe
Copy link
Owner

bastibe commented Nov 28, 2023

This is a backend issue with libsndfile, the library soundfile uses to open audio files. Please check there if this is a known bug. Soundfile currently lags behind libsndfile by one release, so it is possible that it is already fixed upstream.

Since you mentioned pysoundfile. I hope that's a typo. Pysoundfile is severely outdated. Use soundfile instead.

@JainVidit12
Copy link

Hi,

I got the same issue on soundfile.

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

6 participants