zohann commited on
Commit
f8b8863
·
verified ·
1 Parent(s): 136b70a

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

Browse files
Audio_Effects_SDK/samples/effects_delayed_streams_demo/run_effect.sh ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Config file location
4
+ cfg_file=/tmp/tmp_cfg.txt
5
+
6
+ effect="denoiser"
7
+ gpu="t4"
8
+ ulimit_val=0
9
+ sample_rate=16
10
+ output_sample_rate=48
11
+ batch_size=10
12
+ reset=
13
+ multi_input=""
14
+ frame_size=10;
15
+ enable_vad=
16
+ ALL_STREAMS_ACTIVE="one_step_delay_streams none
17
+ two_step_delay_streams none"
18
+ SOME_STREAMS_ACTIVE="one_step_delay_streams 0 2 6 8
19
+ two_step_delay_streams 3 5 9"
20
+
21
+ active_streams=$SOME_STREAMS_ACTIVE
22
+
23
+ declare -A gpu_map=( ["a100"]="sm_80"
24
+ ["a30"]="sm_80"
25
+ ["a2"]="sm_86"
26
+ ["a10"]="sm_86"
27
+ ["a16"]="sm_86"
28
+ ["a40"]="sm_86"
29
+ ["t4"]="sm_75"
30
+ ["v100"]="sm_70"
31
+ )
32
+
33
+ gpu_list=$(IFS=/; printf "%s" "${!gpu_map[*]}")
34
+
35
+ declare -A supported_effects=( ["denoiser"]="16 48"
36
+ ["dereverb"]="16 48"
37
+ ["dereverb_denoiser"]="16 48"
38
+ ["aec"]="16 48"
39
+ ["superres"]="8_to_16 16_to_48 8_to_48"
40
+ )
41
+
42
+ supported_effects_list=$(IFS=/; printf "%s" "${!supported_effects[*]}")
43
+
44
+ while [[ "$#" -gt 0 ]]; do
45
+ case $1 in
46
+ -e|--effect) effect="$2"; shift ;;
47
+ -g|--gpu) gpu="$2"; shift ;;
48
+ -u|--ulimit) ulimit_val="$2"; shift ;;
49
+ -s|--sample_rate) sample_rate="$2"; shift ;;
50
+ -o|--output_sample_rate) output_sample_rate="$2"; shift ;;
51
+ -c|--cfg-file) cfg_file="$2"; shift;;
52
+ -r|--reset) multi_input="0,1,2,3,4" reset="reset 2 3 5";;
53
+ -f|--frame_size) frame_size="$2"; shift;;
54
+ -v|--enable_vad) enable_vad=1;;
55
+ -t|--all_streams_active) all_streams_active=$ALL_STREAMS_ACTIVE;;
56
+ -h|--help) echo -e "-g, --gpu : $gpu_list [default=t4]"
57
+ echo -e "-e, --effect : effect to use: $supported_effects_list [default=denoiser]"
58
+ 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)]"
59
+ echo -e "-s, --sample_rate : sample rate to use 8/16/48 (in kHz). [default=16]"
60
+ echo -e "-o, --output_sample_rate : output sample rate to use 16/48 (in kHz). [default=48]"
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 "-t, --all_streams_active: Make all streams active (streams are delayed by default)"
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
+ input_list=""
114
+ if [ "$effect" == "aec" ]; then
115
+ farend_wav=$(./list.sh ../input_files/aec/${sample_rate}k/farend ${batch_size} ${multi_input})
116
+ if [ $? -ne 0 ]; then
117
+ echo "Error generating input files list"
118
+ echo "Command returned: $farend_wav"
119
+ exit 1
120
+ fi
121
+ nearend_wav=${farend_wav//farend/nearend}
122
+ input_list="input_wav_list $nearend_wav
123
+ input_farend_wav_list $farend_wav"
124
+ else
125
+ wav=$(./list.sh ../input_files/${effect}/${sample_rate}k/ ${batch_size} ${multi_input})
126
+ if [ $? -ne 0 ]; then
127
+ echo "Error generating input files list"
128
+ echo "Command returned: $wav"
129
+ exit 1
130
+ fi
131
+ input_list="input_wav_list $wav"
132
+ fi
133
+
134
+ out_file=""
135
+ for i in $(seq 1 $batch_size); do
136
+ out_file="$out_file ${effect}_${sample_rate}k_$i.wav"
137
+ done
138
+
139
+ echo "effect ${effect}
140
+ sample_rate ${sample_rate}000
141
+ model ${model}
142
+ real_time 0
143
+ intensity_ratio 1.0
144
+ $active_streams
145
+ $input_list
146
+ output_wav_list $out_file
147
+ frame_size ${frame_size}" > $cfg_file
148
+
149
+ if [ ! -z "$reset" ]; then
150
+ echo "$reset" >> $cfg_file
151
+ fi
152
+
153
+ if [ ! -z "$enable_vad" ]; then
154
+ echo "enable_vad 1" >> $cfg_file
155
+ fi
156
+
157
+ echo "Using the config file $cfg_file"
158
+
159
+ if [ "$ulimit_val" -ne "0" ]; then
160
+ if [ "$ulimit_val" -le "1024" ]; then
161
+ echo "You probably dont want to do this. ulimit is too low.";
162
+ exit;
163
+ fi
164
+ echo "ulimit set to ${ulimit_val}"
165
+ ulimit -n $ulimit_val
166
+ exit;
167
+ fi
168
+
169
+ ./effects_delayed_streams_demo -c $cfg_file