-
Notifications
You must be signed in to change notification settings - Fork 4
/
sample_file.zsh
executable file
·127 lines (102 loc) · 2.75 KB
/
sample_file.zsh
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
#!/bin/zsh
zmodload zsh/mathfunc
#set -x
if [ $# -lt 1 ]
then
echo "usage: ./sample_file.sh file"
exit 1
fi
file=$1
e_step=10
if [ ! -z $2 ]
then
e_step=$2
fi
function random_string() {
echo `cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 6`
}
function die() {
rm -rf $f 1>/dev/null 2>&1
echo $1
exit 1
}
function split_file() {
prefix=$1
s_file=$2
split_start_sec=0
split_step=0.025
for i in {0..7}
do
s_fn=`random_string`.wav
f1=data/audio/${prefix}_${s_fn}
f2=data_48k/audio/${prefix}_${s_fn}
sox $s_file -r 8k -b 8 ${f1} trim $split_start_sec $split_step
sox $s_file -r 48k -b 16 ${f2} trim $split_start_sec $split_step
split_start_sec=$((split_start_sec + split_step))
split_start_sec=`printf "%0.3f" split_start_sec`
done
mv $s_file data_200ms/audio/${prefix}_${s_file}
}
if [ ! -f $file ]
then
echo "$file not found"
exit 1
fi
f=`random_string`.wav
echo "processing..."
sox $file $f remix - 1>/dev/null 2>&1
start_sec=60
step=360
duration=$((int(`soxi -D $f`)))
while [ $((start_sec + step)) -lt $duration ]
do
fn=`random_string`
sox $f ${fn}.wav trim $start_sec $step 1>/dev/null 2>&1
if [ ! -f ${fn}.wav ]
then
die "sox trim failed"
fi
ts=`python energy.py ${fn}.wav -n 5 -s $e_step -w 0.20 | cut -d ' ' -f1`
for t in `echo $ts`
do
fn2=`random_string`
sox ${fn}.wav ${fn2}.wav trim $t 0.20 1>/dev/null 2>&1
if [ ! -f ${fn2}.wav ]
then
die "sox trim failed"
fi
while true
do
echo "\nplaying ${fn2}.wav"
play -q ${fn2}.wav gain -l 12 1>/dev/null 2>&1
prediction=`python mlp_vad.py ${fn2}.wav 2>/dev/null`
echo -n "is this $prediction? (S/n/r/d)? "
old_stty_cfg=$(stty -g)
stty raw -echo ; yn=$(head -c 1) ; stty $old_stty_cfg
case ${yn:0:1} in
""|S|s )
split_file 's' ${fn2}.wav
echo "marked ${fn2} as speech"
break
;;
N|n )
split_file 'n' ${fn2}.wav
echo "marked ${fn2} as noise"
break
;;
D|d )
rm ${fn2}.wav
echo "discarded ${fn2}"
break
;;
esac
done
done
rm ${fn}.wav 1>/dev/null 2>&1
start_sec=$((start_sec + step))
done
num_speech=`find data/audio/ -name s_\*.wav | wc -l | tr -d ' '`
echo "total speech samples: $num_speech"
num_noise=`find data/audio/ -name n_\*.wav | wc -l | tr -d ' '`
echo "total noise samples: $num_noise"
rm $f