My question is similar to a previous question about "get-mean-amplitude-of-wav-from-sox":
Get Mean amplitude(only) of .wav from sox
I would like to be able to use the stats sox to do batch measurements of 1,000's of .wav files in a directory, and store the results in a data frame or some similar structure I can save as a csv text file.
For one sound file, the code would be:
./sox SampleSound.wav -n stat
Resulting in the following output:
Samples read: 72000000
Length (seconds): 3600.000000
Scaled by: 2147483647.0
Maximum amplitude: 0.778809
Minimum amplitude: -1.000000
Midline amplitude: -0.110596
Mean norm: 0.062671
Mean amplitude: -0.008131
RMS amplitude: 0.172914
Maximum delta: 1.778809
Minimum delta: 0.000000
Mean delta: 0.014475
RMS delta: 0.057648
Rough frequency: 1061
Volume adjustment: 1.000
I would like to: - take batch measurements on 1,000's of sound files in a given directory, - capture the stats output in columns along with the sound file name that was measured, - and export for use as covariates in an analysis in R.
Thanks!
Matthew
First you will need to perform a system call to
sox
, and capture its output. For example:Setting
intern = TRUE
returns the output of the command to a variable. Strangely,sox
provides its output tostderr
and notstdout
, hence the need for2>&1
. The best way forward now is to wrap this in a function which also postprocesses the output ofsystem
:Next you can wrap this in an apply loop to get all the stats from a given directory:
To extract only the
value
column, which contains the stats you need: