Can the sox command handle variables in shell scripts
Hi,
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 Code:
#!/bin/bash 1.059 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. |
The problem is that sox writes the gain value to stderr, not stdout. Your script is capturing a null, which is why it's complaining about an invalid value. Use:
Code:
stat=$(sox "$i" louder.wav stat -v 2>&1) |
Quote:
I added the 2>&1 as you said and got this error sox WARN dither: dither clipped 1 samples; decrease volume? sox WARN sox: `Internet radio show.wav' balancing clipped 1 samples; decrease volume? sox FAIL sox: Volume value `sox' is not a number sox FAIL sox: Volume value `Samples' is not a number Very weird... I am using sox v14.3.0 |
Those errors are from the following sox invocation. You may want to echo the stat value and file being processed so that you can see which of the files is having a problem.
|
I am going to continue experimenting. If sox can't handles variables, I'll have to use the normalize command instead.
|
Quote:
In my first post I did the sox gain manually by typing it in the terminal. like so. sox "Internet radio show.wav" louder.wav stat -v 1.059 And got that value 1.059, next I applied the gain by tying sox -v 1.059 "Internet radio show.wav" tmp/"Internet radio show.wav" And it works. Only when I type it directly in the terminal. But it does not work in a shell script. Which I don't understand way |
As I said, you won't know until you echo the stat value and file being processed so that you can see which of the files is having a problem.
|
Quote:
echo sox -v $stat "$i" tmp/"$i" The first file "Internet Radio Show.wav" went without any problems. However, the file louder.wav was the culprit. This is the temp file sox uses to write to. So, instead of having louder.wav in the same directory with the wav files. I tell sox to write louder.wav elsewhere like so stat=$(sox "$i" ../louder.wav stat -v 2>&1) I want to thank you for those helpful suggestions. A reputation will be added to you. :) BTW, I saw this sox usage from this website. Linux Cookbook http://dsl.org/cookbook/cookbook_29.html Scroll down to Changing the Amplitude of a Sound File |
All times are GMT -5. The time now is 12:14 AM. |