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.
18 #ifndef _WAKEUP_MANAGER_H_
19 #define _WAKEUP_MANAGER_H_
21 #include "wakeup_manager_wrapper.h"
22 #include "wakeup_settings.h"
23 #include "wakeup_engine_manager.h"
24 #include "wakeup_audio_manager.h"
25 #include "wakeup_policy_default.h"
30 namespace multiassistant
37 enum class STREAMING_MODE {
44 class IWakeupEventObserver {
46 virtual ~IWakeupEventObserver() = default;
47 virtual void on_wakeup(mas_wakeup_event_info wakeup_info) = 0;
48 virtual void on_streaming_audio_data(
49 mas_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
50 virtual void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
51 virtual void on_wakeup_engine_command(
52 mas_wakeup_engine_command_target_e target, const char* name, const char* command) = 0;
55 class ISettingValueObserver {
57 virtual ~ISettingValueObserver() = default;
58 virtual void on_value_changed() = 0;
61 /* If a wakeup event is raised by pressing a voice key,
62 the wakeup_engine attribute of wakeup_event_info will have the following value */
63 #define WAKEUP_ENGINE_VOICE_KEY "voice_key"
68 CWakeupManager(IWakeupEventObserver* wakeup_observer, ISettingValueObserver* setting_observer);
69 virtual ~CWakeupManager();
71 CWakeupManager(const CWakeupManager&) = delete;
72 CWakeupManager& operator=(const CWakeupManager&) = delete;
77 void subscribe_wakeup_observer(IWakeupEventObserver* observer);
78 void unsubscribe_wakeup_observer(IWakeupEventObserver* observer);
80 void subscribe_setting_observer(ISettingValueObserver* observer);
81 void unsubscribe_setting_observer(ISettingValueObserver* observer);
86 bool add_assistant_language(string appid, string language);
87 bool add_assistant_wakeup_word(string appid, string wakeup_word, string language);
88 bool set_assistant_wakeup_engine(string appid, string engine);
89 bool set_assistant_language(string appid, string language);
91 bool set_assistant_enabled(string appid, bool enabled);
92 bool get_assistant_enabled(string appid);
93 bool set_default_assistant(string appid);
94 string get_default_assistant();
96 bool update_voice_feedback_state(string appid, bool state);
97 bool send_assistant_specific_command(string appid, string command);
98 bool set_background_volume(string appid, double ratio);
99 bool update_recognition_result(string appid, int result);
100 bool process_event(mas_plugin_event_e event, void* data, int len);
101 bool get_audio_format(int* rate, int* channel, int* audio_type);
102 bool get_audio_source_type(char** type);
103 bool set_language(string language);
104 bool get_voice_key_pressed();
105 bool set_wake_word_audio_require_flag(bool require);
107 STREAMING_MODE get_streaming_mode();
108 bool set_streaming_mode(STREAMING_MODE mode);
110 bool start_streaming_utterance_data();
111 bool stop_streaming_utterance_data();
112 bool start_streaming_follow_up_data();
113 bool stop_streaming_follow_up_data();
114 bool start_streaming_previous_utterance_data();
115 bool stop_streaming_previous_utterance_data();
117 CWakeupPolicy* get_wakeup_policy();
118 CWakeupEngineManager* get_engine_manager();
119 CAudioManager* get_audio_manager();
120 CWakeupSettings* get_wakeup_settings();
122 vector<IWakeupEventObserver*> get_wakeup_observers();
123 void set_last_wakeup_event_info(mas_wakeup_event_info wakeup_info);
125 vector<ISettingValueObserver*> get_setting_observers();
127 bool change_manager_state(wakeup_manager_state_e state);
128 wakeup_manager_state_e get_manager_state();
130 void feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len);
131 void send_dependency_module_command(string engine_name, string command);
133 class CEngineEventObserver : public IEngineEventObserver
136 bool on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info) override;
137 bool on_speech_status(string engine_name, mas_speech_status_e status) override;
138 bool on_error(string engine_name, int error_code, string error_message) override;
139 bool on_audio_data_require_status(string engine_name, bool require) override;
141 bool on_streaming_audio_data(
142 mas_speech_streaming_event_e event, void* buffer, unsigned int len) override;
143 bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
144 bool on_wakeup_engine_command(
145 mas_wakeup_engine_command_target_e target, string engine, string name, string command) override;
147 void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
149 CWakeupManager *mWakeupManager{nullptr};
152 class CPolicyEventObserver : public IPolicyEventObserver
155 void on_wakeup(mas_wakeup_event_info wakeup_info) override;
157 void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
159 CWakeupManager *mWakeupManager{nullptr};
162 class CAudioEventObserver : public IAudioEventObserver
165 bool on_recording_audio_data(long time, void* data, int len) override;
166 bool on_streaming_audio_data(
167 mas_speech_streaming_event_e event, void* buffer, unsigned int len) override;
169 void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
170 void set_wakeup_engine_manager(CWakeupEngineManager *manager) { mEngineManager = manager; }
172 CWakeupManager *mWakeupManager{nullptr};
173 CWakeupEngineManager *mEngineManager{nullptr};
176 class CSettingsEventObserver : public ISettingsEventObserver
179 bool on_voice_input_language_changed(const char* language) override;
180 bool on_assistant_enabled_info_changed(const char* appid, bool enabled) override;
181 bool on_default_assistant_appid_changed(const char* appid) override;
183 void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
185 CWakeupManager *mWakeupManager{nullptr};
188 void initialize_wakeup_policy();
192 vector<string> languageList;
193 } AssistantLanguageInfo;
194 vector<AssistantLanguageInfo> mAssistantLanguageInfo;
195 map<string, bool> mAssistantSupportsCurrentLanguage;
196 map<string, bool> mAssistantEnabled;
198 vector<IWakeupEventObserver*> mWakeupObservers;
199 vector<ISettingValueObserver*> mSettingObservers;
201 unique_ptr<CWakeupPolicy> mWakeupPolicy;
203 CAudioManager mAudioManager;
204 CWakeupEngineManager mWakeupEngineManager;
205 CWakeupSettings mWakeupSettings;
207 CAudioEventObserver mAudioEventObserver;
208 CEngineEventObserver mEngineEventObserver;
209 CPolicyEventObserver mPolicyEventObserver;
210 CSettingsEventObserver mSettingsEventObserver;
212 thread mEngineDataThread;
213 atomic_bool mStopEngineDataThread{false};
215 bool mVoiceKeyPressed{false};
216 string mCurrentLanguage;
217 string mCurrentDefaultAssistant;
219 STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE};
220 Ecore_Timer* mStreamingDurationTimer{nullptr};
222 wakeup_manager_state_e mWakeupManagerState{WAKEUP_MANAGER_STATE_INACTIVE};
224 mas_wakeup_event_info mLastWakeupEventInfo;
230 #endif /* _WAKEUP_MANAGER_H_ */