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 #define MA_WAKEUP_ENGINE_FUNC_INITIALIZE "wakeup_engine_initialize"
43 typedef int (*wakeup_engine_initialize)(void);
44 #define MA_WAKEUP_ENGINE_FUNC_DEINITIALIZE "wakeup_engine_deinitialize"
45 typedef int (*wakeup_engine_deinitialize)(void);
46 #define MA_WAKEUP_ENGINE_FUNC_ACTIVATE "wakeup_engine_activate"
47 typedef int (*wakeup_engine_activate)(void);
48 #define MA_WAKEUP_ENGINE_FUNC_DEACTIVATE "wakeup_engine_deactivate"
49 typedef int (*wakeup_engine_deactivate)(void);
50 #define MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD "wakeup_engine_add_wakeup_word"
51 typedef int (*wakeup_engine_add_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
52 #define MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE "wakeup_engine_add_language"
53 typedef int (*wakeup_engine_add_language)(const char* appid, const char* language);
54 #define MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE "wakeup_engine_set_language"
55 typedef int (*wakeup_engine_set_language)(const char* language);
56 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE "wakeup_engine_update_manager_state"
57 typedef int (*wakeup_engine_update_manager_state)(wakeup_manager_state_e state);
58 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_RECOGNITION_RESULT "wakeup_engine_update_recognition_result"
59 typedef int (*wakeup_engine_update_recognition_result)(const char* appid, int result);
60 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_FORMAT "wakeup_engine_set_audio_format"
61 typedef int (*wakeup_engine_set_audio_format)(int rate, int channel, int audio_type);
62 #define MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT "wakeup_engine_get_audio_format"
63 typedef int (*wakeup_engine_get_audio_format)(int* rate, int* channel, int* audio_type);
64 #define MA_WAKEUP_ENGINE_FUNC_FEED_AUDIO_DATA "wakeup_engine_feed_audio_data"
65 typedef int (*wakeup_engine_feed_audio_data)(long time, void* data, int len);
66 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT "wakeup_engine_get_utterance_data_count"
67 typedef int (*wakeup_engine_get_utterance_data_count)(void);
68 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA "wakeup_engine_get_utterance_data"
69 typedef int (*wakeup_engine_get_utterance_data)(int index, wakeup_speech_data *data);
70 #define MA_WAKEUP_ENGINE_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_engine_set_assistant_specific_command"
71 typedef int (*wakeup_engine_set_assistant_specific_command)(const char* appid, const char* command);
72 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_engine_set_wakeup_event_callback"
73 typedef int (*wakeup_engine_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
74 #define MA_WAKEUP_ENGINE_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_engine_set_speech_status_callback"
75 typedef int (*wakeup_engine_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
76 #define MA_WAKEUP_ENGINE_FUNC_SET_ERROR_CALLBACK "wakeup_engine_set_error_callback"
77 typedef int (*wakeup_engine_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
78 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_DATA_REQUIRE_STATUS_CALLBACK "wakeup_engine_set_audio_data_require_status_callback"
79 typedef int (*wakeup_engine_set_audio_data_require_status_callback)(wakeup_service_audio_data_require_status_cb callback, void* user_data);
82 wakeup_engine_initialize initialize;
83 wakeup_engine_deinitialize deinitialize;
84 wakeup_engine_activate activate;
85 wakeup_engine_deactivate deactivate;
86 wakeup_engine_add_wakeup_word add_wakeup_word;
87 wakeup_engine_add_language add_language;
88 wakeup_engine_set_language set_language;
89 wakeup_engine_update_manager_state update_manager_state;
90 wakeup_engine_update_recognition_result update_recognition_result;
91 wakeup_engine_set_audio_format set_audio_format;
92 wakeup_engine_get_audio_format get_audio_format;
93 wakeup_engine_feed_audio_data feed_audio_data;
94 wakeup_engine_get_utterance_data_count get_utterance_data_count;
95 wakeup_engine_get_utterance_data get_utterance_data;
96 wakeup_engine_set_assistant_specific_command set_assistant_specific_command;
97 wakeup_engine_set_wakeup_event_callback set_wakeup_event_callback;
98 wakeup_engine_set_speech_status_callback set_speech_status_callback;
99 wakeup_engine_set_error_callback set_error_callback;
100 wakeup_engine_set_audio_data_require_status_callback set_audio_data_require_status_callback;
101 } wakeup_engine_interface;
103 class IEngineEventObserver
106 virtual ~IEngineEventObserver() = default;
107 virtual bool on_wakeup_event(string engine_name, wakeup_event_info wakeup_info) = 0;
108 virtual bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) = 0;
109 virtual bool on_error(string engine_name, int error_code, string error_message) = 0;
110 virtual bool on_audio_data_require_status(string engine_name, bool require) = 0;
112 virtual bool on_streaming_audio_data(
113 wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
116 class CWakeupEngineManager
119 CWakeupEngineManager();
120 CWakeupEngineManager(IEngineEventObserver *observer);
121 virtual ~CWakeupEngineManager();
123 CWakeupEngineManager(const CWakeupEngineManager&) = delete;
124 CWakeupEngineManager& operator=(const CWakeupEngineManager&) = delete;
129 void subscribe(IEngineEventObserver *observer);
130 void unsubscribe(IEngineEventObserver *observer);
132 bool get_audio_data_required();
133 void set_selected_wakeup_info(wakeup_event_info wakeup_info);
135 bool set_language(string language);
136 void set_assistant_activated(string appid, bool activated);
138 void start_streaming_current_utterance_data();
139 void stop_streaming_current_utterance_data();
141 void update_manager_state(wakeup_manager_state_e state);
142 void update_recognition_result(string appid, int result);
144 void engine_add_target_assistant(string engine_name, string appid);
145 void engine_add_wakeup_word(string appid, string wakeup_word, string language);
146 void engine_set_assistant_specific_command(string appid, string command);
147 void engine_feed_audio_data(long time, void* data, int len);
149 bool on_wakeup_event(string engine_name, wakeup_event_info wakeup_info);
150 bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
151 bool on_error(string engine_name, int error_code, string error_message);
152 bool on_audio_data_require_status(string engine_name, bool require);
156 bool activated{false};
157 bool audio_data_require_status{false};
159 wakeup_engine_interface interface{nullptr, };
160 vector<string> assistant_list;
161 set<string> activated_assistants;
162 void *engine_handle{nullptr};
165 void add_engine_directory(string name, string path);
166 void add_engine(string name, string path);
168 vector<IEngineEventObserver*> mObservers;
170 void streaming_speech_data_thread_func();
172 vector<EngineInfo> mEngineInfo;
173 const EngineInfo* mSelectedEngine{nullptr};
174 bool mAudioDataRequired{false};
176 thread mStreamingThread;
177 atomic_bool mStopStreamingThread{false};
183 #endif /* _WAKEUP_ENGINE_MANAGER_H_ */