I need to get the length of a .wav file.
Using:
sox output.wav -n stat
Gives:
Samples read: 449718
Length (seconds): 28.107375
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -0.999969
Midline amplitude: 0.000000
Mean norm: 0.145530
Mean amplitude: 0.000291
RMS amplitude: 0.249847
Maximum delta: 1.316925
Minimum delta: 0.000000
Mean delta: 0.033336
RMS delta: 0.064767
Rough frequency: 660
Volume adjustment: 1.000
How do I use grep or some other method to only output the value of the length in the second column, i.e. 28.107375?
Thanks
This can be done by using:
soxi -D input.mp3
the output will be the duration directly in secondssoxi -d input.mp3
the output will be the duration with the following format hh:mm:ss.ssThere is my solution for C# (unfortunately
sox --i -D out.wav
returns wrong result in some cases):I just added an option for JSON output on the 'stat' and 'stats' effects. This should make getting info about an audiofile a little bit easier.
https://github.com/kylophone/SoxJSONStatStats
This worked for me (in Windows):
The
stat
effect sends its output tostderr
, use2>&1
to redirect tostdout
. Usesed
to extract the relevant bits:In CentOS