zohann commited on
Commit
30ee64e
·
verified ·
1 Parent(s): 0b339b6

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

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