zohann commited on
Commit
f4492a8
·
verified ·
1 Parent(s): 2e57aaf

Upload Audio_Effects_SDK/samples/effects_demo/run_effect_chained.sh with huggingface_hub

Browse files
Audio_Effects_SDK/samples/effects_demo/run_effect_chained.sh ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Config file location
4
+ cfg_file=
5
+
6
+ effect1="denoiser"
7
+ effect2="superres"
8
+ gpu="t4"
9
+ ulimit_val=0
10
+ sample_rate1=16
11
+ sample_rate2=16
12
+ output_sample_rate1=16
13
+ output_sample_rate2=48
14
+ batch_size=1
15
+ reset=
16
+ multi_input=""
17
+ frame_size=10;
18
+ input_file=
19
+
20
+ args=()
21
+
22
+ declare -A gpu_map=( ["a100"]="sm_80"
23
+ ["a30"]="sm_80"
24
+ ["a2"]="sm_86"
25
+ ["a10"]="sm_86"
26
+ ["a16"]="sm_86"
27
+ ["a40"]="sm_86"
28
+ ["t4"]="sm_75"
29
+ ["v100"]="sm_70"
30
+ )
31
+ declare -a supported_effects=( "denoiser_16k_superres_16k"
32
+ "dereverb_16k_superres_16k"
33
+ "dereverb_denoiser_16k_superres_16k"
34
+ "superres_8k_denoiser_16k"
35
+ "superres_8k_dereverb_16k"
36
+ "superres_8k_dereverb_denoiser_16k"
37
+ "superres_8k_dereverb_denoiser_16k"
38
+ )
39
+
40
+ gpu_list=$(IFS=/; printf "%s" "${!gpu_map[*]}")
41
+
42
+ while [[ "$#" -gt 0 ]]; do
43
+ args+=($1)
44
+ case $1 in
45
+ -e1|--effect1) effect1="$2"; args+=($2); shift ;;
46
+ -e2|--effect2) effect2="$2"; args+=($2); shift ;;
47
+ -g|--gpu) gpu="$2"; args+=($2); shift ;;
48
+ -u|--ulimit) ulimit_val="$2"; args+=($2); shift ;;
49
+ -s1|--sample_rate) sample_rate1="$2"; args+=($2); shift ;;
50
+ -s2|--sample_rate2) sample_rate2="$2"; args+=($2); shift ;;
51
+ -o1|--output_sample_rate1) output_sample_rate1="$2"; args+=($2); shift ;;
52
+ -o2|--output_sample_rate2) output_sample_rate2="$2"; args+=($2); shift ;;
53
+ -b|--batch_size) batch_size="$2"; args+=($2); shift ;;
54
+ -c|--cfg-file) cfg_file="$2"; args+=($2); shift;;
55
+ -r|--reset) multi_input="0,1,2,3,4" reset="reset 2 3 5";;
56
+ -f|--frame_size) frame_size="$2"; args+=($2); shift;;
57
+ -i|--input_file) input_file="$2"; unset 'args[${#args[@]}-1]'; shift;;
58
+ -h|--help) echo -e "-g, --gpu : $gpu_list [default=t4]"
59
+ echo -e "-e1, --effect1 : First effect to use: denoiser/dereverb/dereverb_denoiser/superres [default=denoiser]"
60
+ echo -e "-e2, --effect2 : Second effect to use: denoiser/dereverb/dereverb_denoiser/superres [default=denoiser]"
61
+ 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)]"
62
+ echo -e "-s1, --sample_rate1 : sample rate to use 8/16/48 (in kHz) for first effect. [default=16]"
63
+ echo -e "-s2, --sample_rate2 : sample rate to use 8/16/48 (in kHz) for second effect. [default=48]"
64
+ echo -e "-o1, --output_sample_rate1 : output sample rate to use 16/48 (in kHz) for first effect. [default=48]"
65
+ echo -e "-o2, --output_sample_rate2 : output sample rate to use 16/48 (in kHz) for second effect. [default=48]"
66
+ echo -e "-b, --batch_size : batch size to use. [default=1, max=1024]"
67
+ echo -e "-c, --cfg-file: configuration file to write to"
68
+ echo -e "-f, --frame_size: frame size to be used 10/20ms. [default=10]"
69
+ echo -e "-i, --input_file: file to be used as input, instead of using sample input files (file must be in correct format)"
70
+ echo -e "-h, --help: print this help menu";exit;;
71
+ *) echo "Unknown parameter passed: $1"; exit 1 ;;
72
+ esac
73
+ shift
74
+ done
75
+
76
+ effect_check="\b${effect1}_${sample_rate1}k_${effect2}_${sample_rate2}k\b"
77
+ if ! [[ "${supported_effects[@]}" =~ ${effect_check} ]]; then
78
+ echo "Chain (${effect1} ${sample_rate1}k + ${effect2} ${sample_rate2}k) is not supported. Supported chains are:"
79
+ for e in "${supported_effects[@]}"; do
80
+ v=${e//k_/k + }
81
+ echo "- ${v//_/ }"
82
+ done
83
+ exit 1
84
+ fi
85
+
86
+ OUT_DIR="chained/${effect1}${sample_rate1}k_${effect2}${sample_rate2}k"
87
+ mkdir -p "$OUT_DIR"
88
+ input_list=""
89
+ out_file=""
90
+ if [ ! -z "$input_file" ]; then
91
+ if [[ ! (-f "$input_file" || -d "$input_file") ]]; then
92
+ echo "Error: File/folder '$input_file' does not exist"
93
+ exit 1
94
+ fi
95
+ if [ $(($batch_size)) -ne 1 ]; then
96
+ echo "Error: Batch size must be 1 when input file/folder is specified (got $batch_size)"
97
+ exit 1
98
+ fi
99
+ if [ -d "$input_file" ]; then
100
+ if [ ! -z "$cfg_file" ]; then
101
+ echo "Error: config file cannot be specified if input is a folder"
102
+ exit 1
103
+ fi
104
+ # If folder, process file by file for all files in that folder
105
+ for i in "${input_file}"/*.wav; do
106
+ ./$0 "${args[@]}" -i "$i"
107
+ if [ $? -ne 0 ]; then
108
+ echo "Error processing file '$i'"
109
+ exit 1
110
+ fi
111
+ done
112
+ exit 0
113
+ else
114
+ input_list="input_wav_list $input_file"
115
+ out_file="$OUT_DIR/$(basename $input_file)"
116
+ fi
117
+ else
118
+ folder="${effect1}_${sample_rate1}k_${effect2}_${sample_rate2}k"
119
+ wav=$(./list.sh ../input_files/chaining/${folder}/ ${batch_size} ${multi_input})
120
+ if [ $? -ne 0 ]; then
121
+ echo "Error generating input files list"
122
+ echo "Command returned: $wav"
123
+ exit 1
124
+ fi
125
+ input_list="input_wav_list $wav"
126
+ for i in $(seq 1 $batch_size); do
127
+ out_file="$out_file ${OUT_DIR}/${effect1}${sample_rate1}k_${effect2}${sample_rate2}k_$i.wav"
128
+ done
129
+ fi
130
+
131
+ if [ -z "$cfg_file" ]; then
132
+ cfg_file="/tmp/tmp_cfg.txt"
133
+ fi
134
+
135
+ if [ -z "${gpu_map[$gpu]:-}" ]; then
136
+ echo "Invalid GPU (got $gpu, supported $gpu_list)"
137
+ exit 1
138
+ fi
139
+ arch="${gpu_map[$gpu]}"
140
+
141
+ model1="../../models"
142
+ model2="../../models"
143
+ if [ "$effect1" == "superres" ]; then
144
+ model1="${model1}/${arch}/${effect1}_${sample_rate1}k_to_${output_sample_rate1}k.trtpkg"
145
+ else
146
+ model1="${model1}/${arch}/${effect1}_${sample_rate1}k.trtpkg"
147
+ fi
148
+
149
+ if [ "$effect2" == "superres" ]; then
150
+ model2="${model2}/${arch}/${effect2}_${sample_rate2}k_to_${output_sample_rate2}k.trtpkg"
151
+ else
152
+ model2="${model2}/${arch}/${effect2}_${sample_rate2}k.trtpkg"
153
+ fi
154
+
155
+ echo "effect ${effect1} ${effect2}
156
+ sample_rate ${sample_rate1}000 ${sample_rate2}000
157
+ model ${model1} ${model2}
158
+ real_time 0
159
+ $input_list
160
+ output_wav_list $out_file
161
+ frame_size ${frame_size}" > $cfg_file
162
+
163
+ if [ ! -z "$reset" ]; then
164
+ if [ $batch_size -lt 5 ]; then
165
+ echo "Batch size must be at least 5 for reset configs"
166
+ exit 1
167
+ fi
168
+ echo "$reset" >> $cfg_file
169
+ fi
170
+
171
+ echo "Using the config file $cfg_file"
172
+
173
+ if [ "$ulimit_val" -ne "0" ]; then
174
+ if [ "$ulimit_val" -le "1024" ]; then
175
+ echo "You probably dont want to do this. ulimit is too low.";
176
+ exit;
177
+ fi
178
+ echo "ulimit set to ${ulimit_val}";
179
+ ulimit -n $ulimit_val
180
+ exit;
181
+ fi
182
+
183
+ ./effects_demo -c $cfg_file