-
Notifications
You must be signed in to change notification settings - Fork 0
/
findsilence.sh
executable file
·130 lines (109 loc) · 2.25 KB
/
findsilence.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#path to executable file that handles audio files
executable_path="/home/qwerty/FindSilence/findsilence"
#setting default values to parameters
sort_key="-k 1,1 -k 2,2"
threshold=-1
si_duration=0.25
so_duration=0.0625
frq_res=3;
args=( "$@" )
isfloat ()
{
regexp='^[-+]?[0-9]*\.?[0-9]+$'
if [[ $1 =~ $regexp ]]
then
return 1
else
return 0
fi
}
for (( i=0; i < $#; ++i ))
do
case ${args[i]} in
"--help")
printf "Usage: findsilence [OPTIONS]\n\n"
printf " -t FLOAT\tset threshold value (automaticly by default)\n"
printf " -ms FLOAT\tset minimum silence duration value (default value is %f)\n" $si_duration
printf " -mS FLOAT\tset minimum sound duration value (default value is %f)\n" $so_duration
printf " -st\t\tsort by time, when event occurred\n"
printf " -sc\t\tsort by channel, where event occurred (default)\n"
printf " -f UINT \tset frequency domain resolution ([1-5], default value is %d)\n\n" $frq_res
printf "Example:\n"
printf " $ findsilence -t 0.5 -m 0.25 -st\n\n"
exit 0
;;
"-t")
isfloat ${args[++i]}
if [ $? == 0 ]
then
echo "Wrong threshold value -- ${args[i]}"
exit 1
fi
threshold=${args[i]}
;;
"-ms"|"-mS")
isfloat ${args[i+1]}
if [ $? == 0 ]
then
echo "Wrong minimun duration value -- ${args[i+1]}"
exit 1
fi
case ${args[i]:2:3} in
's')
si_duration=${args[i+1]}
;;
'S')
so_duration=${args[i+1]}
;;
*)
echo "Wrong argument -- ${args[i]}" >&2
;;
esac
((++i))
;;
"-sc"|"-st")
case ${args[i]:2:3} in
'c')
sort_key="-k 1,1 -k 2,2"
;;
't')
sort_key="-k 2,2"
;;
*)
echo "Wrong argument -- ${args[i]}" >&2
exit 1
;;
esac
;;
"-f")
regex="^[12345]{1}$"
if [[ ! ${args[++i]} =~ $regex ]]
then
echo "Wrong frequency resolution value -- ${args[i]}"
exit 1
fi
frq_res=${args[i]}
;;
*)
echo "Wrong argument -- ${args[i]}" >&2
exit -1
;;
esac
done
while true
do
read fname
tmp=$?
if [[ "$fname" = "" && ${tmp} != 0 ]]
then
break
fi
sox $fname -e signed-integer -b 16 /tmp/fsilence_$$.wav
echo "F $fname"
$executable_path "/tmp/fsilence_$$.wav" $threshold $si_duration $so_duration $frq_res | sort -n $sort_key
done
if [ -f "/tmp/fsilence_$$.wav" ]
then
rm "/tmp/fsilence_$$.wav"
fi