sudo apt-get install sox
audio info
soxi xxx.wav
sox xxx.wav -n stats
#!/bin/sh
if [ "$1" = "-h" ]; then
echo " Usage: ./test2.sh -22.99
This will generate a new file that to modify the volume value
"
exit 0
fi
echo
############## start work #############
target=$(echo | awk "{print $1}" | sed 's/-//g') #取正數
$(mkdir new_files)
for file in *.wav
do
RMS_lev=$(sox $file -n stats 2>&1 | grep "RMS lev dB" | cut -d " " -f 7)
echo $file="$RMS_lev"
diff=$(echo | awk "{print $target+$RMS_lev}")
#echo $diff
intV=$(echo $diff | cut -d "." -f 1) #整數
#echo $intV
if [ $intV -lt 0 ]; then #小於
echo "< 0"
a=$(echo | awk "{print $diff}" | sed 's/-//g') #取正數
sox $file new_files/$file vol $a dB
elif [ $intV -eq -0 ]; then
echo "= -0"
a=$(echo | awk "{print $diff}" | sed 's/-//g') #取正數
sox $file new_files/$file vol $a dB
elif [ $intV -eq 0 ]; then
echo "= 0"
sox $file new_files/$file vol -$diff dB
else
echo "> 0"
sox $file new_files/$file vol -$diff dB
fi
done
sox command:
1. sox xxx.wav -n stats
2. sox xxx.wav -n stat
3. sox infile.wav outfile.wav vol 3 dB stats
ref:
1. 使用awk进行数字计算,保留指定位小数
2. stackoverflow
3. ubuntu forums
沒有留言:
張貼留言