chore: import upstream snapshot with attribution
Create PR to main with cherry-pick from release / cherry-pick (push) Failing after 0s
CICD NeMo / pre-flight (push) Failing after 0s
CICD NeMo / configure (push) Has been skipped
Build, validate, and release Neural Modules / pre-flight (push) Failing after 1s
CICD NeMo / code-linting (push) Has been skipped
Build, validate, and release Neural Modules / release (push) Has been skipped
Build, validate, and release Neural Modules / release-summary (push) Has been cancelled
CICD NeMo / cicd-test-container-build (push) Has been cancelled
CICD NeMo / cicd-import-tests (push) Has been cancelled
CICD NeMo / L0_Setup_Test_Data_And_Models (push) Has been cancelled
CICD NeMo / cicd-main-unit-tests (push) Has been cancelled
CICD NeMo / cicd-main-speech (push) Has been cancelled
CICD NeMo / Nemo_CICD_Test (push) Has been cancelled
CICD NeMo / Coverage (e2e) (push) Has been cancelled
CICD NeMo / Coverage (unit-test) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
CICD NeMo / cicd-wait-in-queue (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:28:58 +08:00
commit ba4be087d5
2316 changed files with 2668701 additions and 0 deletions
@@ -0,0 +1,106 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from argparse import ArgumentParser
from nemo.collections.asr.parts.utils.vad_utils import generate_overlap_vad_seq, generate_vad_segment_table
from nemo.utils import logging
"""
Note you can use NeMo/examples/asr/speech_classification/vad_infer.py which includes the functionalities appeared in this function directly.
You are encouraged to use this script if you want to try overlapped mean/median smoothing filter and postprocessing technique without perform costly NN inference several times.
You can also use this script to write RTTM-like files if you have frame level prediction already.
This script serves two purposes:
1) gen_overlap_seq:
Generate predictions with overlapping input segments by using the frame level prediction from NeMo/examples/asr/speech_classification/vad_infer.py.
Then a smoothing filter is applied to decide the label for a frame spanned by multiple segments.
2gen_seg_table:
Converting frame level prediction to speech/no-speech segment in start and end times format with postprocessing technique.
Usage:
python vad_overlap_posterior.py --gen_overlap_seq --gen_seg_table --frame_folder=<FULL PATH OF YOU STORED FRAME LEVEL PREDICTION> --method='median' --overlap=0.875 --num_workers=20
You can play with different postprocesing parameters. Here we just show the simpliest condition onset=offset=threshold=0.5
See more details about postprocesing in function binarization and filtering in NeMo/nemo/collections/asr/parts/utils/vad_utils
"""
postprocessing_params = {"onset": 0.5, "offset": 0.5}
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("--gen_overlap_seq", default=False, action='store_true')
parser.add_argument("--gen_seg_table", default=False, action='store_true')
parser.add_argument("--frame_folder", type=str, required=True)
parser.add_argument(
"--method",
type=str,
required=True,
help="Use mean/median for overlapped prediction. Use frame for gen_seg_table of frame prediction",
)
parser.add_argument("--overlap_out_dir", type=str)
parser.add_argument("--table_out_dir", type=str)
parser.add_argument("--overlap", type=float, default=0.875, help="Overlap percentatge. Default is 0.875")
parser.add_argument("--window_length_in_sec", type=float, default=0.63)
parser.add_argument("--shift_length_in_sec", type=float, default=0.01)
parser.add_argument("--num_workers", type=int, default=4)
args = parser.parse_args()
if args.gen_overlap_seq:
start = time.time()
logging.info("Generating predictions with overlapping input segments")
overlap_out_dir = generate_overlap_vad_seq(
frame_pred_dir=args.frame_folder,
smoothing_method=args.method,
overlap=args.overlap,
window_length_in_sec=args.window_length_in_sec,
shift_length_in_sec=args.shift_length_in_sec,
num_workers=args.num_workers,
out_dir=args.overlap_out_dir,
)
logging.info(
f"Finish generating predictions with overlapping input segments with smoothing_method={args.method} and overlap={args.overlap}"
)
end = time.time()
logging.info(f"Generate overlapped prediction takes {end-start:.2f} seconds!\n Save to {overlap_out_dir}")
if args.gen_seg_table:
start = time.time()
logging.info("Converting frame level prediction to speech/no-speech segment in start and end times format.")
frame_length_in_sec = args.shift_length_in_sec
if args.gen_overlap_seq:
logging.info("Use overlap prediction. Change if you want to use basic frame level prediction")
vad_pred_dir = overlap_out_dir
frame_length_in_sec = 0.01
else:
logging.info("Use basic frame level prediction")
vad_pred_dir = args.frame_folder
table_out_dir = generate_vad_segment_table(
vad_pred_dir=vad_pred_dir,
postprocessing_params=postprocessing_params,
frame_length_in_sec=frame_length_in_sec,
num_workers=args.num_workers,
out_dir=args.table_out_dir,
)
logging.info(f"Finish generating speech semgents table with postprocessing_params: {postprocessing_params}")
end = time.time()
logging.info(
f"Generating rttm-like tables for {vad_pred_dir} takes {end-start:.2f} seconds!\n Save to {table_out_dir}"
)
@@ -0,0 +1,146 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import numpy as np
from nemo.collections.asr.parts.utils.vad_utils import vad_tune_threshold_on_dev
from nemo.utils import logging
"""
This script is designed for thresholds tuning for postprocessing of VAD
See details about it in nemo/collections/asr/parts/utils/vad_utils/binarization and filtering
Usage:
python vad_tune_threshold.py \
--onset_range="0,1,0.2" --offset_range="0,1,0.2" --min_duration_on_range="0.1,0.8,0.05" --min_duration_off_range="0.1,0.8,0.05" --not_filter_speech_first \
--vad_pred=<FULL PATH OF FOLDER OF FRAME LEVEL PREDICTION FILES> \
--groundtruth_RTTM=<DIRECTORY OF VAD PREDICTIONS OR A FILE CONTAINS THE PATHS OF THEM> \
--vad_pred_method="median"
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--onset_range", help="range of onset in list 'START,END,STEP' to be tuned on", type=str)
parser.add_argument("--offset_range", help="range of offset in list 'START,END,STEP' to be tuned on", type=str)
parser.add_argument(
"--pad_onset_range",
help="range of pad_onset in list 'START,END,STEP' to be tuned on. pad_onset could be negative float",
type=str,
)
parser.add_argument(
"--pad_offset_range",
help="range of pad_offset in list 'START,END,STEP' to be tuned on. pad_offset could be negative float",
type=str,
)
parser.add_argument(
"--min_duration_on_range", help="range of min_duration_on in list 'START,END,STEP' to be tuned on", type=str
)
parser.add_argument(
"--min_duration_off_range", help="range of min_duration_off in list 'START,END,STEP' to be tuned on", type=str
)
parser.add_argument(
"--not_filter_speech_first",
help="Whether to filter short speech first during filtering, should be either True or False!",
action='store_true',
)
parser.add_argument(
"--vad_pred", help="Directory of vad predictions or a file contains the paths of them.", required=True
)
parser.add_argument(
"--groundtruth_RTTM",
help="Directory of groundtruch rttm files or a file contains the paths of them",
type=str,
required=True,
)
parser.add_argument(
"--result_file",
help="Filename of txt to store results",
default="res",
)
parser.add_argument(
"--vad_pred_method",
help="suffix of prediction file. Should be either in 'frame', 'mean' or 'median'",
required=True,
)
parser.add_argument(
"--focus_metric",
help="metrics we care most when tuning threshold. Should be either in 'DetER', 'FA', 'MISS' ",
type=str,
default='DetER',
)
parser.add_argument(
"--frame_length_in_sec",
help="frame_length_in_sec ",
type=float,
default=0.01,
)
args = parser.parse_args()
params = {}
try:
# if not input range for values of parameters, use default value defined in function binarization and filtering in nemo/collections/asr/parts/utils/vad_utils.py
if args.onset_range:
start, stop, step = [float(i) for i in args.onset_range.split(",")]
onset = np.arange(start, stop, step)
params['onset'] = onset
if args.offset_range:
start, stop, step = [float(i) for i in args.offset_range.split(",")]
offset = np.arange(start, stop, step)
params['offset'] = offset
if args.pad_onset_range:
start, stop, step = [float(i) for i in args.pad_onset_range.split(",")]
pad_onset = np.arange(start, stop, step)
params['pad_onset'] = pad_onset
if args.pad_offset_range:
start, stop, step = [float(i) for i in args.pad_offset_range.split(",")]
pad_offset = np.arange(start, stop, step)
params['pad_offset'] = pad_offset
if args.min_duration_on_range:
start, stop, step = [float(i) for i in args.min_duration_on_range.split(",")]
min_duration_on = np.arange(start, stop, step)
params['min_duration_on'] = min_duration_on
if args.min_duration_off_range:
start, stop, step = [float(i) for i in args.min_duration_off_range.split(",")]
min_duration_off = np.arange(start, stop, step)
params['min_duration_off'] = min_duration_off
if args.not_filter_speech_first:
params['filter_speech_first'] = False
except:
raise ValueError(
"Theshold input is invalid! Please enter it as a 'START,STOP,STEP' for onset, offset, min_duration_on and min_duration_off, and enter True/False for filter_speech_first"
)
best_threhsold, optimal_scores = vad_tune_threshold_on_dev(
params,
args.vad_pred,
args.groundtruth_RTTM,
args.result_file,
args.vad_pred_method,
args.focus_metric,
args.frame_length_in_sec,
)
logging.info(
f"Best combination of thresholds for binarization selected from input ranges is {best_threhsold}, and the optimal score is {optimal_scores}"
)
@@ -0,0 +1,90 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from argparse import ArgumentParser
import numpy as np
from nemo.collections.asr.parts.utils.vad_utils import prepare_manifest
from nemo.utils import logging
"""
This script is designed for inference of frame level Voice Activity Detection (VAD)
This script serves three goals:
(1) Write audio files to manifest
(2) Split audio file for avoiding CUDA memory issue
(3) Take care of joint of seperate json line for an audio file
Usage:
python write_long_audio_manifest.py --inp_dir=<FULL PATH OF FOLDER OF AUDIO FILES> --split_duration=300 --window_length_in_sec=0.63 --num_worker=10
"""
def main():
parser = ArgumentParser()
parser.add_argument("--inp_dir", type=str, required=True, help="(full path) folder of files to be processed")
parser.add_argument(
"--inp_list", type=str, help="(full path) a file contains NAME of files inside inp_dir to be processed"
)
parser.add_argument("--out_dir", type=str, default=".", help="(full path) location to store generated json file")
parser.add_argument("--manifest_name", type=str, default="generated_manifest", help="name of generated json file")
parser.add_argument("--split_duration", type=int, required=True, help="max duration of each audio clip/line")
parser.add_argument(
"--window_length_in_sec",
type=float,
default=0.63,
help="window length in sec for VAD context input , default is 0.63s",
)
parser.add_argument("--num_workers", type=int, default=4, help="number of workers for multiprocessing")
args = parser.parse_args()
if not args.inp_list:
input_audios = []
for root, dirs, files in os.walk(args.inp_dir):
for basename in files:
if basename.endswith('.wav'):
filename = os.path.join(root, basename)
input_audios.append(filename)
else:
name_list = np.loadtxt(args.inp_list, dtype='str')
input_audios = [os.path.join(args.inp_dir, name + ".wav") for name in name_list]
input_list = []
for i in input_audios:
input_list.append({'audio_filepath': i, "offset": 0, "duration": None})
logging.info(f"Number of wav files to be processed: {len(input_audios)}")
output_path = os.path.join(args.out_dir, args.manifest_name + '.json')
logging.info("Split long audio file to avoid CUDA memory issue")
logging.debug("Try smaller split_duration if you still have CUDA memory issue")
config = {
'input': input_list,
'window_length_in_sec': args.window_length_in_sec,
'split_duration': args.split_duration,
'num_workers': args.num_workers,
'prepared_manfiest_vad_input': output_path,
}
manifest_vad_input = prepare_manifest(config)
logging.info(f"Done! Save to {manifest_vad_input}")
if __name__ == '__main__':
main()