|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2022-2023 Xu Xiang |
| 3 | +# 2022 Zhengyang Chen ([email protected]) |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +. ./path.sh || exit 1 |
| 18 | + |
| 19 | +stage=-1 |
| 20 | +stop_stage=-1 |
| 21 | +sad_type="oracle" |
| 22 | +partition="dev" |
| 23 | + |
| 24 | +# do cmn on the sub-segment or on the vad segment |
| 25 | +subseg_cmn=true |
| 26 | +# whether print the evaluation result for each file |
| 27 | +get_each_file_res=1 |
| 28 | + |
| 29 | +. tools/parse_options.sh |
| 30 | + |
| 31 | +# Prerequisite |
| 32 | +if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then |
| 33 | + mkdir -p external_tools |
| 34 | + |
| 35 | + # [1] Download evaluation toolkit |
| 36 | + wget -c https://github.com/usnistgov/SCTK/archive/refs/tags/v2.4.12.zip -O external_tools/SCTK-v2.4.12.zip |
| 37 | + unzip -o external_tools/SCTK-v2.4.12.zip -d external_tools |
| 38 | + |
| 39 | + # [3] Download ResNet34 speaker model pretrained by WeSpeaker Team |
| 40 | + mkdir -p pretrained_models |
| 41 | + |
| 42 | + wget -c https://wespeaker-1256283475.cos.ap-shanghai.myqcloud.com/models/voxceleb/voxceleb_resnet34_LM.onnx -O pretrained_models/voxceleb_resnet34_LM.onnx |
| 43 | +fi |
| 44 | + |
| 45 | + |
| 46 | +# Download VoxConverse dev/test audios and the corresponding annotations |
| 47 | +if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then |
| 48 | + mkdir -p data |
| 49 | + |
| 50 | + # Download annotations for dev and test sets (version 0.0.3) |
| 51 | + wget -c https://github.com/joonson/voxconverse/archive/refs/heads/master.zip -O data/voxconverse_master.zip |
| 52 | + unzip -o data/voxconverse_master.zip -d data |
| 53 | + |
| 54 | + # Download annotations from VoxSRC-23 validation toolkit (looks like version 0.0.2) |
| 55 | + # cd data && git clone https://github.com/JaesungHuh/VoxSRC2023.git --recursive && cd - |
| 56 | + |
| 57 | + # Download dev audios |
| 58 | + mkdir -p data/dev |
| 59 | + |
| 60 | + #wget --no-check-certificate -c https://mm.kaist.ac.kr/datasets/voxconverse/data/voxconverse_dev_wav.zip -O data/voxconverse_dev_wav.zip |
| 61 | + # The above url may not be reachable, you can try the link below. |
| 62 | + # This url is from https://github.com/joonson/voxconverse/blob/master/README.md |
| 63 | + wget --no-check-certificate -c https://www.robots.ox.ac.uk/~vgg/data/voxconverse/data/voxconverse_dev_wav.zip -O data/voxconverse_dev_wav.zip |
| 64 | + unzip -o data/voxconverse_dev_wav.zip -d data/dev |
| 65 | + |
| 66 | + # Create wav.scp for dev audios |
| 67 | + ls `pwd`/data/dev/audio/*.wav | awk -F/ '{print substr($NF, 1, length($NF)-4), $0}' > data/dev/wav.scp |
| 68 | + |
| 69 | + # Test audios |
| 70 | + mkdir -p data/test |
| 71 | + |
| 72 | + #wget --no-check-certificate -c https://mm.kaist.ac.kr/datasets/voxconverse/data/voxconverse_test_wav.zip -O data/voxconverse_test_wav.zip |
| 73 | + # The above url may not be reachable, you can try the link below. |
| 74 | + # This url is from https://github.com/joonson/voxconverse/blob/master/README.md |
| 75 | + wget --no-check-certificate -c https://www.robots.ox.ac.uk/~vgg/data/voxconverse/data/voxconverse_test_wav.zip -O data/voxconverse_test_wav.zip |
| 76 | + unzip -o data/voxconverse_test_wav.zip -d data/test |
| 77 | + |
| 78 | + # Create wav.scp for test audios |
| 79 | + ls `pwd`/data/test/voxconverse_test_wav/*.wav | awk -F/ '{print substr($NF, 1, length($NF)-4), $0}' > data/test/wav.scp |
| 80 | +fi |
| 81 | + |
| 82 | + |
| 83 | +# Voice activity detection |
| 84 | +if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then |
| 85 | + # Set VAD min duration |
| 86 | + min_duration=0.255 |
| 87 | + |
| 88 | + if [[ "x${sad_type}" == "xoracle" ]]; then |
| 89 | + # Oracle SAD: handling overlapping or too short regions in ground truth RTTM |
| 90 | + while read -r utt wav_path; do |
| 91 | + python3 wespeaker/diar/make_oracle_sad.py \ |
| 92 | + --rttm data/voxconverse-master/${partition}/${utt}.rttm \ |
| 93 | + --min-duration $min_duration |
| 94 | + done < data/${partition}/wav.scp > data/${partition}/oracle_sad |
| 95 | + fi |
| 96 | + |
| 97 | + if [[ "x${sad_type}" == "xsystem" ]]; then |
| 98 | + # System SAD: applying 'silero' VAD |
| 99 | + python3 wespeaker/diar/make_system_sad.py \ |
| 100 | + --scp data/${partition}/wav.scp \ |
| 101 | + --min-duration $min_duration > data/${partition}/system_sad |
| 102 | + fi |
| 103 | +fi |
| 104 | + |
| 105 | + |
| 106 | +# Extract fbank features |
| 107 | +if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ]; then |
| 108 | + |
| 109 | + [ -d "exp/${sad_type}_sad_fbank" ] && rm -r exp/${sad_type}_sad_fbank |
| 110 | + |
| 111 | + echo "Make Fbank features and store it under exp/${sad_type}_sad_fbank" |
| 112 | + echo "..." |
| 113 | + bash local/make_fbank.sh \ |
| 114 | + --scp data/${partition}/wav.scp \ |
| 115 | + --segments data/${partition}/${sad_type}_sad \ |
| 116 | + --store_dir exp/${partition}_${sad_type}_sad_fbank \ |
| 117 | + --subseg_cmn ${subseg_cmn} \ |
| 118 | + --nj 24 |
| 119 | +fi |
| 120 | + |
| 121 | +# Extract embeddings |
| 122 | +if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then |
| 123 | + |
| 124 | + [ -d "exp/${sad_type}_sad_embedding" ] && rm -r exp/${sad_type}_sad_embedding |
| 125 | + |
| 126 | + echo "Extract embeddings and store it under exp/${sad_type}_sad_embedding" |
| 127 | + echo "..." |
| 128 | + bash local/extract_emb.sh \ |
| 129 | + --scp exp/${partition}_${sad_type}_sad_fbank/fbank.scp \ |
| 130 | + --pretrained_model pretrained_models/voxceleb_resnet34_LM.onnx \ |
| 131 | + --device cuda \ |
| 132 | + --store_dir exp/${partition}_${sad_type}_sad_embedding \ |
| 133 | + --batch_size 96 \ |
| 134 | + --frame_shift 10 \ |
| 135 | + --window_secs 1.5 \ |
| 136 | + --period_secs 0.75 \ |
| 137 | + --subseg_cmn ${subseg_cmn} \ |
| 138 | + --nj 1 |
| 139 | +fi |
| 140 | + |
| 141 | + |
| 142 | +# Applying umap clustering algorithm |
| 143 | +if [ ${stage} -le 6 ] && [ ${stop_stage} -ge 6 ]; then |
| 144 | + |
| 145 | + [ -f "exp/umap_cluster/${partition}_${sad_type}_sad_labels" ] && rm exp/umap_cluster/${partition}_${sad_type}_sad_labels |
| 146 | + |
| 147 | + echo "Doing umap clustering and store the result in exp/umap_cluster/${partition}_${sad_type}_sad_labels" |
| 148 | + echo "..." |
| 149 | + python3 wespeaker/diar/umap_clusterer.py \ |
| 150 | + --scp exp/${partition}_${sad_type}_sad_embedding/emb.scp \ |
| 151 | + --output exp/umap_cluster/${partition}_${sad_type}_sad_labels |
| 152 | +fi |
| 153 | + |
| 154 | + |
| 155 | +# Convert labels to RTTMs |
| 156 | +if [ ${stage} -le 7 ] && [ ${stop_stage} -ge 7 ]; then |
| 157 | + python3 wespeaker/diar/make_rttm.py \ |
| 158 | + --labels exp/umap_cluster/${partition}_${sad_type}_sad_labels \ |
| 159 | + --channel 1 > exp/umap_cluster/${partition}_${sad_type}_sad_rttm |
| 160 | +fi |
| 161 | + |
| 162 | + |
| 163 | +# Evaluate the result |
| 164 | +if [ ${stage} -le 8 ] && [ ${stop_stage} -ge 8 ]; then |
| 165 | + ref_dir=data/voxconverse-master/ |
| 166 | + #ref_dir=data/VoxSRC2023/voxconverse/ |
| 167 | + echo -e "Get the DER results\n..." |
| 168 | + perl external_tools/SCTK-2.4.12/src/md-eval/md-eval.pl \ |
| 169 | + -c 0.25 \ |
| 170 | + -r <(cat ${ref_dir}/${partition}/*.rttm) \ |
| 171 | + -s exp/umap_cluster/${partition}_${sad_type}_sad_rttm 2>&1 | tee exp/umap_cluster/${partition}_${sad_type}_sad_res |
| 172 | + |
| 173 | + if [ ${get_each_file_res} -eq 1 ];then |
| 174 | + single_file_res_dir=exp/umap_cluster/${partition}_${sad_type}_single_file_res |
| 175 | + mkdir -p $single_file_res_dir |
| 176 | + echo -e "\nGet the DER results for each file and the results will be stored underd ${single_file_res_dir}\n..." |
| 177 | + |
| 178 | + awk '{print $2}' exp/umap_cluster/${partition}_${sad_type}_sad_rttm | sort -u | while read file_name; do |
| 179 | + perl external_tools/SCTK-2.4.12/src/md-eval/md-eval.pl \ |
| 180 | + -c 0.25 \ |
| 181 | + -r <(cat ${ref_dir}/${partition}/${file_name}.rttm) \ |
| 182 | + -s <(grep "${file_name}" exp/umap_cluster/${partition}_${sad_type}_sad_rttm) > ${single_file_res_dir}/${partition}_${file_name}_res |
| 183 | + done |
| 184 | + echo "Done!" |
| 185 | + fi |
| 186 | +fi |
0 commit comments