-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
334 lines (268 loc) · 12.4 KB
/
Makefile
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
SHELL := /bin/bash
# Use this file to override various settings
-include /vagrant/Makefile.options
# Set to 'yes' if you want to do speaker ID for trs files
DO_SPEAKER_ID?=no
SID_THRESHOLD?=13
# Some audio produces no results (can't be segmented), or transcribes better
# when segmented differently
# Changing SEGMENTS to one of these values gives more flexibilty;
# (see http://www-lium.univ-lemans.fr/diarization/doku.php/quick_start)
#
# show.seg : default - final segmentation with NCLR/CE clustering
# show.i.seg : initial segmentation (entire audio)
# show.pms.seg : sPeech/Music/Silence segmentation (don't use)
# show.s.seg : GLR based segmentation, make Small segments
# show.l.seg : linear clustering (merge only side by side segments)
# show.h.seg : hierarchical clustering
# show.d.seg : viterbi decoding
# show.adj.h.seg : boundaries adjusted
# show.flt1.seg : filter spk segmentation according to pms segmentation
# show.flt2.seg : filter spk segmentation according to pms segmentation
# show.spl.seg : segments longer than 20 sec are split
# show.spl10.seg : segments longer than 10 sec are split
# show.g.seg : the gender and the bandwith are detected
SEGMENTS ?= show.seg
# Where is Kaldi root directory?
KALDI_ROOT?=~/eesen
GRAPH_DIR?=$(EESEN_ROOT)/asr_egs/tedlium/v1/data/lang_phn_test
MODEL_DIR?=$(EESEN_ROOT)/asr_egs/tedlium/v1/exp/train_phn_l5_c320
# How many processes to use for one transcription task
# must be less than number of speakers, which for lium segmentation is often only 1
njobs ?= 1
# How many threads to use in each process
#nthreads ?= 1
# add Kaldi binaries to path
PATH := utils:$(KALDI_ROOT)/src/bin:$(KALDI_ROOT)/tools/openfst/bin:$(KALDI_ROOT)/src/fstbin/:$(KALDI_ROOT)/src/gmmbin/:$(KALDI_ROOT)/src/featbin/:$(KALDI_ROOT)/src/lm/:$(KALDI_ROOT)/src/sgmmbin/:$(KALDI_ROOT)/src/sgmm2bin/:$(KALDI_ROOT)/src/fgmmbin/:$(KALDI_ROOT)/src/latbin/:$(KALDI_ROOT)/src/nnetbin:$(KALDI_ROOT)/src/nnet2bin/:$(KALDI_ROOT)/src/kwsbin:$(KALDI_ROOT)/src/ivectorbin:$(PATH)
# add EESEN binaries to path
PATH := $(EESEN_ROOT)/src/decoderbin:$(EESEN_ROOT)/src/featbin:$(EESEN_ROOT)/src/nnetbin:$(PATH)
export train_cmd=run.pl
export decode_cmd=run.pl
export cuda_cmd=run.pl
export mkgraph_cmd=run.pl
# optimum experimentally determined LM weight for TEDLIUM data set
# (produces lowest WER)
LM_SCALE?=8
# Find out where this Makefile is located (this is not really needed)
where-am-i = $(lastword $(MAKEFILE_LIST))
THIS_DIR := $(shell dirname $(call where-am-i))
# This ends up just being a folder name for output
FINAL_PASS=eesen
#LD_LIBRARY_PATH=$(KALDI_ROOT)/tools/openfst/lib
.SECONDARY:
.DELETE_ON_ERROR:
export
# Call this (once) before using the system
.init: .kaldi #.lang .composed_lms
.kaldi:
rm -f steps utils
ln -fs $(KALDI_ROOT)/egs/wsj/s5/steps
ln -fs $(KALDI_ROOT)/egs/wsj/s5/utils
ln -fs $(KALDI_ROOT)/egs/sre08/v1/sid
mkdir -p src-audio
build/audio/base/%.wav: src-audio/%.sph
mkdir -p `dirname $@`
sox $^ build/audio/base/$*.wav rate -v $(sample_rate) #channels 1
build/audio/base/%.wav: src-audio/%.wav
mkdir -p `dirname $@`
sox $^ -c 1 -b 16 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.WAV
mkdir -p `dirname $@`
sox $^ -c 1 -b 16 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.mp3
mkdir -p `dirname $@`
sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.MP3
mkdir -p `dirname $@`
sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.ogg
mkdir -p `dirname $@`
sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.mp2
mkdir -p `dirname $@`
sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.m4a
mkdir -p `dirname $@`
avconv -i $^ -ac 1 -ar $(sample_rate) -y $@
# ffmpeg -i $^ -f sox - | sox -t sox - -c 1 -b 16 $@ rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.mp4
mkdir -p `dirname $@`
# sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
avconv -i $^ -ac 1 -ar $(sample_rate) -y $@
echo "converted audio"
date +%s%N | cut -b1-13
build/audio/base/%.wav: src-audio/%.MP4
mkdir -p `dirname $@`
# sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
avconv -i $^ -ac 1 -ar $(sample_rate) -y $@
echo "converted audio"
date +%s%N | cut -b1-13
build/audio/base/%.wav: src-audio/%.flac
mkdir -p `dirname $@`
sox $^ -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.amr
mkdir -p `dirname $@`
amrnb-decoder $^ [email protected]
sox -s -b 16 -c 1 -r 8000 [email protected] -c 1 build/audio/base/$*.wav rate -v $(sample_rate)
build/audio/base/%.wav: src-audio/%.mpg
mkdir -p `dirname $@`
avconv -i $^ -f sox - | sox -t sox - -c 1 -b 16 build/audio/base/$*.wav rate -v $(sample_rate)
# ffmpeg -i $^ -f sox - | sox -t sox - -c 1 -b 16 build/audio/base/$*.wav rate -v $(sample_rate)
# Speaker diarization
build/diarization/%/$(SEGMENTS): build/audio/base/%.wav
rm -rf `dirname $@`
mkdir -p `dirname $@`
echo "$* 1 0 1000000000 U U U 1" > `dirname $@`/show.uem.seg;
./scripts/diarization.sh $^ `dirname $@`/show.uem.seg $(SEGMENTS);
echo "diarization complete"
date +%s%N | cut -b1-13
#build/audio/segmented/%: build/diarization/%/show.seg
build/audio/segmented/%: build/diarization/%/$(SEGMENTS)
rm -rf $@
mkdir -p $@
cat $^ | cut -f 3,4,8 -d " " | \
while read LINE ; do \
start=`echo $$LINE | cut -f 1 -d " " | perl -npe '$$_=$$_/100.0'`; \
len=`echo $$LINE | cut -f 2 -d " " | perl -npe '$$_=$$_/100.0'`; \
sp_id=`echo $$LINE | cut -f 3 -d " "`; \
timeformatted=`echo "$$start $$len" | perl -ne '@t=split(); $$start=$$t[0]; $$len=$$t[1]; $$end=$$start+$$len; printf("%08.3f-%08.3f\n", $$start,$$end);'` ; \
if [ $${sp_id} == 'A' ]; then \
sox build/audio/base/$*.wav -c 1 $@/$*_$${timeformatted}_$${sp_id}.wav trim $$start $$len remix 1; \
elif [ $${sp_id} == 'B' ]; then \
sox build/audio/base/$*.wav -c 1 $@/$*_$${timeformatted}_$${sp_id}.wav trim $$start $$len remix 2; \
else \
sox build/audio/base/$*.wav --norm $@/$*_$${timeformatted}_$${sp_id}.wav trim $$start $$len; \
fi \
done
build/trans/%/wav.scp: build/audio/segmented/%
mkdir -p `dirname $@`
/bin/ls $</*.wav | \
perl -npe 'chomp; $$orig=$$_; s/.*\/(.*)_(\d+\.\d+-\d+\.\d+)_(.*)\.wav/\1-\3---\2/; $$_=$$_ . " $$orig\n";' | LC_ALL=C sort > $@
build/trans/%/utt2spk: build/trans/%/wav.scp
cat $^ | perl -npe 's/\s+.*//; s/((.*)---.*)/\1 \2/' > $@
build/trans/%/spk2utt: build/trans/%/utt2spk
utils/utt2spk_to_spk2utt.pl $^ > $@
# FBANK calculation
# example target:
# make build/trans/myvideo/fbank
# note the % pattern matches e.g. myvideo
build/trans/%/fbank: build/trans/%/spk2utt
rm -rf $@ build/trans/$*/cmvn.scp
steps/$(fbank).sh --fbank-config conf/fbank.$(sample_rate).conf --cmd "$$train_cmd" --nj 1 \
build/trans/$* build/trans/$*/exp/make_fbank $@ || exit 1
steps/compute_cmvn_stats.sh build/trans/$* build/trans/$*/exp/make_fbank $@ || exit 1
echo "feature generation done"
date +%s%N | cut -b1-13
# example target
# make build/trans/myvideo/eesen/decode/log
build/trans/%/eesen/decode/log: build/trans/%/spk2utt build/trans/%/fbank
rm -rf build/trans/$*/eesen && mkdir -p build/trans/$*/eesen
ifeq ($(MODELS),tedlium.eesen) ### Decode with Eesen
local/decode_ctc_lat_phon.sh --cmd "$$decode_cmd" --nj $(njobs) --beam $(BEAM) \
--lattice_beam 8.0 --max-active 5000 --skip_scoring true \
--acwt $(ACWT) $(GRAPH_DIR) build/trans/$* `dirname $@` $(MODEL_DIR) || exit 1;
else ifeq ($(MODELS,swbd.tf)) ### Decode with Eesen TF Model
local/decode_ctc_lat_tf.sh --mdl $(MODEL_DIR)/dbr-run6/model/epoch18.ckpt --scoredir build/trans/$* \
--cmd "$$decode_cmd" --nj $(njobs) --beam $(BEAM) \
--lattice_beam 8.0 --max-active 5000 --skip_scoring true \
--acwt $(ACWT) --temperature 1.25 \
$(GRAPH_DIR) build/trans/$* `dirname $@` $(MODEL_DIR) || exit 1;
endif
# scoring can happen here now, get_ctm_conf.sh only scores if -f build/trans/$*/stm
# produces confidence scores
# e.g. make build/trans/myvideo/eesen/decode/.ctm
# % = build/trans/myvideo/eesen
%/decode/.ctm: %/decode/log
# local/get_ctm.sh `dirname $*` $*/graph $*/decode
# local/get_ctm_conf.sh `dirname $*` $*/graph $*/decode
# local/lattice_to_ctm_aspire.sh `dirname $*` $(GRAPH_DIR) $*/decode
local/get_ctm_conf.sh `dirname $*` $(GRAPH_DIR) $*/decode
touch -m $@
# % = myvideo/eesen
# e.g. make build/trans/myvideo/eesen.segmented.splitw2.ctm
build/trans/%.segmented.splitw2.ctm: build/trans/%/decode/.ctm
# cat build/trans/$*/decode/score_$(LM_SCALE)/`dirname $*`.ctm | perl -npe 's/(.*)-(S\d+)---(\S+)/\1_\3_\2/' > $@
cat build/trans/$*/decode/score_$(LM_SCALE)/`dirname $*`.ctm | perl -npe 's/(.*)-(\w+)---(\S+)/\1_\3_\2/' > $@
#build/trans/myvideo/eesen.segmented.splitw2.ctm -> build/trans/myvideo/eesen.segmented.with-compounds.ctm
%.with-compounds.ctm: %.splitw2.ctm
cat $*.splitw2.ctm > $@
#build/trans/myvideo/eesen.segmented.with-compounds.ctm -> build/trans/myvideo/eesen.segmented.ctm
%.segmented.ctm: %.segmented.with-compounds.ctm
cat $^ > $@
%.ctm: %.segmented.ctm
cat $^ | python scripts/unsegment-ctm.py | LC_ALL=C sort -k 1,1 -k 3,3n -k 4,4n > $@
%.with-compounds.ctm: %.segmented.with-compounds.ctm
cat $^ | python scripts/unsegment-ctm.py | LC_ALL=C sort -k 1,1 -k 3,3n -k 4,4n > $@
%.hyp: %.segmented.ctm
cat $^ | python scripts/segmented-ctm-to-hyp.py > $@
ifeq "yes" "$(DO_SPEAKER_ID)"
build/trans/%/$(FINAL_PASS).trs: build/trans/%/$(FINAL_PASS).hyp build/trans/%/sid-result.txt
cat build/trans/$*/$(FINAL_PASS).hyp | python scripts/hyp2trs.py --sid build/trans/$*/sid-result.txt > $@
else
build/trans/%/$(FINAL_PASS).trs: build/trans/%/$(FINAL_PASS).hyp
cat $^ | python scripts/hyp2trs.py > $@
endif
%.sbv: %.hyp
cat $^ | python scripts/hyp2sbv.py > $@
%.txt: %.hyp
cat $^ | perl -npe 'use locale; s/ \(\S+\)/\./; $$_= ucfirst();' > $@
%.srt: %.ctm
cat $^ | python scripts/ctm2srt.py > $@
%.labels: %.ctm
cat $^ | python scripts/ctm2labels.py > $@
build/output/%.trs: build/trans/%/$(FINAL_PASS).trs
mkdir -p `dirname $@`
cp $^ $@
echo "final output done"
date +%s%N | cut -b1-13
build/output/%.ctm: build/trans/%/$(FINAL_PASS).ctm
mkdir -p `dirname $@`
cp $^ $@
build/output/%.txt: build/trans/%/$(FINAL_PASS).txt
mkdir -p `dirname $@`
cp $^ $@
build/output/%.with-compounds.ctm: build/trans/%/$(FINAL_PASS).with-compounds.ctm
mkdir -p `dirname $@`
cp $^ $@
build/output/%.sbv: build/trans/%/$(FINAL_PASS).sbv
mkdir -p `dirname $@`
cp $^ $@
build/output/%.srt: build/trans/%/$(FINAL_PASS).ctm
mkdir -p `dirname $@`
cp $^ $@
build/output/%.ali: build/trans/%/$(FINAL_PASS).txt
mkdir -p `dirname $@`
./run_align.sh --GRAPH_DIR $(GRAPH_DIR) --MODEL_DIR $(MODEL_DIR) $*
### Speaker ID stuff
# i-vectors for each speaker in our audio file
build/trans/%/ivectors: build/trans/%/mfcc
sid/extract_ivectors.sh --cmd "$$decode_cmd" --nj $(njobs) \
$(THIS_DIR)/kaldi-data/extractor_2048_top500 build/trans/$* $@
# a cross product of train and test speakers
build/trans/%/sid-trials.txt: build/trans/%/ivectors
cut -f 1 -d " " $(THIS_DIR)/kaldi-data/ivectors_train_top500/spk_ivector.scp | \
while read a; do \
cut -f 1 -d " " build/trans/$*/ivectors/spk_ivector.scp | \
while read b; do \
echo "$$a $$b"; \
done ; \
done > $@
# similarity scores
build/trans/%/sid-scores.txt: build/trans/%/sid-trials.txt
ivector-plda-scoring \
"ivector-copy-plda --smoothing=0.0 $(THIS_DIR)/kaldi-data/ivectors_train_top500/plda - |" \
"ark:ivector-subtract-global-mean scp:$(THIS_DIR)/kaldi-data/ivectors_train_top500/spk_ivector.scp ark:- |" \
"ark:ivector-subtract-global-mean scp:build/trans/$*/ivectors/spk_ivector.scp ark:- |" \
build/trans/$*/sid-trials.txt $@
# pick speakers above the threshold
build/trans/%/sid-result.txt: build/trans/%/sid-scores.txt
cat build/trans/$*/sid-scores.txt | sort -u -k 2,2 -k 3,3nr | sort -u -k2,2 | \
awk 'int($$3)>=$(SID_THRESHOLD)' | perl -npe 's/(\S+) \S+-(S\d+) \S+/\2 \1/; s/-/ /g' > $@
# Meta-target that deletes all files created during processing a file. Call e.g. 'make .etteytlus2013.clean
.%.clean:
rm -rf build/audio/base/$*.wav build/audio/segmented/$* build/diarization/$* build/trans/$*
# rm -rf build/audio/base/$*.wav build/audio/segmented/$* build/diarization/$* build/trans/$* #src-audio/$*.wav
# Also deletes the output files
.%.cleanest: .%.clean
rm -rf build/output/$*.{trs,txt,ctm,with-compounds.ctm,sbv,ali,labels}