python-soundfile
python-soundfile copied to clipboard
flac returning ValueError: array is too big
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.
What does f.frames contain? It sounds like it contains an unreasonable number.
also getting this error for a flac file
What does f.frames contain? It sounds like it contains an unreasonable number.
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.
Interesting! I have seen another issue where a malformed file caused similar confusion. That's perhaps good to keep in mind.
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.
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
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.
Hi,
I got the same issue on soundfile.