-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpromptConvert.sh
More file actions
executable file
·82 lines (71 loc) · 2.33 KB
/
Copy pathpromptConvert.sh
File metadata and controls
executable file
·82 lines (71 loc) · 2.33 KB
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
82
#!/bin/bash
. /etc/init.d/functions
starttime=`date +"%Y-%m-%d_%H-%M-%S"`
LOG="promptConvert.log"
STARTPATH="."
if [ $# -eq 1 ]; then
STARTPATH=$1
fi
COUNT=0
echo "Start time is $starttime" > $LOG
echo " STARTPATH=$STARTPATH" >> $LOG
# Use step(), try(), and next() to perform a series of commands and print
# [ OK ] or [FAILED] at the end. The step as a whole fails if any individual
# command fails.
step() {
echo -n -e "$@"
echo -e "\n\nSTEP - $@"&>> $LOG
STEP_OK=0
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
}
next() {
[[ -f /tmp/step.$$ ]] && { STEP_OK=$(< /tmp/step.$$); rm -f /tmp/step.$$; }
[[ $STEP_OK -eq 0 ]] && echo_success || echo_failure
echo
return $STEP_OK
}
setpass() {
echo -n "$@"
STEP_OK=0
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
}
#START
#check if sox is installed
step "Checking for sox tool"
command -v sox >/dev/null 2>&1 || { echo >&2 "Script requires sox (SoX) but it's not installed. Please install via package manager before proceeding"; exit 1; }
setpass
next
step "Converting:\n"
# can be installed via yum install sox
# for AMR confersion, you will need the aditional libs
# yum install opencore-amr
#FILELIST=$(find $STARTPATH \( -name '*.WAV' -or -name '*.wav' -type f \) -print0 )
#for f in $FILELIST; do
for f in $STARTPATH/* $STARTPATH/**/* ; do
if [ -f "$f" ]
then
#only supporting WAV or wav files in this convert
if [[ $f =~ .*\.(WAV|wav) ]]
then
let COUNT=COUNT+1
echo "============================== $f ========================================" >> $LOG
soxi "$f" >> $LOG
filebase=`echo $f | rev | cut -f 2- -d '.' | rev`
SOXARGS="-b 8 -c 1 -r 8k -e u-law "
echo " Filebase=$filebase" >> $LOG
echo " Creating ulaw Version via sox $f $SOXARGS "$filebase".ul" >> $LOG
sox "$f" $SOXARGS "$filebase".ul &>> $LOG
echo " Convert complete - new file information" >> $LOG
soxi "$filebase".ul &>> $LOG
echo " renaming "$filebase".ul file to "${filebase,,}".ulaw" >> $LOG
mv "$filebase".ul "${filebase,,}".ulaw &>> $LOG
echo "#$COUNT: $f => "${filebase,,}".ulaw" | tee -a $LOG
#echo " Creating AMR Version" >> $LOG
#sox $f -b 8 -c 1 -r 16k -e u-law {$filebase}.ul &>> $LOG
fi
fi
done
setpass
echo -e -n "\n\nProcess complete, $COUNT files converted "
next
echo -e "\nSee $LOG for details."