I have a simple shell script using the sox command to set a maximum gain value to the audio without clipping or distortion.
For example,I type from a terminal
sox audiofile.wav louder.wav stat -v
The value return is 1.059, which means I can safely increase the volume by that value. The louder.wav can be any name. Sox needs a temporary file to write to.
To commit the change
sox -v 1.059 audiofile.wav tmp/audiofile.wav
Note: The tmp/audiofile.wav is the louder version
Anyway, I put this in a shell script like so
for i in *.wav
# this line gets a stat value for each wav file and stores it in the stat variable
stat=$(sox "$i" louder.wav stat -v)
# this line commits the chances and writes the louder versions to tmp with the same filename..
sox -v $stat "$i" tmp/"$i"
I gave the script a test run in a directory and I get this error.
sox FAIL sox: Volume value `' is not a number
Probably text, not sound
It seems like sox doesn't understand the $stat variable I have set. I even tried sox "$stat" to no effect.
I have many experience writing shells scripts with more complex variables, pattern substitution and expressions and command line programs like ffmpeg, mplayer. mencoder and others understand them.
Does anyone has any ideas or this a bug in sox?
PS: In case you're thinking of telling me to use the normalize command, I did so in the pass. Normalize is a good tool, but sometimes it distorts the audio.