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 16 #ifndef HDI_DEVICE_INTELL_VOICE_ADAPTER_SERVICE_H 17 #define HDI_DEVICE_INTELL_VOICE_ADAPTER_SERVICE_H 18 19 #include <memory> 20 #include <fstream> 21 #include <map> 22 23 #include "v1_2/iintell_voice_engine_adapter.h" 24 #include "i_engine.h" 25 26 namespace OHOS { 27 namespace IntelligentVoice { 28 namespace Engine { 29 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback; 30 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent; 31 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterInfo; 32 using OHOS::HDI::IntelligentVoice::Engine::V1_0::StartInfo; 33 using OHOS::HDI::IntelligentVoice::Engine::V1_0::ContentType; 34 using OHOS::HDI::IntelligentVoice::Engine::V1_2::EvaluationResultInfo; 35 36 class EngineListener : public IEngineCallback { 37 public: 38 explicit EngineListener(const sptr<IIntellVoiceEngineCallback> &cb); 39 ~EngineListener(); 40 void OnIntellVoiceEvent(const IntellVoiceEngineCallBackEvent &event) override; 41 private: 42 sptr<IIntellVoiceEngineCallback> cb_; 43 }; 44 45 class IntellVoiceEngineAdapterImpl : public HDI::IntelligentVoice::Engine::V1_2::IIntellVoiceEngineAdapter { 46 public: 47 explicit IntellVoiceEngineAdapterImpl(std::unique_ptr<IEngine> engine); 48 ~IntellVoiceEngineAdapterImpl(); 49 50 int32_t SetCallback(const sptr<IIntellVoiceEngineCallback> &engineCallback) override; 51 int32_t Attach(const IntellVoiceEngineAdapterInfo &info) override; 52 int32_t Detach() override; 53 int32_t SetParameter(const std::string &keyValueList) override; 54 int32_t GetParameter(const std::string &keyList, std::string &valueList) override; 55 int32_t Start(const StartInfo &info) override; 56 int32_t Stop() override; 57 int32_t WriteAudio(const std::vector<uint8_t> &buffer) override; 58 int32_t Read(ContentType type, sptr<Ashmem> &buffer) override; 59 int32_t GetWakeupPcm(std::vector<uint8_t> &data) override; 60 int32_t Evaluate(const std::string &word, EvaluationResultInfo &info) override; 61 62 private: 63 int32_t ReadFileDataInner(ContentType type, uint8_t *&buffer, uint32_t &size); 64 65 private: 66 std::unique_ptr<IEngine> engine_ = nullptr; 67 }; 68 } 69 } 70 } 71 #endif 72