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 #include "kws_sdk.h" 17 18 #include "aie_log.h" 19 #include "kws_retcode.h" 20 #include "kws_sdk_impl.h" 21 22 namespace OHOS { 23 namespace AI { KWSSdk()24KWSSdk::KWSSdk() : kwsSdkImpl_(nullptr) 25 { 26 } 27 ~KWSSdk()28KWSSdk::~KWSSdk() 29 { 30 if (kwsSdkImpl_ != nullptr) { 31 kwsSdkImpl_->Destroy(); 32 kwsSdkImpl_ = nullptr; 33 } 34 } 35 Create()36int32_t KWSSdk::Create() 37 { 38 if (kwsSdkImpl_ != nullptr) { 39 return kwsSdkImpl_->Create(); 40 } 41 kwsSdkImpl_ = std::unique_ptr<KWSSdkImpl>(new (std::nothrow) KWSSdkImpl()); 42 if (kwsSdkImpl_ == nullptr) { 43 HILOGE("[KWSSdk]Fail to allocate memory for kws sdk"); 44 return KWS_RETCODE_FAILURE; 45 } 46 return kwsSdkImpl_->Create(); 47 } 48 SetCallback(const std::shared_ptr<KWSCallback> & callback)49int32_t KWSSdk::SetCallback(const std::shared_ptr<KWSCallback> &callback) 50 { 51 if (kwsSdkImpl_ == nullptr) { 52 HILOGE("[KWSSdk]The SDK has not been created"); 53 return KWS_RETCODE_FAILURE; 54 } 55 return kwsSdkImpl_->SetCallback(callback); 56 } 57 SyncExecute(const Array<int16_t> & input)58int32_t KWSSdk::SyncExecute(const Array<int16_t> &input) 59 { 60 if (kwsSdkImpl_ == nullptr) { 61 HILOGE("[KWSSdk]The SDK has not been created"); 62 return KWS_RETCODE_FAILURE; 63 } 64 return kwsSdkImpl_->SyncExecute(input); 65 } 66 Destroy()67int32_t KWSSdk::Destroy() 68 { 69 if (kwsSdkImpl_ == nullptr) { 70 return KWS_RETCODE_SUCCESS; 71 } 72 return kwsSdkImpl_->Destroy(); 73 } 74 } // namespace AI 75 } // namespace OHOS