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 I_ENGINE_H 16 #define I_ENGINE_H 17 18 #include <functional> 19 #include <memory> 20 #include "v1_0/intell_voice_engine_types.h" 21 #include "v1_1/intell_voice_engine_types.h" 22 #include "v1_2/intell_voice_engine_types.h" 23 24 namespace OHOS { 25 namespace IntelligentVoice { 26 namespace Engine { 27 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent; 28 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterInfo; 29 using OHOS::HDI::IntelligentVoice::Engine::V1_0::StartInfo; 30 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterDescriptor; 31 using OHOS::HDI::IntelligentVoice::Engine::V1_0::ContentType; 32 using OHOS::HDI::IntelligentVoice::Engine::V1_1::IntellVoiceDataOprType; 33 using OHOS::HDI::IntelligentVoice::Engine::V1_2::UploadHdiFile; 34 using OHOS::HDI::IntelligentVoice::Engine::V1_2::EvaluationResultInfo; 35 using IntellVoiceStatus = int32_t; 36 37 using getParameterCb = std::function<void(const std::string &retStr)>; 38 using getFileDataCb = std::function<void(std::shared_ptr<uint8_t> data, uint32_t size)>; 39 40 class IEngineCallback { 41 public: 42 IEngineCallback() = default; 43 virtual ~IEngineCallback() = default; 44 virtual void OnIntellVoiceEvent(const IntellVoiceEngineCallBackEvent &event) = 0; 45 }; 46 47 struct OprDataInfo { 48 std::shared_ptr<char> data = nullptr; 49 uint32_t size = 0; 50 }; 51 52 class IDataOprListener { 53 public: 54 IDataOprListener() = default; 55 virtual ~IDataOprListener() = default; 56 virtual int32_t OnDataOprEvent(IntellVoiceDataOprType type, const OprDataInfo &inData, OprDataInfo &outData) = 0; 57 }; 58 59 class IEngine { 60 public: IEngine()61 IEngine() {}; ~IEngine()62 virtual ~IEngine() {}; 63 virtual IntellVoiceStatus SetListener(std::shared_ptr<IEngineCallback> listener) = 0; 64 virtual IntellVoiceStatus Init(const IntellVoiceEngineAdapterInfo &adapterInfo) = 0; 65 virtual IntellVoiceStatus Release() = 0; 66 virtual IntellVoiceStatus SetParameter(const std::string &keyValueList) = 0; 67 virtual IntellVoiceStatus GetParameter(const std::string &keyList, getParameterCb cb) = 0; 68 virtual IntellVoiceStatus Write(const uint8_t *buffer, uint32_t size) = 0; 69 virtual IntellVoiceStatus Start(const StartInfo &info) = 0; 70 virtual IntellVoiceStatus Stop() = 0; 71 virtual IntellVoiceStatus Cancel() = 0; 72 virtual IntellVoiceStatus ReadFileData(ContentType type, getFileDataCb cb) = 0; 73 virtual IntellVoiceStatus GetWakeupPcm(std::vector<uint8_t> &data) = 0; 74 virtual IntellVoiceStatus Evaluate(const std::string &word, EvaluationResultInfo &info) = 0; 75 }; 76 77 class IEngineManager { 78 public: ~IEngineManager()79 virtual ~IEngineManager() {}; 80 virtual int32_t CreateAdapter(const IntellVoiceEngineAdapterDescriptor &descriptor, 81 std::unique_ptr<IEngine> &engine) = 0; 82 virtual int32_t ReleaseAdapter(const IntellVoiceEngineAdapterDescriptor &descriptor) = 0; 83 virtual int32_t SetDataOprListener(std::shared_ptr<IDataOprListener> listener) = 0; 84 virtual int32_t GetUploadFiles(int32_t maxNum, std::vector<UploadHdiFile> &files) = 0; 85 virtual int32_t GetCloneFilesList(std::vector<std::string> &cloneFiles) = 0; 86 virtual int32_t GetCloneFile(const std::string &filePath, std::shared_ptr<uint8_t> &buffer, uint32_t &size) = 0; 87 virtual int32_t SendCloneFile(const std::string &filePath, const uint8_t *buffer, uint32_t size) = 0; 88 virtual int32_t ClearUserWakeupData(const std::string &wakeupPhrase) = 0; 89 }; 90 } 91 } 92 } 93 #endif 94