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_sdk.h 28 * 29 * @brief Defines the basic functions for the KWS SDK. 30 * 31 * @since 2.2 32 * @version 1.0 33 */ 34 35 #ifndef KWS_SDK_H 36 #define KWS_SDK_H 37 38 #include <memory> 39 40 #include "ai_datatype.h" 41 #include "kws_callback.h" 42 43 namespace OHOS { 44 namespace AI { 45 class KWSSdk { 46 public: 47 /** 48 * @brief Defines the constructor for the KWS SDK. 49 * 50 * @since 2.2 51 * @version 1.0 52 */ 53 KWSSdk(); 54 55 /** 56 * @brief Defines the destructor for the KWS SDK. 57 * 58 * @since 2.2 59 * @version 1.0 60 */ 61 virtual ~KWSSdk(); 62 63 /** 64 * @brief Creates a KWS SDK instance. 65 * 66 * @return Returns {@link KWS_RETCODE_SUCCESS} if the operation is successful; 67 * returns a non-zero error code defined by {@link KWSRetCode} otherwise. 68 * 69 * @since 2.2 70 * @version 1.0 71 */ 72 int32_t Create(); 73 74 /** 75 * @brief Synchronously executes the KWS task. 76 * 77 * @param input Indicates the input array defined by {@link Array} for the KWS task. The element type is int16_t. 78 * @return Returns {@link KWS_RETCODE_SUCCESS} if the operation is successful; 79 * returns a non-zero error code defined by {@link KWSRetCode} otherwise. 80 * 81 * @since 2.2 82 * @version 1.0 83 */ 84 int32_t SyncExecute(const Array<int16_t> &input); 85 86 /** 87 * @brief Sets the callback for the KWS task. 88 * 89 * @param callback Indicates the callback defined by {@link KWSCallback} for implementing the post-processing logic. 90 * @return Returns {@link KWS_RETCODE_SUCCESS} if the operation is successful; 91 * returns a non-zero error code defined by {@link KWSRetCode} otherwise. 92 * 93 * @since 2.2 94 * @version 1.0 95 */ 96 int32_t SetCallback(const std::shared_ptr<KWSCallback> &callback); 97 98 /** 99 * @brief Destroys the KWS SDK instance to release the session engaged with the plugin. 100 * 101 * @return Returns {@link KWS_RETCODE_SUCCESS} if the operation is successful; 102 * returns a non-zero error code defined by {@link KWSRetCode} otherwise. 103 * 104 * @since 2.2 105 * @version 1.0 106 */ 107 int32_t Destroy(); 108 private: 109 class KWSSdkImpl; 110 std::unique_ptr<KWSSdkImpl> kwsSdkImpl_; 111 }; 112 } // namespace AI 113 } // namespace OHOS 114 #endif // KWS_SDK_H 115 /** @} */