2 * Copyright 2018-2019 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, mas_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, mas_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);
87 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK "wakeup_engine_set_wakeup_engine_command_callback"
88 typedef int (*wakeup_engine_set_wakeup_engine_command_callback)(wakeup_service_engine_command_cb callback, void* user_data);
90 /* Interfaces after version 1 */
91 #define MA_WAKEUP_ENGINE_FUNC_GET_VERSION "wakeup_engine_get_version"
92 typedef int (*wakeup_engine_get_version)(int* version);
93 #define MA_WAKEUP_ENGINE_FUNC_SET_DEPENDENCY_MODULE_COMMAND "wakeup_engine_set_dependency_module_command"
94 typedef int (*wakeup_engine_set_dependency_module_command)(const char* command);
97 wakeup_engine_initialize initialize;
98 wakeup_engine_deinitialize deinitialize;
99 wakeup_engine_activate activate;
100 wakeup_engine_deactivate deactivate;
101 wakeup_engine_add_wakeup_word add_wakeup_word;
102 wakeup_engine_add_language add_language;
103 wakeup_engine_set_language set_language;
104 wakeup_engine_update_manager_state update_manager_state;
105 wakeup_engine_update_recognition_result update_recognition_result;
106 wakeup_engine_set_audio_format set_audio_format;
107 wakeup_engine_get_audio_format get_audio_format;
108 wakeup_engine_feed_audio_data feed_audio_data;
109 wakeup_engine_get_utterance_data_count get_utterance_data_count;
110 wakeup_engine_get_utterance_data get_utterance_data;
111 wakeup_engine_get_wake_word_data_count get_wake_word_data_count;
112 wakeup_engine_get_wake_word_data get_wake_word_data;
113 wakeup_engine_get_version get_version;
114 wakeup_engine_set_assistant_specific_command set_assistant_specific_command;
115 wakeup_engine_set_wake_word_audio_require_flag set_wake_word_audio_require_flag;
116 wakeup_engine_set_dependency_module_command set_dependency_module_command;
117 wakeup_engine_set_wakeup_event_callback set_wakeup_event_callback;
118 wakeup_engine_set_speech_status_callback set_speech_status_callback;
119 wakeup_engine_set_error_callback set_error_callback;
120 wakeup_engine_set_audio_data_require_status_callback set_audio_data_require_status_callback;
121 wakeup_engine_set_wakeup_engine_command_callback set_wakeup_engine_command_callback;
122 } wakeup_engine_interface;
124 class IEngineEventObserver
127 virtual ~IEngineEventObserver() = default;
128 virtual bool on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info) = 0;
129 virtual bool on_speech_status(string engine_name, mas_speech_status_e status) = 0;
130 virtual bool on_error(string engine_name, int error_code, string error_message) = 0;
131 virtual bool on_audio_data_require_status(string engine_name, bool require) = 0;
133 virtual bool on_streaming_audio_data(
134 mas_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
135 virtual bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
136 virtual bool on_wakeup_engine_command(
137 mas_wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command) = 0;
140 class CWakeupEngineManager
143 CWakeupEngineManager();
144 CWakeupEngineManager(IEngineEventObserver *observer);
145 virtual ~CWakeupEngineManager();
147 CWakeupEngineManager(const CWakeupEngineManager&) = delete;
148 CWakeupEngineManager& operator=(const CWakeupEngineManager&) = delete;
153 void subscribe(IEngineEventObserver *observer);
154 void unsubscribe(IEngineEventObserver *observer);
156 bool get_audio_data_required();
157 void set_selected_wakeup_info(mas_wakeup_event_info wakeup_info);
159 bool set_language(string language);
160 bool set_assistant_language(string appid, string language);
161 void set_assistant_activated(string appid, bool activated);
162 bool get_assistant_activated(string appid);
163 void set_wake_word_audio_require_flag(bool require);
165 void start_streaming_current_utterance_data();
166 void stop_streaming_current_utterance_data();
168 void update_manager_state(wakeup_manager_state_e state);
169 void update_recognition_result(string appid, int result);
171 void engine_add_target_assistant(string engine_name, string appid);
172 void engine_add_wakeup_word(string appid, string wakeup_word, string language);
173 void engine_set_assistant_specific_command(string appid, string command);
174 void engine_set_dependency_module_command(string engine_name, string command);
175 void engine_feed_audio_data(long time, void* data, int len);
177 bool on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info);
178 bool on_speech_status(string engine_name, mas_speech_status_e status);
179 bool on_error(string engine_name, int error_code, string error_message);
180 bool on_audio_data_require_status(string engine_name, bool require);
181 bool on_wakeup_engine_command(string engine_name,
182 mas_wakeup_engine_command_target_e target, string assistant_name, string command);
187 bool activated{false};
188 bool audio_data_require_status{false};
190 wakeup_engine_interface interface{nullptr, };
191 vector<string> assistant_list;
192 set<string> activated_assistants;
193 void *engine_handle{nullptr};
196 void add_engine_directory(string name, string path);
197 void add_engine(string name, string path);
199 vector<IEngineEventObserver*> mObservers;
201 void streaming_speech_data_thread_func();
203 vector<EngineInfo> mEngineInfo;
204 const EngineInfo* mSelectedEngine{nullptr};
205 bool mAudioDataRequired{false};
207 thread mStreamingThread;
208 atomic_bool mStopStreamingThread{false};
210 bool mWakeWordAudioRequired{false};
216 #endif /* _WAKEUP_ENGINE_MANAGER_H_ */