-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnormalize_wavs.sh
executable file
·59 lines (56 loc) · 1.47 KB
/
normalize_wavs.sh
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
#!/bin/bash
#
# Generates normalized wav based on the wav
# files found in $FOLDER recursively.
#
# - Requires: sox
#
# - Example:
# wavs/file0.wav
# wavs/file1.wav
# wavs/folder0/file2.wav
#
# # With DELTA=5, MIN=-10, MAX=0, generates:
# wavs/file0_norm_0.wav
# wavs/file0_norm_-5.wav
# wavs/file0_norm_-10.wav
# wavs/file1_norm_0.wav
# wavs/file1_norm_-5.wav
# wavs/file1_norm_-10.wav
# wavs/folder0/file2_norm_0.wav
# wavs/folder0/file2_norm_-5.wav
# wavs/folder0/file2_norm_-10.wav
#
# # If run again, nothing is re-produced unless
# # new wav files are added.
#
#
# - Hint: Change sox command if needed!
#
#
# - Author: luismartingil
# - Year: 2014
#
MIN=-50 # Min normalization level (sox `norm`)
MAX=0 # MAX normalization level (sox `norm`)
DELTA=5 # Ticks - Output wavs every $DELTA from MIN to MAX
FOLDER=wavs # Folder to look for the *.wav files recursively
STAMP=_norm_ # Stamped string to be attached to new normalized files
hash sox 2>/dev/null || { echo >&2 "sox needed"; exit 1; }
# Let's go!
for audio in `find $FOLDER/ -name "*.wav" -type f`; do
if [[ $audio != *$STAMP* ]]; then # Dont want to regenerate normalized ones
for i in $(seq $MIN $DELTA $MAX); do
NAME="${audio%.*}"$STAMP$i.wav
if [ ! -f $NAME ]; then
echo "Processing: "$NAME
# sox command
sox $audio --encoding signed-integer --bits 16 -c 1 -r 8000 $NAME norm $i
else
echo "Already exists: "$NAME
fi
done
else
echo "Already normalized: "$audio
fi
done