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.h"
27 namespace multiassistant
34 /**************************************************************************************
35 *** Definitions for wakeup engine interface
36 *************************************************************************************/
37 #define MA_WAKEUP_ENGINE_PATH tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "multiassistant/engines")
38 /* Need to check whether this dedicated engine path also needs to be configurable */
39 #define MA_WAKEUP_DEDICATED_ENGINE_PATH "shared/lib/libwakeup-engine.so"
41 #define MA_WAKEUP_ENGINE_FUNC_INITIALIZE "wakeup_engine_initialize"
42 typedef int (*wakeup_engine_initialize)(void);
43 #define MA_WAKEUP_ENGINE_FUNC_DEINITIALIZE "wakeup_engine_deinitialize"
44 typedef int (*wakeup_engine_deinitialize)(void);
45 #define MA_WAKEUP_ENGINE_FUNC_ACTIVATE "wakeup_engine_activate"
46 typedef int (*wakeup_engine_activate)(void);
47 #define MA_WAKEUP_ENGINE_FUNC_DEACTIVATE "wakeup_engine_deactivate"
48 typedef int (*wakeup_engine_deactivate)(void);
49 #define MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD "wakeup_engine_add_wakeup_word"
50 typedef int (*wakeup_engine_add_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
51 #define MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE "wakeup_engine_add_language"
52 typedef int (*wakeup_engine_add_language)(const char* appid, const char* language);
53 #define MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE "wakeup_engine_set_language"
54 typedef int (*wakeup_engine_set_language)(const char* language);
55 #define MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE "wakeup_engine_update_manager_state"
56 typedef int (*wakeup_engine_update_manager_state)(wakeup_manager_state_e state);
57 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_FORMAT "wakeup_engine_set_audio_format"
58 typedef int (*wakeup_engine_set_audio_format)(int rate, int channel, int audio_type);
59 #define MA_WAKEUP_ENGINE_FUNC_GET_AUDIO_FORMAT "wakeup_engine_get_audio_format"
60 typedef int (*wakeup_engine_get_audio_format)(int* rate, int* channel, int* audio_type);
61 #define MA_WAKEUP_ENGINE_FUNC_FEED_AUDIO_DATA "wakeup_engine_feed_audio_data"
62 typedef int (*wakeup_engine_feed_audio_data)(long time, void* data, int len);
63 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA_COUNT "wakeup_engine_get_utterance_data_count"
64 typedef int (*wakeup_engine_get_utterance_data_count)(void);
65 #define MA_WAKEUP_ENGINE_FUNC_GET_UTTERANCE_DATA "wakeup_engine_get_utterance_data"
66 typedef int (*wakeup_engine_get_utterance_data)(int index, wakeup_speech_data *data);
67 #define MA_WAKEUP_ENGINE_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_engine_set_assistant_specific_command"
68 typedef int (*wakeup_engine_set_assistant_specific_command)(const char* appid, const char* command);
69 #define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_engine_set_wakeup_event_callback"
70 typedef int (*wakeup_engine_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
71 #define MA_WAKEUP_ENGINE_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_engine_set_speech_status_callback"
72 typedef int (*wakeup_engine_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
73 #define MA_WAKEUP_ENGINE_FUNC_SET_ERROR_CALLBACK "wakeup_engine_set_error_callback"
74 typedef int (*wakeup_engine_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
75 #define MA_WAKEUP_ENGINE_FUNC_SET_AUDIO_DATA_REQUIRE_STATUS_CALLBACK "wakeup_engine_set_audio_data_require_status_callback"
76 typedef int (*wakeup_engine_set_audio_data_require_status_callback)(wakeup_service_audio_data_require_status_cb callback, void* user_data);
79 wakeup_engine_initialize initialize;
80 wakeup_engine_deinitialize deinitialize;
81 wakeup_engine_activate activate;
82 wakeup_engine_deactivate deactivate;
83 wakeup_engine_add_wakeup_word add_wakeup_word;
84 wakeup_engine_add_language add_language;
85 wakeup_engine_set_language set_language;
86 wakeup_engine_update_manager_state update_manager_state;
87 wakeup_engine_set_audio_format set_audio_format;
88 wakeup_engine_get_audio_format get_audio_format;
89 wakeup_engine_feed_audio_data feed_audio_data;
90 wakeup_engine_get_utterance_data_count get_utterance_data_count;
91 wakeup_engine_get_utterance_data get_utterance_data;
92 wakeup_engine_set_assistant_specific_command set_assistant_specific_command;
93 wakeup_engine_set_wakeup_event_callback set_wakeup_event_callback;
94 wakeup_engine_set_speech_status_callback set_speech_status_callback;
95 wakeup_engine_set_error_callback set_error_callback;
96 wakeup_engine_set_audio_data_require_status_callback set_audio_data_require_status_callback;
97 } wakeup_engine_interface;
99 class IEngineEventObserver
102 virtual ~IEngineEventObserver() {}
103 virtual bool on_wakeup_event(string engine_name, wakeup_event_info info) = 0;
104 virtual bool on_speech_status(string engine_name, wakeup_service_speech_status_e status) = 0;
105 virtual bool on_error(string engine_name, int error_code, string error_message) = 0;
106 virtual bool on_audio_data_require_status(string engine_name, bool require) = 0;
108 virtual bool on_streaming_audio_data(
109 wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
112 class CWakeupEngineManager
115 CWakeupEngineManager();
116 virtual ~CWakeupEngineManager();
118 CWakeupEngineManager(const CWakeupEngineManager&) = delete;
119 CWakeupEngineManager& operator=(const CWakeupEngineManager&) = delete;
124 void subscribe(IEngineEventObserver *observer);
125 void unsubscribe(IEngineEventObserver *observer);
127 bool get_audio_data_required();
128 void set_selected_wakeup_info(wakeup_event_info info);
130 void start_streaming_current_utterance_data();
131 void stop_streaming_current_utterance_data();
133 void update_manager_state(wakeup_manager_state_e state);
135 void engine_add_target_assistant(const string engine_name, const string appid);
136 void engine_add_wakeup_word(const string appid, const string wakeup_word, const string language);
137 void engine_set_assistant_specific_command(const string appid, const string command);
138 void engine_feed_audio_data(long time, void* data, int len);
140 bool on_wakeup_event(string engine_name, wakeup_event_info info);
141 bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
142 bool on_error(string engine_name, int error_code, string error_message);
143 bool on_audio_data_require_status(string engine_name, bool require);
149 bool audio_data_require_status{false};
151 wakeup_engine_interface interface{nullptr, };
152 vector<string> assistant_list;
153 void *engine_handle{nullptr};
156 void add_engine_directory(const string name, const string path);
157 void add_engine(const string name, const string path);
159 vector<IEngineEventObserver*> mObservers;
161 void streaming_speech_data_thread_func();
163 vector<EngineInfo> mEngineInfo;
164 const EngineInfo* mSelectedEngine{nullptr};
165 bool mAudioDataRequired{false};
167 thread mStreamingThread;
168 atomic_bool mStopStreamingThread{false};
174 #endif /* _WAKEUP_ENGINE_MANAGER_H_ */