Calculate duration of ".ds2" file?

121 Views Asked by At

I have a few sample ".ds2" audio files and I need to find the duration of those files. I've done a little bit of research but could not find anything that works for python. Is there any python package or some other way that I can use to get the duration of these files?

1

There are 1 best solutions below

1
On

You can work with this alternative solution incase you can't find the actual one .

I couldn't find any python module which can read .ds2 files. However, python wave module has the .wav file read capability. Hence convert the .ds2 to .wav .

You can follow this link. The program is as follows.

import wave
import contextlib
fname = '/tmp/test.wav'
with contextlib.closing(wave.open(fname,'r')) as f:
    frames = f.getnframes()
    rate = f.getframerate()
    duration = frames / float(rate)
    print(duration)