-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalignaudio
executable file
·81 lines (67 loc) · 1.88 KB
/
alignaudio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -e
version="0.1"
USAGE="Usage: `basename $0` [-p] [-m] [-a] files"
PRESERVE_PITCH=0;
USE_COMPARATOR="min"
# Parse command line options.
while getopts "hvpam" OPT; do
case "$OPT" in
h)
echo $USAGE
exit 0
;;
v)
echo "`basename $0` version $version"
exit 0
;;
p)
PRESERVE_PITCH=1
;;
a)
USE_COMPARATOR="avg"
;;
m)
USE_COMPARATOR="max"
;;
:)
echo "option -$OPTARG needs an argument"
;;
\?)
# getopts issues an error message
echo $USAGE >&2
exit 1
;;
esac
done
if [ $PRESERVE_PITCH == 1 ]; then
echo "We are preserving pitch";
fi
shift $(($OPTIND - 1))
filesToProcess="$@"
#echo "Time to process : $filesToProcess"
fileLengths=($(soxi -s $filesToProcess | sort -n) );
#echo ${fileLengths[@]};
if [ $USE_COMPARATOR == "avg" ]; then
targetLength=$(echo ${fileLengths[@]} | tr ' ' '\n' | awk '{total+=$1; count+=1;} END {printf("%.0f\n", total/count)}');
elif [ $USE_COMPARATOR == "max" ]; then
targetLength=${fileLengths[${#fileLengths[@]}-1]};
else
targetLength=${fileLengths[0]};
fi
echo "Targetting $targetLength samples" ;
for file in ${filesToProcess[@]}; do
lengthOfFile=`soxi -s $file`;
if [ $lengthOfFile == $targetLength ]; then
echo "Skipping $file";
else
speed=$(bc <<< "scale = 10; $lengthOfFile / $targetLength")
echo "Processing $file";
fileOut="${file%.*}_aligned.${file#*.}";
echo "sox $file $fileOut speed $speed";
sox -V1 $file $fileOut speed $speed
outLength=`soxi -s $fileOut`;
echo "$fileOut is now $outLength samples";
fi
done
echo "Done!!"