1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup kws_sdk
18  * @{
19  *
20  * @brief Defines the basic functions, constants, and error codes for the wakeup keyword spotting (KWS) SDK.
21  *
22  * @since 2.2
23  * @version 1.0
24  */
25 
26 /**
27  * @file kws_constants.h
28  *
29  * @brief Defines the default configuration items for the KWS task.
30  *
31  * @since 2.2
32  * @version 1.0
33  */
34 
35 #ifndef KWS_CONSTANTS_H
36 #define KWS_CONSTANTS_H
37 
38 #include <string>
39 
40 namespace OHOS {
41 namespace AI {
42 /**
43  * @brief Defines the invalid handle for the KWS task.
44  *
45  * @since 2.2
46  * @version 1.0
47  */
48 const intptr_t INVALID_KWS_HANDLE = -1;
49 
50 /**
51  * @brief Defines the client version for the KWS task.
52  *
53  * @since 2.2
54  * @version 1.0
55  */
56 const long long CLIENT_VERSION_KWS = 20001001;
57 
58 /**
59  * @brief Defines the algorithm version for the KWS task.
60  *
61  * @since 2.2
62  * @version 1.0
63  */
64 const long long ALGOTYPE_VERSION_KWS = 20001002;
65 
66 /**
67  * @brief Defines the default size of the output window for SlideWindowProcessor.
68  *
69  * @since 2.2
70  * @version 1.0
71  */
72 const size_t DEFAULT_SLIDE_WINDOW_SIZE = 4000;
73 
74 /**
75  * @brief Defines the default step for SlideWindowProcessor.
76  *
77  * @since 2.2
78  * @version 1.0
79  */
80 const size_t DEFAULT_SLIDE_STEP_SIZE = 400;
81 
82 /**
83  * @brief Defines the default mean file path for NormProcessor.
84  *
85  * @since 2.2
86  * @version 1.0
87  */
88 const std::string DEFAULT_NORM_MEAN_FILE_PATH = "/storage/data/kws_mean.txt";
89 
90 /**
91  * @brief Defines the default standard deviation file path for NormProcessor.
92  *
93  * @since 2.2
94  * @version 1.0
95  */
96 const std::string DEFAULT_NORM_STD_FILE_PATH = "/storage/data/kws_std.txt";
97 
98 /**
99  * @brief Defines the default input size for NormProcessor.
100  *
101  * @since 2.2
102  * @version 1.0
103  */
104 const size_t DEFAULT_NORM_INPUT_SIZE = DEFAULT_SLIDE_STEP_SIZE;
105 
106 /**
107  * @brief Defines the default number of channels for NormProcessor.
108  *
109  * @since 2.2
110  * @version 1.0
111  */
112 const size_t DEFAULT_NORM_NUM_CHANNELS = 40;
113 
114 /**
115  * @brief Defines the default scaling coefficient for NormProcessor.
116  *
117  * @since 2.2
118  * @version 1.0
119  */
120 const float DEFAULT_NORM_SCALE = 4096.0f;
121 
122 /**
123  * @brief Defines the default step (in ms) of the audio sampling window for MFCCProcessor.
124  *
125  * @since 2.2
126  * @version 1.0
127  */
128 const int32_t DEFAULT_MFCC_WINDOW_SIZE_MS = 30;
129 
130 /**
131  * @brief Defines the default interval (in ms) between audio sampling windows for MFCCProcessor.
132  *
133  * @since 2.2
134  * @version 1.0
135  */
136 const int32_t DEFAULT_MFCC_SLIDE_SIZE_MS = 20;
137 
138 /**
139  * @brief Defines the default sampling rate for MFCCProcessor.
140  *
141  * @since 2.2
142  * @version 1.0
143  */
144 const uint32_t DEFAULT_MFCC_SAMPLE_RATE = 16000;
145 
146 /**
147  * @brief Defines the default number of frequency-domain channels for MFCCProcessor.
148  *
149  * @since 2.2
150  * @version 1.0
151  */
152 const uint32_t DEFAULT_MFCC_NUM_CHANNELS = 40;
153 
154 /**
155  * @brief Defines the default number of features for MFCCProcessor.
156  *
157  * @since 2.2
158  * @version 1.0
159  */
160 const uint32_t DEFAULT_MFCC_FEATURE_SIZE = DEFAULT_NORM_INPUT_SIZE;
161 
162 /**
163  * @brief Defines the default logarithmic weight for MFCCProcessor.
164  *
165  * @since 2.2
166  * @version 1.0
167  */
168 const int16_t DEFAULT_LOG_SCALE_SHIFT = 6;
169 
170 /**
171  * @brief Defines the default number of smooth bits for noise reduction.
172  *
173  * @since 2.2
174  * @version 1.0
175  */
176 const int16_t DEFAULT_NOISE_SMOOTHING_BITS = 10;
177 
178 /**
179  * @brief Defines the default number of gain bits.
180  *
181  * @since 2.2
182  * @version 1.0
183  */
184 const int16_t DEFAULT_PCAN_GAIN_BITS = 21;
185 
186 /**
187  * @brief Defines the default gain normalization index.
188  *
189  * @since 2.2
190  * @version 1.0
191  */
192 const float DEFAULT_PCAN_GAIN_STRENGTH = 0.95f;
193 
194 /**
195  * @brief Defines the default denominator offset for gain normalization.
196  *
197  * @since 2.2
198  * @version 1.0
199  */
200 const float DEFAULT_PCAN_GAIN_OFFSET = 80.0f;
201 
202 /**
203  * @brief Defines the default minimum frequency threshold of the filter.
204  *
205  * @since 2.2
206  * @version 1.0
207  */
208 const float DEFAULT_FILTERBANK_LOWER_BAND_LIMIT = 125.0f;
209 
210 /**
211  * @brief Defines the default maximum frequency threshold of the filter.
212  *
213  * @since 2.2
214  * @version 1.0
215  */
216 const float DEFAULT_FILTERBANK_UPPER_BAND_LIMIT = 7500.0f;
217 
218 /**
219  * @brief Defines the smoothing coefficient for even channels of noise estimation.
220  *
221  * @since 2.2
222  * @version 1.0
223  */
224 const float DEFAULT_NOISE_EVEN_SMOOTHING = 0.025f;
225 
226 /**
227  * @brief Defines the smoothing coefficient for odd channels of noise estimation.
228  *
229  * @since 2.2
230  * @version 1.0
231  */
232 const float DEFAULT_NOISE_ODD_SMOOTHING = 0.06f;
233 
234 /**
235  * @brief Defines the signal reservation ratio for noise estimation.
236  *
237  * @since 2.2
238  * @version 1.0
239  */
240 const float DEFAULT_NOISE_MIN_SIGNAL_REMAINING = 0.05f;
241 
242 /**
243  * @brief Specifies whether energy gain is executed for MFCCProcessor by default.
244  *
245  * @since 2.2
246  * @version 1.0
247  */
248 const bool DEFAULT_ENABLE_PCAN_GAIN = true;
249 
250 /**
251  * @brief Specifies whether weighted logarithm is executed for MFCCProcessor by default.
252  *
253  * @since 2.2
254  * @version 1.0
255  */
256 const bool DEFAULT_ENABLE_LOG_SCALE = true;
257 } // namespace AI
258 } // namespace OHOS
259 #endif // KWS_CONSTANTS_H
260 /** @} */