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 26 namespace OHOS { 27 namespace IntellVoiceEngine { 28 class EnrollEngine : public EngineBase, private EngineUtil { 29 public: 30 ~EnrollEngine(); 31 bool Init(const std::string ¶m) override; 32 void SetCallback(sptr<IRemoteObject> object) override; 33 int32_t Attach(const IntellVoiceEngineInfo &info) override; 34 int32_t Detach(void) override; 35 int32_t Start(bool isLast) override; 36 int32_t Stop() override; 37 int32_t SetParameter(const std::string &keyValueList) override; 38 std::string GetParameter(const std::string &key) override; 39 int32_t WriteAudio(const uint8_t *buffer, uint32_t size) override; 40 int32_t Evaluate(const std::string &word, EvaluationResultInfo &info) override; 41 42 private: 43 EnrollEngine(); 44 bool SetParameterInner(const std::string &keyValueList); 45 bool StartAudioSource(); 46 void StopAudioSource(); 47 void OnEnrollEvent(int32_t msgId, int32_t result); 48 void OnEnrollComplete(); 49 50 private: 51 using EngineUtil::adapter_; 52 std::string name_ = "lp enroll engine instance"; 53 bool isPcmFromExternal_ = false; 54 int32_t enrollResult_ = -1; 55 sptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback> callback_ = nullptr; 56 std::unique_ptr<AudioSource> audioSource_ = nullptr; 57 std::mutex mutex_; 58 OHOS::AudioStandard::AudioCapturerOptions capturerOptions_; 59 friend class IntellVoiceUtils::SptrFactory<EngineBase, EnrollEngine>; 60 }; 61 } 62 } 63 #endif 64