Skip to content

Commit 7e6ed60

Browse files
committed
speed up uncompress function 5x, add wav/numpy writer and script usage
1 parent 31ba6d1 commit 7e6ed60

23 files changed

+304
-149
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
*.py text eol=lf
44
*.sh text eol=lf
5+

scripts/compute_directional_feats.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ transpose=false
1515

1616
echo "$0 $@"
1717

18+
function usage {
19+
echo "Options:"
20+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
21+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
22+
echo " --compress <true|false> # compress feature or not, (default=true)"
23+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
24+
echo " --numpy <numpy> # load masks from np.ndarray instead, (default=false)"
25+
echo " --transpose <transpose> # transpose TF-mask or not, (default=false)"
26+
}
27+
1828
. ./path.sh
1929
. ./utils/parse_options.sh || exit 1
2030

21-
[ $# -ne 4 ] && echo "Script format error: $0 <data-dir> <mask-scp> <log-dir> <feats-dir>" && exit 1
31+
[ $# -ne 4 ] && echo "Script format error: $0 <data-dir> <mask-scp> <log-dir> <feats-dir>" && usage && exit 1
2232

2333
src_dir=$(cd $1; pwd)
2434
dst_dir=$4

scripts/compute_librosa_fbank.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ compress=true
2424

2525
echo "$0 $@"
2626

27+
function usage {
28+
echo "Options:"
29+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
30+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
31+
echo " --compress <true|false> # compress feature or not, (default=true)"
32+
echo " --apply-log <true|false> # use log or linear fbank, (default=true)"
33+
echo " --apply-pow <true|false> # use power or magnitude spectrogram, (default=false)"
34+
echo " --fbank-conf <fbank-conf> # stft configurations files, (default=conf/fbank_librosa.conf)"
35+
echo " --sample-normalize <true|false> # normalize wav samples into [0, 1] or not, (default=true)"
36+
}
37+
2738
. ./path.sh
2839

2940
. ./utils/parse_options.sh || exit 1
3041

31-
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <fbank-dir>" && exit 1
42+
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <fbank-dir>" && usage && exit 1
3243

3344
src_dir=$(cd $1; pwd)
3445
dst_dir=$3

scripts/compute_librosa_spectrogram.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ compress=true
2121

2222
echo "$0 $@"
2323

24+
function usage {
25+
echo "Options:"
26+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
27+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
28+
echo " --compress <true|false> # compress feature or not, (default=true)"
29+
echo " --apply-log <true|false> # use log or linear spectrogram, (default=true)"
30+
echo " --apply-pow <true|false> # use power or magnitude spectrogram, (default=false)"
31+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
32+
echo " --sample-normalize <true|false> # normalize wav samples into [0, 1] or not, (default=true)"
33+
}
34+
2435
. ./path.sh
2536

2637
. ./utils/parse_options.sh || exit 1
2738

28-
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <spectrogram-dir>" && exit 1
39+
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <spectrogram-dir>" && usage && exit 1
2940

3041
src_dir=$(cd $1; pwd)
3142
dst_dir=$3
@@ -46,9 +57,11 @@ for n in $(seq $nj); do wav_split_scp="$wav_split_scp $exp_dir/wav.$n.scp"; done
4657

4758
./utils/split_scp.pl $src_dir/wav.scp $wav_split_scp || exit 1
4859

60+
$apply_log && $apply_pow && echo "$0: Using log-amplitude feature instead" && exit 1
61+
4962
name="linear_amp_spectrogram"
50-
$apply_log && name="log_amp_spectrogram"
51-
$apply_pow && name="log_pow_spectrogram"
63+
$apply_log && ! $apply_pow && name="log_amp_spectrogram"
64+
! $apply_log && $apply_pow && name="linear_pow_spectrogram"
5265

5366
dir=$(basename $src_dir)
5467

scripts/compute_oracle_mask.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -eu
44

55
mask="irm"
6-
# for iam(FFT-mask)
6+
# for iam(FFT-mask)/psm etc
77
cutoff=10
88
stft_conf=conf/stft.conf
99

@@ -13,17 +13,27 @@ nj=40
1313

1414
echo "$0 $@"
1515

16+
function usage {
17+
echo "Options:"
18+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
19+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
20+
echo " --compress <true|false> # compress feature or not, (default=true)"
21+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
22+
echo " --cutoff <cutoff> # values to cutoff when compute iam/psm, (default=10)"
23+
echo " --mask <ibm|iam|psm|irm|psa> # type of TF-masks to compute, (default=irm)"
24+
}
25+
1626
. ./path.sh
1727
. ./utils/parse_options.sh || exit 1
1828

19-
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <mask-dir>" && exit 1
29+
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <mask-dir>" && usage && exit 1
2030

2131
data_dir=$(cd $1; pwd)
2232
mask_dir=$3
2333

2434
denominator_scp=noise.scp
2535
case $mask in
26-
"iam"|"psm" )
36+
"iam"|"psm"|"psa" )
2737
denominator_scp=wav.scp
2838
;;
2939
"ibm"|"irm" )

