Author Topic: query soundfile length on command line to use in script?  (Read 286 times)

p8rpp

  • Sr. Member
  • ****
  • Posts: 57
    • View Profile
query soundfile length on command line to use in script?
« on: December 01, 2018, 10:08:31 AM »
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

  • Sr. Member
  • ****
  • Posts: 69
    • View Profile
Re: query soundfile length on command line to use in script?
« Reply #1 on: December 01, 2018, 11:51:09 AM »
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

  • Sr. Member
  • ****
  • Posts: 57
    • View Profile
Re: query soundfile length on command line to use in script?
« Reply #2 on: December 01, 2018, 12:07:50 PM »
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