-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathep_133_sample_converter.sh
executable file
·75 lines (63 loc) · 1.24 KB
/
ep_133_sample_converter.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
req-check() {
declare -a REQUIREMENTS=("sox" "ffmpeg")
for i in "${REQUIREMENTS[@]}"
do
REQ_TEST=$(which $i)
if [ "$REQ_TEST" == "" ]
then
message "Install $i" "$i is not installed. install $i from your package manager."
exit
fi
done
}
help-menu() {
cat <<EOF
---------------------------
ep-133 sample converter
---------------------------
EOF
}
message() {
cat <<EOF
-${1}-
$2
EOF
}
arg-check() {
#COUNTER=0
COUNTER=$(echo $@ | wc -w | xargs)
if [ $COUNTER -gt 1 ]
then
message "ERROR" "you can only convert one file at a time. run with --help for options"
exit
fi
if [ "$1" == "" ]
then
message "ERROR" "you must input a file. run with --help for options"
exit
elif [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
help-menu
exit
fi
sox --info $1
if [ $? -gt 0 ]
then
message "ERROR" "not a valid audio file"
exit
fi
}
convert_file() {
INPUT_FILE=$1
TRIMMED_NAME=$(basename $INPUT_FILE)
OUTPUT_FILE=${TRIMMED_NAME%.*}
sox $INPUT_FILE -c 1 -r 46875 -b 16 converted/${OUTPUT_FILE}.wav #speed 2.0
}
if ! [ -d converted ]
then
mkdir converted
fi
req-check
arg-check $@
convert_file $1