• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "wakeup_intell_voice_engine.h"
17 #include "i_intell_voice_engine.h"
18 #include "intell_voice_manager.h"
19 #include "intell_voice_log.h"
20 
21 #define LOG_TAG "WakeupIntellVoiceEngine"
22 
23 using namespace std;
24 using namespace OHOS::IntellVoiceEngine;
25 
26 namespace OHOS {
27 namespace IntellVoice {
WakeupIntellVoiceEngine(const WakeupIntelligentVoiceEngineDescriptor & descriptor)28 WakeupIntellVoiceEngine::WakeupIntellVoiceEngine(const WakeupIntelligentVoiceEngineDescriptor &descriptor)
29 {
30     INTELL_VOICE_LOG_INFO("enter");
31 
32     descriptor_ = make_unique<WakeupIntelligentVoiceEngineDescriptor>();
33     descriptor_->needReconfirm = descriptor.needReconfirm;
34     descriptor_->wakeupPhrase = descriptor.wakeupPhrase;
35     IntellVoiceManager::GetInstance()->CreateIntellVoiceEngine(INTELL_VOICE_WAKEUP, engine_);
36 }
37 
~WakeupIntellVoiceEngine()38 WakeupIntellVoiceEngine::~WakeupIntellVoiceEngine()
39 {
40     INTELL_VOICE_LOG_INFO("enter");
41 }
42 
SetSensibility(const int32_t & sensibility)43 int32_t WakeupIntellVoiceEngine::SetSensibility(const int32_t &sensibility)
44 {
45     INTELL_VOICE_LOG_INFO("enter");
46     if (engine_ == nullptr) {
47         INTELL_VOICE_LOG_ERROR("engine is null");
48         return -1;
49     }
50     string keyValueList = "Sensibility=" + to_string(sensibility);
51     return engine_->SetParameter(keyValueList);
52 }
53 
SetWakeupHapInfo(const WakeupHapInfo & info)54 int32_t WakeupIntellVoiceEngine::SetWakeupHapInfo(const WakeupHapInfo &info)
55 {
56     INTELL_VOICE_LOG_INFO("enter");
57     int32_t ret;
58     if (engine_ == nullptr) {
59         INTELL_VOICE_LOG_ERROR("engine is null");
60         return -1;
61     }
62     ret = engine_->SetParameter("wakeup_bundle_name=" + info.bundleName);
63     ret += engine_->SetParameter("wakeup_ability_name=" + info.abilityName);
64     return ret;
65 }
66 
SetParameter(const string & key,const string & value)67 int32_t WakeupIntellVoiceEngine::SetParameter(const string &key, const string &value)
68 {
69     INTELL_VOICE_LOG_INFO("enter");
70     if (engine_ == nullptr) {
71         INTELL_VOICE_LOG_ERROR("engine is null");
72         return -1;
73     }
74     string keyValueList = key + "=" + value;
75     return engine_->SetParameter(keyValueList);
76 }
77 
Release()78 int32_t WakeupIntellVoiceEngine::Release()
79 {
80     INTELL_VOICE_LOG_INFO("enter");
81     return 0;
82 }
83 
SetCallback(shared_ptr<IIntellVoiceEngineEventCallback> callback)84 int32_t WakeupIntellVoiceEngine::SetCallback(shared_ptr<IIntellVoiceEngineEventCallback> callback)
85 {
86     INTELL_VOICE_LOG_INFO("enter");
87     if (engine_ == nullptr) {
88         INTELL_VOICE_LOG_ERROR("engine is null");
89         return -1;
90     }
91 
92     callback_ = sptr<EngineCallbackInner>(new (std::nothrow) EngineCallbackInner(callback));
93     if (callback_ == nullptr) {
94         INTELL_VOICE_LOG_ERROR("callback_ is nullptr");
95         return -1;
96     }
97     engine_->SetCallback(callback_->AsObject());
98     return 0;
99 }
100 
StartCapturer(int32_t channels)101 int32_t WakeupIntellVoiceEngine::StartCapturer(int32_t channels)
102 {
103     INTELL_VOICE_LOG_INFO("enter");
104     if (engine_ == nullptr) {
105         INTELL_VOICE_LOG_ERROR("engine is null");
106         return -1;
107     }
108     return engine_->StartCapturer(channels);
109 }
110 
Read(std::vector<uint8_t> & data)111 int32_t WakeupIntellVoiceEngine::Read(std::vector<uint8_t> &data)
112 {
113     INTELL_VOICE_LOG_INFO("enter");
114     CHECK_CONDITION_RETURN_RET(engine_ == nullptr, -1, "engine is null");
115 
116     return engine_->Read(data);
117 }
118 
StopCapturer()119 int32_t WakeupIntellVoiceEngine::StopCapturer()
120 {
121     INTELL_VOICE_LOG_INFO("enter");
122     CHECK_CONDITION_RETURN_RET(engine_ == nullptr, -1, "engine is null");
123 
124     return engine_->StopCapturer();
125 }
126 
GetWakeupPcm(std::vector<uint8_t> & data)127 int32_t WakeupIntellVoiceEngine::GetWakeupPcm(std::vector<uint8_t> &data)
128 {
129     INTELL_VOICE_LOG_INFO("enter");
130     CHECK_CONDITION_RETURN_RET(engine_ == nullptr, -1, "engine is null");
131 
132     return engine_->GetWakeupPcm(data);
133 }
134 
NotifyHeadsetWakeEvent()135 int32_t WakeupIntellVoiceEngine::NotifyHeadsetWakeEvent()
136 {
137     INTELL_VOICE_LOG_INFO("enter");
138     if (engine_ == nullptr) {
139         INTELL_VOICE_LOG_ERROR("engine is null");
140         return -1;
141     }
142     return engine_->NotifyHeadsetWakeEvent();
143 }
144 
NotifyHeadsetHostEvent(int32_t event)145 int32_t WakeupIntellVoiceEngine::NotifyHeadsetHostEvent(int32_t event)
146 {
147     INTELL_VOICE_LOG_INFO("enter, event:%{public}d", event);
148     if (engine_ == nullptr) {
149         INTELL_VOICE_LOG_ERROR("engine is null");
150         return -1;
151     }
152     return engine_->NotifyHeadsetHostEvent(static_cast<OHOS::IntellVoiceEngine::HeadsetHostEventType>(event));
153 }
154 }
155 }