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

Add the number of frames in info

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

I need to get the number of frames in a file before calling blocks. That would be nice to either have info.duration as a float or add a num_frames attribute.

ghost avatar Apr 15 '16 15:04 ghost

As a quick work-around, you can create a SoundFile object (ideally in a with statement), use len() to get the number of frames and then use the blocks() method (instead of the blocks() function).

import soundfile as sf

with sf.SoundFile('myfile.wav') as f:
    frames = len(f)
    for block in f.blocks(1024):
        # do something

mgeier avatar Apr 17 '16 16:04 mgeier