scripts/compute_spatial_feats.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,26 @@ src_sample_tdoa=false
2323

2424
echo "$0 $@"
2525

26+
function usage {
27+
echo "Options:"
28+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
29+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
30+
echo " --compress <true|false> # compress feature or not, (default=true)"
31+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
32+
echo " --feats <srp|ipd|msc> # type of spatial features, (default=ipd)"
33+
echo " --ipd-index <ipd-index> # channel index to compute ipd, (default=0,1)"
34+
echo " --ipd-sin <true|false> # paste sin(ipd) feature or not, (default=false)"
35+
echo " --msc-ctx <msc-ctx> # length of context for MSC computation, (default=1)"
36+
echo " --srp-fs <srp-fs> # sample frequency for source wave, (default=16000)"
37+
echo " --srp-topo <srp-topo> # microphone topo description, (default="")"
38+
echo " --srp-num-doa <num-doa> # doa resolution, (default=181)"
39+
echo " --srp-sample-tdoa <true|false> # sample tdoa instead of doa, (default=false)"
40+
}
41+
2642
. ./path.sh
2743
. ./utils/parse_options.sh || exit 1
2844

29-
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <feats-dir>" && exit 1
45+
[ $# -ne 3 ] && echo "Script format error: $0 <data-dir> <log-dir> <feats-dir>" && usage && exit 1
3046

3147
src_dir=$(cd $1; pwd)
3248
dst_dir=$3

scripts/run_adapt_beamformer.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ masking=false
1616

1717
echo "$0 $@"
1818

19+
function usage {
20+
echo "Options:"
21+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
22+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
23+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
24+
echo " --numpy <numpy> # load masks from np.ndarray instead, (default=false)"
25+
echo " --transpose <transpose> # transpose TF-mask or not, (default=false)"
26+
echo " --beamformer <mvdr|pmwf|gevd> # type of adaptive beamformer to apply, (default=mvdr)"
27+
echo " --normalize <true|false> # do ban or not, (default=false)"
28+
echo " --masking <true|false> # do TF-masking after beamforming or not, (default=false)"
29+
}
30+
1931
. ./path.sh
2032
. ./utils/parse_options.sh || exit 1
2133

22-
[ $# -ne 3 ] && echo "Script format error: $0 <wav-scp> <mask-dir/mask-scp> <enhan-dir>" && exit 1
34+
[ $# -ne 3 ] && echo "Script format error: $0 <wav-scp> <mask-dir/mask-scp> <enhan-dir>" && usage && exit 1
2335

2436
wav_scp=$1
2537
enhan_dir=$3

scripts/run_auxiva.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ set -eu
88
cmd="run.pl"
99
nj=40
1010
epochs=20
11-
window="hann"
12-
frame_length=1024
13-
frame_shift=256
11+
fs=16000
12+
stft_conf=conf/stft.conf
1413

1514
echo "$0 $@"
1615

16+
function usage {
17+
echo "Options:"
18+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
19+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
20+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
21+
echo " --epochs <epochs> # number of epochs to run AuxIVA, (default=20)"
22+
echo " --fs <fs> # sample frequency for output wave, (default=16000)"
23+
}
24+
1725
. ./path.sh || exit 1
1826
. ./utils/parse_options.sh || exit 1
1927

20-
[ $# -ne 2 ] && echo "Script format error: $0 <wav-scp> <dst-dir>" && exit 1
28+
[ $# -ne 2 ] && echo "Script format error: $0 <wav-scp> <dst-dir>" && usage && exit 1
2129

2230
wav_scp=$1
2331
dst_dir=$2
@@ -32,14 +40,14 @@ for n in $(seq $nj); do split_wav_scp="$split_wav_scp $exp_dir/wav.$n.scp"; done
3240

3341
./utils/split_scp.pl $wav_scp $split_wav_scp || exit 1
3442

43+
stft_opts=$(cat $stft_conf | xargs)
44+
3545
mkdir -p $dst_dir
3646
$cmd JOB=1:$nj $exp_dir/log/run_auxiva.JOB.log \
3747
./scripts/sptk/apply_auxiva.py \
48+
--sample-frequency $fs \
3849
--num-epochs $epochs \
39-
--window $window \
40-
--center true \
41-
--frame-length $frame_length \
42-
--frame-shift $frame_shift \
50+
$stft_opts \
4351
$exp_dir/wav.JOB.scp \
4452
$dst_dir
4553

scripts/run_cgmm.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
set -eu
66

77
nj=40
8+
cmd="run.pl"
89
epochs=20
910
# stft.conf example:
1011
# --frame-length 1024
@@ -16,9 +17,19 @@ init_mask=
1617

1718
echo "$0 $@"
1819

20+
function usage {
21+
echo "Options:"
22+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
23+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
24+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
25+
echo " --epochs <epochs> # number of epochs to run CGMM, (default=20)"
26+
echo " --init-mask <init-mask> # dir or script for mask initialization, (default="")"
27+
}
28+
29+
. ./path.sh
1930
. ./utils/parse_options.sh || exit 1
2031

21-
[ $# -ne 2 ] && echo "Script format error: $0 <wav-scp> <dst-dir>" && exit 1
32+
[ $# -ne 2 ] && echo "Script format error: $0 <wav-scp> <dst-dir>" && usage && exit 1
2233

2334
wav_scp=$1
2435
dst_dir=$2
@@ -37,7 +48,7 @@ cgmm_opts="--num-epochs $epochs"
3748
[ ! -z $init_mask ] && cgmm_opts="$cgmm_opts --init-speech-mask $init_mask"
3849

3950
mkdir -p $dst_dir
40-
./utils/run.pl JOB=1:$nj $exp_dir/log/run_cgmm.JOB.log \
51+
$cmd JOB=1:$nj $exp_dir/log/run_cgmm.JOB.log \
4152
./scripts/sptk/estimate_cgmm_masks.py \
4253
$stft_opts $cgmm_opts \
4354
$exp_dir/wav.JOB.scp \

scripts/run_fixed_beamformer.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ weight_key="weights"
1111

1212
echo "$0 $@"
1313

14+
function usage {
15+
echo "Options:"
16+
echo " --nj <nj> # number of jobs to run parallel, (default=40)"
17+
echo " --cmd <run.pl|queue.pl> # how to run jobs, (default=run.pl)"
18+
echo " --stft-conf <stft-conf> # stft configurations files, (default=conf/stft.conf)"
19+
echo " --weight-key <weight-key> # index keys to index matlab mat files, (default=weights)"
20+
}
21+
1422
. ./path.sh
1523
. ./utils/parse_options.sh || exit 1
1624

17-
[ $# -ne 3 ] && echo "Script format error: $0 <wav-scp> <weight-mat> <enhan-dir>" && exit 1
25+
[ $# -ne 3 ] && echo "Script format error: $0 <wav-scp> <weight-mat> <enhan-dir>" && usage && exit 1
1826

1927
wav_scp=$1
2028
weight=$2

0 commit comments

Comments
 (0)