python-soundfile icon indicating copy to clipboard operation
python-soundfile copied to clipboard

Can't read a SoundFile object for a wav file

Open toddrjen opened this issue 9 years ago • 1 comments
trafficstars

It is impossible to read a wav file contained in a SoundFile object without specify a length, even though it is possible for the read function. Consider this (using the PySoundFile test file mono.wav):

>>> import soundfile as sf
>>>
>>> sf.read('mono.wav')
(array([  0.00000000e+00,   3.05175781e-05,   6.10351562e-05,
         -6.10351562e-05,  -3.05175781e-05]), 44100)
>>> sobj = sf.SoundFile('mono.wav', 'r')
>>> sobj.read()
ValueError                                Traceback (most recent call last)
<ipython-input-9-8c7a6773277d> in <module>()
----> 1 sobj.read()

/usr/lib/python3.5/site-packages/soundfile.py in read(self, frames, dtype, always_2d, fill_value, out)
    944         """
    945         if out is None:
--> 946             frames = self._check_frames(frames, fill_value)
    947             out = self._create_empty_array(frames, always_2d, dtype)
    948         else:

/usr/lib/python3.5/site-packages/soundfile.py in _check_frames(self, frames, fill_value)
   1328                 frames = remaining_frames
   1329         elif frames < 0:
-> 1330             raise ValueError("frames must be specified for non-seekable files")
   1331         return frames
   1332 

ValueError: frames must be specified for non-seekable files

I would think that if it is possible to call sf.read(fname) on a file, it would also be possible to call read() on an object for the same file.

toddrjen avatar Apr 13 '16 20:04 toddrjen

It looks like you are using libsndfile version 1.0.26, which is broken, see #158 and https://github.com/erikd/libsndfile/issues/124. You should install version 1.0.25 (at least until 1.0.27 is out).

mgeier avatar Apr 14 '16 07:04 mgeier