1 /* 2 * Copyright (c) 2023 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 #ifndef ENROLL_ENGINE_H 16 #define ENROLL_ENGINE_H 17 #include <memory> 18 #include <string> 19 #include "v1_0/iintell_voice_engine_callback.h" 20 #include "audio_info.h" 21 #include "audio_source.h" 22 #include "intell_voice_generic_factory.h" 23 #include "engine_base.h" 24 #include "engine_util.h" 25 #include "enroll_adapter_listener.h" 26 #include "task_executor.h" 27 28 namespace OHOS { 29 namespace IntellVoiceEngine { 30 class EnrollEngine : public EngineBase, private EngineUtil, private OHOS::IntellVoiceUtils::TaskExecutor { 31 public: 32 ~EnrollEngine(); 33 bool Init(const std::string ¶m) override; 34 void SetCallback(sptr<IRemoteObject> object) override; 35 int32_t Attach(const IntellVoiceEngineInfo &info) override; 36 int32_t Detach(void) override; 37 int32_t Start(bool isLast) override; 38 int32_t Stop() override; 39 int32_t SetParameter(const std::string &keyValueList) override; 40 std::string GetParameter(const std::string &key) override; 41 int32_t WriteAudio(const uint8_t *buffer, uint32_t size) override; 42 int32_t Evaluate(const std::string &word, EvaluationResult &result) override; 43 44 private: 45 EnrollEngine(); 46 bool SetParameterInner(const std::string &keyValueList); 47 bool StartAudioSource(); 48 void StopAudioSource(); 49 void OnEnrollEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event); 50 void OnEnrollComplete(int32_t result, const std::string &info); 51 52 private: 53 using EngineUtil::adapter_; 54 std::string name_ = "lp enroll engine instance"; 55 bool isPcmFromExternal_ = false; 56 std::atomic<int32_t> enrollResult_ = -1; 57 uint32_t callerTokenId_ = 0; 58 std::shared_ptr<EnrollAdapterListener> adapterListener_ = nullptr; 59 sptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback> callback_ = nullptr; 60 std::unique_ptr<AudioSource> audioSource_ = nullptr; 61 std::string wakeupPhrase_; 62 std::mutex mutex_; 63 OHOS::AudioStandard::AudioCapturerOptions capturerOptions_; 64 friend class IntellVoiceUtils::SptrFactory<EngineBase, EnrollEngine>; 65 }; 66 } 67 } 68 #endif 69