#!/bin/bash # Config file location cfg_file= effect="denoiser" gpu="t4" ulimit_val=0 sample_rate=16 output_sample_rate=48 batch_size=1 reset= multi_input="" frame_size=10; enable_vad= input_file= args=() declare -A gpu_map=( ["a100"]="sm_80" ["a30"]="sm_80" ["a2"]="sm_86" ["a10"]="sm_86" ["a16"]="sm_86" ["a40"]="sm_86" ["t4"]="sm_75" ["v100"]="sm_70" ) gpu_list=$(IFS=/; printf "%s" "${!gpu_map[*]}") declare -A supported_effects=( ["denoiser"]="16 48" ["dereverb"]="16 48" ["dereverb_denoiser"]="16 48" ["aec"]="16 48" ["superres"]="8_to_16 16_to_48 8_to_48" ) supported_effects_list=$(IFS=/; printf "%s" "${!supported_effects[*]}") while [[ "$#" -gt 0 ]]; do args+=($1) case $1 in -e|--effect) effect="$2"; args+=($2); shift ;; -g|--gpu) gpu="$2"; args+=($2); shift ;; -u|--ulimit) ulimit_val="$2"; args+=($2); shift ;; -s|--sample_rate) sample_rate="$2"; args+=($2); shift ;; -o|--output_sample_rate) output_sample_rate="$2"; args+=($2); shift ;; -b|--batch_size) batch_size="$2"; args+=($2); shift ;; -c|--cfg-file) cfg_file="$2"; args+=($2); shift;; -r|--reset) multi_input="0,1,2,3,4" reset="reset 2 3 5";; -f|--frame_size) frame_size="$2"; args+=($2); shift;; -v|--enable_vad) enable_vad=1;; -i|--input_file) input_file="$2"; unset 'args[${#args[@]}-1]'; shift;; -h|--help) echo -e "-g, --gpu : $gpu_list [default=t4]" echo -e "-e, --effect : effect to use: $supported_effects_list [default=denoiser]" echo -e "-u, --ulimit : raise files open ulimit, this is used when running larger batch sizes that exceed the kernel maximum open files limit. Warning: Use this option with caution. [default=0(unusued)]" echo -e "-s, --sample_rate : sample rate to use 8/16/48 (in kHz). [default=16]" echo -e "-o, --output_sample_rate : output sample rate to use 16/48 (in kHz). [default=48]" echo -e "-b, --batch_size : batch size to use. [default=1, max=1024]" echo -e "-c, --cfg-file: configuration file to write to" echo -e "-f, --frame_size: frame size to be used 10/20ms. [default=10]" echo -e "-v, --enable_vad: Enable VAD. Refer to the Programming Guide for supported effects. [default=disabled]" echo -e "-i, --input_file: file/folder to be used as input, instead of using sample input files (file must be in correct format)" echo -e "-h, --help: print this help menu";exit;; *) echo "Unknown parameter passed: $1"; exit 1 ;; esac shift done # Verify if effect is supported if [ "$effect" == "superres" ]; then rate_check="${sample_rate}_to_${output_sample_rate}" else rate_check="$sample_rate" fi if [ -z "${supported_effects[$effect]:-}" ]; then echo "Invalid effect (got $effect, supported $supported_effects_list)" exit 1 fi rate_supported="${supported_effects[$effect]}" check_val="\b$rate_check\b" if ! [[ "$rate_supported" =~ $check_val ]]; then if [ "$effect" == "superres" ]; then cv=${rate_supported// /, } echo "Sample rate combination '$sample_rate -> $output_sample_rate' is not supported for Superres (supported combinations: ${cv//_to_/ -> }" else echo "Sample rate '$rate_check' is not supported for this effect (supported: ${rate_supported// /, })" fi exit 1 fi # Validate GPU if [ -z "${gpu_map[$gpu]:-}" ]; then echo "Invalid GPU (got $gpu, supported $gpu_list)" exit 1 fi arch="${gpu_map[$gpu]}" model="../../models" if [ "$effect" == "superres" ]; then model="${model}/${arch}/${effect}_${sample_rate}k_to_${output_sample_rate}k.trtpkg" else model="${model}/${arch}/${effect}_${sample_rate}k.trtpkg" fi if [ ! -f "$model" ]; then echo "Model file not found (using '$model')" exit 1 fi OUT_DIR="${effect}/${sample_rate}k" mkdir -p "$OUT_DIR" input_list="" out_file="" if [ ! -z "$input_file" ]; then if [[ ! (-f "$input_file" || -d "$input_file") ]]; then echo "Error: File/folder '$input_file' does not exist" exit 1 fi if [ $(($batch_size)) -ne 1 ]; then echo "Error: Batch size must be 1 when input file/folder is specified (got $batch_size)" exit 1 fi if [ -d "$input_file" ]; then if [ ! -z "$cfg_file" ]; then echo "Error: config file cannot be specified if input is a folder" exit 1 fi # If folder, process file by file for all files in that folder for i in "${input_file}"/*.wav; do ./$0 "${args[@]}" -i "$i" if [ $? -ne 0 ]; then echo "Error processing file '$i'" exit 1 fi done exit 0 else input_list="input_wav_list $input_file" out_file="$OUT_DIR/$(basename $input_file)" fi else if [ "$effect" == "aec" ]; then farend_wav=$(./list.sh ../input_files/aec/${sample_rate}k/farend ${batch_size} ${multi_input}) if [ $? -ne 0 ]; then echo "Error generating input files list" echo "Command returned: $farend_wav" exit 1 fi nearend_wav=${farend_wav//farend/nearend} input_list="input_wav_list $nearend_wav input_farend_wav_list $farend_wav" else wav=$(./list.sh ../input_files/${effect}/${sample_rate}k/ ${batch_size} ${multi_input}) if [ $? -ne 0 ]; then echo "Error generating input files list" echo "Command returned: $wav" exit 1 fi input_list="input_wav_list $wav" fi for i in $(seq 1 $batch_size); do out_file="$out_file $OUT_DIR/${effect}_${sample_rate}k_$i.wav" done fi if [ -z "$cfg_file" ]; then cfg_file="/tmp/tmp_cfg.txt" fi echo "effect ${effect} sample_rate ${sample_rate}000 model ${model} real_time 0 intensity_ratio 1.0 $input_list output_wav_list $out_file frame_size ${frame_size}" > $cfg_file if [ ! -z "$reset" ]; then if [ $batch_size -lt 5 ]; then echo "Batch size must be at least 5 for reset configs" exit 1 fi echo "$reset" >> $cfg_file fi if [ ! -z "$enable_vad" ]; then echo "enable_vad 1" >> $cfg_file fi echo "Using the config file $cfg_file" if [ "$ulimit_val" -ne "0" ]; then if [ "$ulimit_val" -le "1024" ]; then echo "You probably dont want to do this. ulimit is too low."; exit; fi echo "ulimit set to ${ulimit_val}"; ulimit -n $ulimit_val exit; fi ./effects_demo -c $cfg_file