query soundfile length on command line to use in script?

Started by p8rpp, December 01, 2018, 10:08:31 AM

Previous topic - Next topic

p8rpp

Hi,

I would like to use the length of a soundfile as a paramter in another cdp program and would like to do this automatically in a (Unix) shell script. sfprops lists the Duration as
File type:  soundfile
Format         :  Standard WAVE format
Sample Rate    :  44100
Channels       :  1
Sample Frames  :  874292
sample type:   :  16-bit
duration       :  19.8252 secs
no peak data in this infile

and I can grep the duration using
cdp_sfprops infile.wav | grep duration | cut -f 2 -d":" | cut -f 3- -d " " | cut -f 1 -d " "
which gives only
19.8252

Is there a quicker/leaner/shorter way to do this which possibly also works on Windows?

Thank you!


rwdobson

perhaps use the "split" tool after grep, to pull out the duration field?

Re Windows, I suspect trying to use DOS (and maybe even powershell) will be a relatively unhappy experience. You might like to install minGW and the associated Msys shell, which gives you a bash shell and enough of the unix utilities to do most things. Any command you need that isn't provided already can probably be found on the net somewhere. but grep, cut, split etc are all there. I think Cygwin is much the same kind of thing, but I have no experience of that. I use minGW to build all the CDP programs for Windows.

p8rpp

Thanks Richard!
I thought someone must have had had a use for this in the past decades as so many parameters depend on infile length.
cheers, P