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 IINTELL_VOICE_ENGINE_H
17 #define IINTELL_VOICE_ENGINE_H
18 #include "iremote_broker.h"
19 #include "i_intell_voice_engine_callback.h"
20 #include "v1_2/intell_voice_engine_types.h"
21 
22 namespace OHOS {
23 namespace IntellVoiceEngine {
24 using OHOS::HDI::IntelligentVoice::Engine::V1_2::EvaluationResultInfo;
25 
26 enum IntellVoiceEngineType {
27     INTELL_VOICE_ENROLL = 0,
28     INTELL_VOICE_WAKEUP,
29     INTELL_VOICE_UPDATE,
30     ENGINE_TYPE_BUT
31 };
32 
33 enum IntellVoiceUpdateSceneType {
34     INTELL_VOICE_DEFAULT = -1,
35     INTELL_VOICE_SILENCE_UPDATE = 0,
36     INTELL_VOICE_CLONE_UPDATE,
37     INTELL_VOICE_CLOUD_UPDATE,
38     INTELL_VOICE_SCENE_TYPE_BUT
39 };
40 
41 enum HeadsetHostEventType {
42     HEADSET_HOST_OFF = 0,
43     HEADSET_HOST_ON = 1,
44 };
45 
46 struct IntellVoiceEngineInfo {
47     std::string wakeupPhrase;
48     bool isPcmFromExternal { false };
49     int32_t minBufSize { 0 };
50     int32_t sampleChannels { 0 };
51     int32_t bitsPerSample { 0 };
52     int32_t sampleRate { 0 };
53 };
54 
55 class IIntellVoiceEngine : public IRemoteBroker {
56 public:
57     DECLARE_INTERFACE_DESCRIPTOR(u"HDI.IntellVoice.Engine");
58 
59     enum {
60         INTELL_VOICE_ENGINE_SET_CALLBACK = 0,
61         INTELL_VOICE_ENGINE_ATTACH,
62         INTELL_VOICE_ENGINE_DETACH,
63         INTELL_VOICE_ENGINE_SET_PARAMETER,
64         INTELL_VOICE_ENGINE_GET_PARAMETER,
65         INTELL_VOICE_ENGINE_START,
66         INTELL_VOICE_ENGINE_STOP,
67         INTELL_VOICE_ENGINE_WRITE_AUDIO,
68         INTELL_VOICE_ENGINE_STAET_CAPTURER,
69         INTELL_VOICE_ENGINE_READ,
70         INTELL_VOICE_ENGINE_STOP_CAPTURER,
71         INTELL_VOICE_ENGINE_GET_WAKEUP_PCM,
72         INTELL_VOICE_ENGINE_EVALUATE,
73         INTELL_VOICE_ENGINE_NOTIFY_HEADSET_WAKE_EVENT,
74         INTELL_VOICE_ENGINE_NOTIFY_HEADSET_HOSTEVENT
75     };
76 
77     virtual void SetCallback(sptr<IRemoteObject> object) = 0;
78     virtual int32_t Attach(const IntellVoiceEngineInfo &info) = 0;
79     virtual int32_t Detach(void) = 0;
80     virtual int32_t SetParameter(const std::string &keyValueList) = 0;
81     virtual std::string GetParameter(const std::string &key) = 0;
82     virtual int32_t Start(bool isLast) = 0;
83     virtual int32_t Stop(void) = 0;
84     virtual int32_t WriteAudio(const uint8_t *buffer, uint32_t size) = 0;
85     virtual int32_t StartCapturer(int32_t channels) = 0;
86     virtual int32_t Read(std::vector<uint8_t> &data) = 0;
87     virtual int32_t StopCapturer() = 0;
88     virtual int32_t GetWakeupPcm(std::vector<uint8_t> &data) = 0;
89     virtual int32_t Evaluate(const std::string &word, EvaluationResultInfo &info) = 0;
90     virtual int32_t NotifyHeadsetWakeEvent() = 0;
91     virtual int32_t NotifyHeadsetHostEvent(HeadsetHostEventType event) = 0;
92 };
93 }
94 }
95 
96 #endif
97