2 * Copyright 2018 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _WAKEUP_ENGINE_MANAGER_H_
18 #define _WAKEUP_ENGINE_MANAGER_H_
20 #include "wakeup_manager_wrapper.h"
28 namespace multiassistant
35 /**************************************************************************************
36 *** Definitions for wakeup engine interface
37 *************************************************************************************/
38 #define MA_WAKEUP_ENGINE_PATH tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "multiassistant/engines")
39 /* Need to check whether this dedicated engine path also needs to be configurable */
40 #define MA_WAKEUP_DEDICATED_ENGINE_PATH "shared/lib/libwakeup-engine.so"
42 /* Interfaces without version information */
43 #define MA_WAKEUP_ENGINE_FUNC_INITIALIZE "wakeup_engine_initialize"
44 typedef int (*wakeup_engine_initialize)(void);
45 #define MA_WAKEUP_ENGINE_FUNC_DEINITIALIZE "wakeup_engine_deinitialize"
46 typedef int (*wakeup_engine_deinitialize)(void);
47 #define MA_WAKEUP_ENGINE_FUNC_ACTIVATE "wakeup_engine_activate"
48 typedef int (*wakeup_engine_activate)(void);
49 #define MA_WAKEUP_ENGINE_FUNC_DEACTIVATE "wakeup_engine_deactivate"
50 typedef int (*wakeup_engine_deactivate)(void);
51 #define MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD "wakeup_engine_add_wakeup_word"
52 typedef int (*wakeup_engine_add_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
53 #define MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE "wakeup_engine_add_language"
54 typedef int (*wakeup_engine_add_language)(const char* appid, const char* language);
55 #define MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE "wakeup_engine_set_language"
56 typedef int (*wakeup_engine_set_language)(const char* language);
57 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE "wakeup_engine_update_manager_state"
58 typedef int (*wakeup_engine_update_manager_state)(wakeup_manager_state_e state);
59 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_RECOGNITION_RESULT "wakeup_engine_update_recognition_result"
60 typedef int (*wakeup_engine_update_recognition_result)(const char* appid, int result);
61 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_FORMAT "wakeup_engine_set_audio_format"
62 typedef int (*wakeup_engine_set_audio_format)(int rate, int channel, int audio_type);
63 #define MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT "wakeup_engine_get_audio_format"
64 typedef int (*wakeup_engine_get_audio_format)(int* rate, int* channel, int* audio_type);
65 #define MA_WAKEUP_ENGINE_FUNC_FEED_AUDIO_DATA "wakeup_engine_feed_audio_data"
66 typedef int (*wakeup_engine_feed_audio_data)(long time, void* data, int len);
67 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT "wakeup_engine_get_utterance_data_count"
68 typedef int (*wakeup_engine_get_utterance_data_count)(void);
69 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA "wakeup_engine_get_utterance_data"
70 typedef int (*wakeup_engine_get_utterance_data)(int index, wakeup_speech_data *data);
71 #define MA_WAKEUP_ENGINE_FUNC_GET_WAKE_WORD_DATA_COUNT "wakeup_engine_get_wake_word_data_count"
72 typedef int (*wakeup_engine_get_wake_word_data_count)(void);
73 #define MA_WAKEUP_ENGINE_FUNC_GET_WAKE_WORD_DATA "wakeup_engine_get_wake_word_data"
74 typedef int (*wakeup_engine_get_wake_word_data)(int index, wakeup_speech_data *data);
75 #define MA_WAKEUP_ENGINE_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_engine_set_assistant_specific_command"
76 typedef int (*wakeup_engine_set_assistant_specific_command)(const char* appid, const char* command);
77 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG "wakeup_engine_set_wake_word_audio_require_flag"
78 typedef int (*wakeup_engine_set_wake_word_audio_require_flag)(bool require);
79 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_engine_set_wakeup_event_callback"
80 typedef int (*wakeup_engine_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
81 #define MA_WAKEUP_ENGINE_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_engine_set_speech_status_callback"
82 typedef int (*wakeup_engine_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
83 #define MA_WAKEUP_ENGINE_FUNC_SET_ERROR_CALLBACK "wakeup_engine_set_error_callback"
84 typedef int (*wakeup_engine_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
85 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_DATA_REQUIRE_STATUS_CALLBACK "wakeup_engine_set_audio_data_require_status_callback"
86 typedef int (*wakeup_engine_set_audio_data_require_status_callback)(wakeup_service_audio_data_require_status_cb callback, void* user_data);
88 /* Interfaces after version 1 */
89 #define MA_WAKEUP_ENGINE_FUNC_GET_VERSION "wakeup_engine_get_version"
90 typedef int (*wakeup_engine_get_version)(int* version);
93 wakeup_engine_initialize initialize;
94 wakeup_engine_deinitialize deinitialize;
95 wakeup_engine_activate activate;
96 wakeup_engine_deactivate deactivate;
97 wakeup_engine_add_wakeup_word add_wakeup_word;
98 wakeup_engine_add_language add_language;
99 wakeup_engine_set_language set_language;
100 wakeup_engine_update_manager_state update_manager_state;
101 wakeup_engine_update_recognition_result update_recognition_result;
102 wakeup_engine_set_audio_format set_audio_format;
103 wakeup_engine_get_audio_format get_audio_format;
104 wakeup_engine_feed_audio_data feed_audio_data;
105 wakeup_engine_get_utterance_data_count get_utterance_data_count;
106 wakeup_engine_get_utterance_data get_utterance_data;
107 wakeup_engine_get_wake_word_data_count get_wake_word_data_count;
108 wakeup_engine_get_wake_word_data get_wake_word_data;
109 wakeup_engine_get_version get_version;
110 wakeup_engine_set_assistant_specific_command set_assistant_specific_command;
111 wakeup_engine_set_wake_word_audio_require_flag set_wake_word_audio_require_flag;
112 wakeup_engine_set_wakeup_event_callback set_wakeup_event_callback;
113 wakeup_engine_set_speech_status_callback set_speech_status_callback;
114 wakeup_engine_set_error_callback set_error_callback;
115 wakeup_engine_set_audio_data_require_status_callback set_audio_data_require_status_callback;
116 } wakeup_engine_interface;
118 class IEngineEventObserver
121 virtual ~IEngineEventObserver() = default;
122 virtual bool on_wakeup_event(string engine_name, wakeup_event_info wakeup_info) = 0;
123 virtual bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) = 0;
124 virtual bool on_error(string engine_name, int error_code, string error_message) = 0;
125 virtual bool on_audio_data_require_status(string engine_name, bool require) = 0;
127 virtual bool on_streaming_audio_data(
128 wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
129 virtual bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
132 class CWakeupEngineManager
135 CWakeupEngineManager();
136 CWakeupEngineManager(IEngineEventObserver *observer);
137 virtual ~CWakeupEngineManager();
139 CWakeupEngineManager(const CWakeupEngineManager&) = delete;
140 CWakeupEngineManager& operator=(const CWakeupEngineManager&) = delete;
145 void subscribe(IEngineEventObserver *observer);
146 void unsubscribe(IEngineEventObserver *observer);
148 bool get_audio_data_required();
149 void set_selected_wakeup_info(wakeup_event_info wakeup_info);
151 bool set_language(string language);
152 void set_assistant_activated(string appid, bool activated);
153 bool get_assistant_activated(string appid);
154 void set_wake_word_audio_require_flag(bool require);
156 void start_streaming_current_utterance_data();
157 void stop_streaming_current_utterance_data();
159 void update_manager_state(wakeup_manager_state_e state);
160 void update_recognition_result(string appid, int result);
162 void engine_add_target_assistant(string engine_name, string appid);
163 void engine_add_wakeup_word(string appid, string wakeup_word, string language);
164 void engine_set_assistant_specific_command(string appid, string command);
165 void engine_feed_audio_data(long time, void* data, int len);
167 bool on_wakeup_event(string engine_name, wakeup_event_info wakeup_info);
168 bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
169 bool on_error(string engine_name, int error_code, string error_message);
170 bool on_audio_data_require_status(string engine_name, bool require);
175 bool activated{false};
176 bool audio_data_require_status{false};
178 wakeup_engine_interface interface{nullptr, };
179 vector<string> assistant_list;
180 set<string> activated_assistants;
181 void *engine_handle{nullptr};
184 void add_engine_directory(string name, string path);
185 void add_engine(string name, string path);
187 vector<IEngineEventObserver*> mObservers;
189 void streaming_speech_data_thread_func();
191 vector<EngineInfo> mEngineInfo;
192 const EngineInfo* mSelectedEngine{nullptr};
193 bool mAudioDataRequired{false};
195 thread mStreamingThread;
196 atomic_bool mStopStreamingThread{false};
198 bool mWakeWordAudioRequired{false};
204 #endif /* _WAKEUP_ENGINE_MANAGER_H_ */