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 #ifndef KWS_SDK_IMPL_H
17 #define KWS_SDK_IMPL_H
18 
19 #include <vector>
20 
21 #include "ai_datatype.h"
22 #include "aie_algorithm_type.h"
23 #include "aie_info_define.h"
24 #include "constants.h"
25 #include "feature_processor.h"
26 #include "kws_callback.h"
27 #include "kws_constants.h"
28 #include "kws_sdk.h"
29 #include "pcm_iterator.h"
30 
31 namespace OHOS {
32 namespace AI {
33 class KWSSdk::KWSSdkImpl {
34 public:
35     KWSSdkImpl();
36     virtual ~KWSSdkImpl();
37     int32_t Create();
38     int32_t SyncExecute(const Array<int16_t> &input);
39     int32_t Destroy();
40     int32_t SetCallback(std::shared_ptr<KWSCallback> callback);
41 
42 private:
43     int32_t InitComponents();
44     int32_t Execute(const Array<uint16_t> &input);
45 
46 private:
47     std::shared_ptr<KWSCallback> callback_ = nullptr;
48     std::unique_ptr<PCMIterator> pcmIterator_ = nullptr;
49     std::unique_ptr<Feature::FeatureProcessor> mfccProcessor_ = nullptr;
50     ConfigInfo configInfo_ {.description = "kws config description"};
51     intptr_t kwsHandle_ = INVALID_KWS_HANDLE;
52     ClientInfo clientInfo_ {
53         .clientVersion = CLIENT_VERSION_KWS,
54         .clientId = INVALID_CLIENT_ID,
55         .sessionId = INVALID_SESSION_ID,
56         .extendLen = EXT_MSG_LEN_DEFAULT,
57         .extendMsg = nullptr
58     };
59     AlgorithmInfo algorithmInfo_ {
60         .clientVersion = CLIENT_VERSION_KWS,
61         .isAsync = false,
62         .algorithmType = ALGORITHM_TYPE_KWS,
63         .algorithmVersion = ALGOTYPE_VERSION_KWS,
64         .isCloud = false,
65         .operateId = STARTING_OPERATE_ID,
66         .requestId = STARTING_REQ_ID,
67         .extendLen = EXT_MSG_LEN_DEFAULT,
68         .extendMsg = nullptr
69     };
70 };
71 } // namespace AI
72 } // namespace OHOS
73 #endif // KWS_SDK_IMPL_H