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.
18 #include <service_app.h>
19 #include <app_manager.h>
30 #include "multi_wakeup_recognizer.h"
31 #include "multi_assistant_main.h"
32 #include "multi_assistant_service.h"
33 #include "multi_assistant_service_plugin.h"
34 #include "multi_assistant_dbus.h"
35 #include "multi_assistant_common.h"
37 /* Sound buf save for test */
43 static char g_temp_file_name[128] = {'\0',};
45 static FILE* g_pFile = NULL;
47 static int g_count = 1;
50 static void *g_handle = NULL;
52 static wakeup_manager_interface _wakeup_manager_interface = { NULL, };
53 static ma_plugin_settings* g_plugin_settings = NULL;
55 static bool is_ui_panel_enabled()
57 /* By default we assume the ui panel is always enabled unless explicitly turned off */
59 if (g_plugin_settings) {
60 ret = g_plugin_settings->ui_panel_enabled;
62 MAS_LOGD("UI Panel Enabled : %d", ret);
66 #if 0 /* + TEST_CODE */
67 Eina_Bool __send_asr_result(void *data)
71 if (!strcmp((char*)data, "Today's")) {
72 masc_ui_dbus_send_asr_result(-1, 1, "Today's");
74 if (!strcmp((char*)data, "weather.")) {
75 masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
82 Eina_Bool __send_result(void *data)
86 int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
88 MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
95 #endif /* -TEST_CODE */
97 Eina_Bool process_wakeup_event_by_appid_timer(char* appid)
99 MAS_LOGD("[ENTER] appid(%s)", appid);
102 if (!appid) return ECORE_CALLBACK_CANCEL;
104 bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
105 bool ui_panel_enabled = is_ui_panel_enabled();
106 if (ui_panel_enabled) masc_ui_dbus_enable_common_ui(!use_custom_ui);
108 mas_set_current_client_by_appid(appid);
109 if (ui_panel_enabled) masc_ui_dbus_change_assistant(appid);
110 if ((pid = mas_get_client_pid_by_appid(appid)) != -1) {
111 mas_client_send_preprocessing_information(pid);
112 mas_client_activate(pid);
114 // Appropriate MA Client not available, trying to launch new one
115 MAS_LOGD("MA Client with appid %s does not exist, launching client", appid);
116 mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
118 mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_WAKEUP);
120 if (appid) free(appid);
123 return ECORE_CALLBACK_CANCEL;
126 Eina_Bool process_wakeup_event_by_word_timer(char* wakeup_word)
130 if (!wakeup_word) return EINA_FALSE;
132 const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
133 process_wakeup_event_by_appid_timer(strdup(appid));
135 if (wakeup_word) free(wakeup_word);
138 return ECORE_CALLBACK_CANCEL;
141 static void __wakeup_event_cb(wakeup_event_info wakeup_info, void* user_data)
143 MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
146 if (is_ui_panel_enabled()) {
149 ret = masc_ui_dbus_send_hello();
152 MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
163 MAS_LOGD("[Recorder Info] File not found!");
167 snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count);
168 int ret = access(g_temp_file_name, 0);
171 MAS_LOGD("[Recorder ERROR] File is already exist");
172 if (0 == remove(g_temp_file_name)) {
173 MAS_LOGD("[Recorder] Remove file");
183 MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name);
186 g_pFile = fopen(g_temp_file_name, "wb+x");
188 MAS_LOGD("[Recorder ERROR] File not found!");
194 #if 0 /* + TEST_CODE */
195 if (WAKEUP_EVENT_SUCCESS == event) {
196 ecore_thread_main_loop_begin();
197 ecore_timer_add(1.0, __send_asr_result, "Today's");
198 ecore_thread_main_loop_end();
200 ecore_thread_main_loop_begin();
201 ecore_timer_add(2.0, __send_asr_result, "weather.");
202 ecore_thread_main_loop_end();
204 ecore_thread_main_loop_begin();
205 ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
206 ecore_thread_main_loop_end();
208 #endif /* - TEST_CODE */
209 if (wakeup_info.wakeup_appid) {
210 ecore_thread_main_loop_begin();
211 ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, (void*)strdup(wakeup_info.wakeup_appid));
212 ecore_thread_main_loop_end();
213 } else if (wakeup_info.wakeup_word) {
214 ecore_thread_main_loop_begin();
215 ecore_timer_add(0.0f, process_wakeup_event_by_word_timer, (void*)strdup(wakeup_info.wakeup_word));
216 ecore_thread_main_loop_end();
221 static bool __validate_streaming_event_order(int pid, wakeup_speech_streaming_event_e *event)
225 static int previous_pid = -1;
226 static wakeup_speech_streaming_event_e previous_event = WAKEUP_SPEECH_STREAMING_EVENT_FINISH;
228 if (NULL == event) return false;
230 wakeup_speech_streaming_event_e expected_sequence [][2] = {
231 {WAKEUP_SPEECH_STREAMING_EVENT_START, WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE},
232 {WAKEUP_SPEECH_STREAMING_EVENT_START, WAKEUP_SPEECH_STREAMING_EVENT_FINISH},
233 {WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE, WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE},
234 {WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE, WAKEUP_SPEECH_STREAMING_EVENT_FINISH},
235 {WAKEUP_SPEECH_STREAMING_EVENT_FINISH, WAKEUP_SPEECH_STREAMING_EVENT_START},
238 if (pid != previous_pid) {
239 /* When sending streaming event to a new client, it always sends START message first */
240 previous_event = WAKEUP_SPEECH_STREAMING_EVENT_FINISH;
243 for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
244 if (previous_event == expected_sequence[loop][0] &&
245 *event == expected_sequence[loop][1]) {
250 /* In case of FINISH -> CONTINUE without START, simply modify current event value */
251 if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
252 WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
253 *event = WAKEUP_SPEECH_STREAMING_EVENT_START;
256 MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
257 previous_event, *event, previous_pid, pid);
263 previous_event = *event;
265 MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
266 previous_event, *event, previous_pid, pid);
271 static void handle_speech_streaming_event_failure(void *data)
273 mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
276 static void __audio_streaming_cb(wakeup_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
278 if (event == WAKEUP_SPEECH_STREAMING_EVENT_FAIL) {
279 ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
282 static int count = 0;
283 if (event != WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
284 MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)", event, buffer, len);
288 int pid = mas_get_current_client_pid();
289 int preprocessing_pid = mas_get_current_preprocessing_client_pid();
291 MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
293 if (__validate_streaming_event_order(pid, &event)) {
294 int ret = masc_dbus_send_streaming_audio_data(pid, event, buffer, len);
296 MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
298 if (pid != preprocessing_pid && -1 != preprocessing_pid) {
299 int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid, event, buffer, len);
301 MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
308 /* write pcm buffer */
310 fwrite(buffer, 1, len, g_pFile);
312 if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) {
314 MAS_LOGE("[Recorder SUCCESS] File Close");
318 MAS_LOGE("[Recorder ERROR] File not found!");
324 static void __speech_status_cb(wakeup_speech_status_e status, void *user_data)
326 MAS_LOGD( "[SUCCESS] __speech_status_cb is called, status(%d)", status);
329 static void __error_cb(int error, const char* err_msg, void* user_data)
331 MAS_LOGD( "[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
333 if (is_ui_panel_enabled()) {
334 int ret = masc_ui_dbus_send_error_message(error, err_msg);
336 MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
341 static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
343 MAS_LOGD( "[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
345 int pid = mas_get_current_client_pid();
346 int ret = masc_dbus_send_streaming_section_changed(pid, (int)section);
348 MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
352 int multi_assistant_service_plugin_initialize(void)
354 MAS_LOGD( "[Enter]");
356 char filepath[512] = {'\0',};
357 const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
358 snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
362 g_handle = dlopen(filepath, RTLD_LAZY);
363 if (NULL != (error = dlerror())) {
364 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
365 return -1; //MAS_ERROR_OPERATION_FAILED;
368 _wakeup_manager_interface.initialize =
369 (wakeup_manager_initialize)dlsym(g_handle,
370 MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
371 _wakeup_manager_interface.deinitialize =
372 (wakeup_manager_deinitialize)dlsym(g_handle,
373 MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
374 _wakeup_manager_interface.get_settings =
375 (wakeup_manager_get_settings)dlsym(g_handle,
376 MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
377 _wakeup_manager_interface.add_assistant_wakeup_word =
378 (wakeup_manager_add_assistant_wakeup_word)dlsym(g_handle,
379 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
380 _wakeup_manager_interface.add_assistant_language =
381 (wakeup_manager_add_assistant_language)dlsym(g_handle,
382 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
383 _wakeup_manager_interface.set_assistant_wakeup_engine =
384 (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle,
385 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
386 _wakeup_manager_interface.set_language =
387 (wakeup_manager_set_language)dlsym(g_handle,
388 MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
389 _wakeup_manager_interface.activate =
390 (wakeup_manager_activate)dlsym(g_handle,
391 MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
392 _wakeup_manager_interface.deactivate =
393 (wakeup_manager_deactivate)dlsym(g_handle,
394 MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
395 _wakeup_manager_interface.update_voice_feedback_state =
396 (wakeup_manager_update_voice_feedback_state)dlsym(g_handle,
397 MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
398 _wakeup_manager_interface.send_assistant_specific_command =
399 (wakeup_manager_send_assistant_specific_command)dlsym(g_handle,
400 MA_WAKEUP_MANAGER_FUNC_SEND_ASSISTANT_SPECIFIC_COMMAND);
401 _wakeup_manager_interface.set_background_volume =
402 (wakeup_manager_set_background_volume)dlsym(g_handle,
403 MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
404 _wakeup_manager_interface.update_recognition_result =
405 (wakeup_manager_update_recognition_result)dlsym(g_handle,
406 MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
407 _wakeup_manager_interface.process_event =
408 (wakeup_manager_process_event)dlsym(g_handle,
409 MA_WAKEUP_MANAGER_FUNC_PROCESS_EVENT);
410 _wakeup_manager_interface.start_streaming_utterance_data =
411 (wakeup_manager_start_streaming_utterance_data)dlsym(g_handle,
412 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
413 _wakeup_manager_interface.stop_streaming_utterance_data =
414 (wakeup_manager_stop_streaming_utterance_data)dlsym(g_handle,
415 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
416 _wakeup_manager_interface.start_streaming_previous_utterance_data =
417 (wakeup_manager_start_streaming_previous_utterance_data)dlsym(g_handle,
418 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
419 _wakeup_manager_interface.stop_streaming_previous_utterance_data =
420 (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(g_handle,
421 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
422 _wakeup_manager_interface.start_streaming_follow_up_data =
423 (wakeup_manager_start_streaming_follow_up_data)dlsym(g_handle,
424 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
425 _wakeup_manager_interface.stop_streaming_follow_up_data =
426 (wakeup_manager_stop_streaming_follow_up_data)dlsym(g_handle,
427 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
428 _wakeup_manager_interface.get_audio_format =
429 (wakeup_manager_get_audio_format)dlsym(g_handle,
430 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
431 _wakeup_manager_interface.get_audio_source_type =
432 (wakeup_manager_get_audio_source_type)dlsym(g_handle,
433 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
434 _wakeup_manager_interface.set_wake_word_audio_require_flag =
435 (wakeup_manager_set_wake_word_audio_require_flag)dlsym(g_handle,
436 MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
437 _wakeup_manager_interface.set_wakeup_event_callback =
438 (wakeup_manager_set_wakeup_event_callback)dlsym(g_handle,
439 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
440 _wakeup_manager_interface.set_utterance_streaming_callback =
441 (wakeup_manager_set_utterance_streaming_callback)dlsym(g_handle,
442 MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
443 _wakeup_manager_interface.set_previous_utterance_streaming_callback =
444 (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(g_handle,
445 MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
446 _wakeup_manager_interface.set_follow_up_streaming_callback =
447 (wakeup_manager_set_follow_up_streaming_callback)dlsym(g_handle,
448 MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
449 _wakeup_manager_interface.set_speech_status_callback =
450 (wakeup_manager_set_speech_status_callback)dlsym(g_handle,
451 MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
452 _wakeup_manager_interface.set_error_callback =
453 (wakeup_manager_set_error_callback)dlsym(g_handle,
454 MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
455 _wakeup_manager_interface.set_streaming_section_changed_callback =
456 (wakeup_manager_set_streaming_section_changed_callback)dlsym(g_handle,
457 MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
460 if (NULL != g_handle) {
461 wakeup_manager_initialize func = _wakeup_manager_interface.initialize;
464 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
468 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
472 wakeup_manager_get_settings get_settings_func = _wakeup_manager_interface.get_settings;
474 if (NULL == get_settings_func) {
475 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
478 ret = get_settings_func(&g_plugin_settings, &struct_size);
479 if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
480 MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
481 g_plugin_settings = NULL;
485 MAS_LOGE("[ERROR] g_handle is not valid");
490 int multi_assistant_service_plugin_deinitialize(void)
497 MAS_LOGD("[Recorder ERROR] File not found!");
501 if (NULL != g_handle) {
502 wakeup_manager_deinitialize func = _wakeup_manager_interface.deinitialize;
504 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
508 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
515 MAS_LOGE("[ERROR] g_handle is not valid");
521 int multi_assistant_service_plugin_get_settings(ma_plugin_settings **settings, size_t *struct_size)
524 if (NULL != g_handle) {
525 wakeup_manager_get_settings func = _wakeup_manager_interface.get_settings;
527 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
529 ret = func(settings, struct_size);
531 MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
535 MAS_LOGE("[ERROR] g_handle is not valid");
540 int multi_assistant_service_plugin_set_language(const char* language)
543 if (NULL != g_handle) {
544 wakeup_manager_set_language func = _wakeup_manager_interface.set_language;
546 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
548 ret = func(language);
550 MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
554 MAS_LOGE("[ERROR] g_handle is not valid");
559 int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
562 if (NULL != g_handle) {
563 wakeup_manager_add_assistant_wakeup_word func = _wakeup_manager_interface.add_assistant_wakeup_word;
565 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
567 ret = func(appid, wakeup_word, language);
569 MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
573 MAS_LOGE("[ERROR] g_handle is not valid");
578 int multi_assistant_service_plugin_add_assistant_language(const char* appid, const char* language)
581 if (NULL != g_handle) {
582 wakeup_manager_add_assistant_language func = _wakeup_manager_interface.add_assistant_language;
584 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
586 ret = func(appid, language);
588 MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
592 MAS_LOGE("[ERROR] g_handle is not valid");
597 int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine)
600 if (NULL != g_handle) {
601 wakeup_manager_set_assistant_wakeup_engine func = _wakeup_manager_interface.set_assistant_wakeup_engine;
603 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
605 ret = func(appid, engine);
607 MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
611 MAS_LOGE("[ERROR] g_handle is not valid");
616 int multi_assistant_service_plugin_activate(void)
619 if (NULL != g_handle) {
620 wakeup_manager_activate func = _wakeup_manager_interface.activate;
622 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
626 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
630 MAS_LOGE("[ERROR] g_handle is not valid");
635 int multi_assistant_service_plugin_deactivate(void)
638 if (NULL != g_handle) {
639 wakeup_manager_deactivate func = _wakeup_manager_interface.deactivate;
641 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
645 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
649 MAS_LOGE("[ERROR] g_handle is not valid");
654 int multi_assistant_service_plugin_update_voice_feedback_state(const char* appid, int state)
657 if (NULL != g_handle) {
658 wakeup_manager_update_voice_feedback_state func = _wakeup_manager_interface.update_voice_feedback_state;
660 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
662 ret = func(appid, state);
664 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
668 MAS_LOGE("[ERROR] g_handle is not valid");
673 int multi_assistant_service_plugin_send_assistant_specific_command(const char* appid, const char* command)
676 if (NULL != g_handle) {
677 wakeup_manager_send_assistant_specific_command func = _wakeup_manager_interface.send_assistant_specific_command;
679 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SEND_ASSISTANT_SPECIFIC_COMMAND);
681 ret = func(appid, command);
683 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
687 MAS_LOGE("[ERROR] g_handle is not valid");
692 int multi_assistant_service_plugin_set_background_volume(const char* appid, double ratio)
695 if (NULL != g_handle) {
696 wakeup_manager_set_background_volume func = _wakeup_manager_interface.set_background_volume;
698 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
700 ret = func(appid, ratio);
702 MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
706 MAS_LOGE("[ERROR] g_handle is not valid");
711 int multi_assistant_service_plugin_update_recognition_result(const char* appid, int state)
714 if (NULL != g_handle) {
715 wakeup_manager_update_recognition_result func = _wakeup_manager_interface.update_recognition_result;
717 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
719 ret = func(appid, state);
721 MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
725 MAS_LOGE("[ERROR] g_handle is not valid");
730 int multi_assistant_service_plugin_process_event(int event, void *data, int len)
733 if (NULL != g_handle) {
734 wakeup_manager_process_event func = _wakeup_manager_interface.process_event;
736 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_EVENT);
738 ret = func(event, data, len);
740 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
744 MAS_LOGE("[ERROR] g_handle is not valid");
749 int multi_assistant_service_plugin_start_streaming_utterance_data(void)
752 if (NULL != g_handle) {
753 wakeup_manager_start_streaming_utterance_data func = _wakeup_manager_interface.start_streaming_utterance_data;
755 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
759 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
763 MAS_LOGE("[ERROR] g_handle is not valid");
768 int multi_assistant_service_plugin_stop_streaming_utterance_data(void)
771 if (NULL != g_handle) {
772 wakeup_manager_stop_streaming_utterance_data func = _wakeup_manager_interface.stop_streaming_utterance_data;
774 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
778 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
782 MAS_LOGE("[ERROR] g_handle is not valid");
787 int multi_assistant_service_plugin_start_streaming_previous_utterance_data(void)
790 if (NULL != g_handle) {
791 wakeup_manager_start_streaming_previous_utterance_data func = _wakeup_manager_interface.start_streaming_previous_utterance_data;
793 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
797 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
801 MAS_LOGE("[ERROR] g_handle is not valid");
806 int multi_assistant_service_plugin_stop_streaming_previous_utterance_data(void)
809 if (NULL != g_handle) {
810 wakeup_manager_stop_streaming_previous_utterance_data func = _wakeup_manager_interface.stop_streaming_previous_utterance_data;
812 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
816 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
820 MAS_LOGE("[ERROR] g_handle is not valid");
825 int multi_assistant_service_plugin_start_streaming_follow_up_data(void)
828 if (NULL != g_handle) {
829 wakeup_manager_start_streaming_follow_up_data func = _wakeup_manager_interface.start_streaming_follow_up_data;
831 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
835 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
839 MAS_LOGE("[ERROR] g_handle is not valid");
844 int multi_assistant_service_plugin_stop_streaming_follow_up_data(void)
847 if (NULL != g_handle) {
848 wakeup_manager_stop_streaming_follow_up_data func = _wakeup_manager_interface.stop_streaming_follow_up_data;
850 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
854 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
858 MAS_LOGE("[ERROR] g_handle is not valid");
863 int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type)
866 if (NULL != g_handle) {
867 wakeup_manager_get_audio_format func = _wakeup_manager_interface.get_audio_format;
869 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
871 ret = func(rate, channel, audio_type);
873 MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
877 MAS_LOGE("[ERROR] g_handle is not valid");
882 int multi_assistant_service_plugin_get_recording_audio_source_type(char** type)
885 if (NULL != g_handle) {
886 wakeup_manager_get_audio_source_type func = _wakeup_manager_interface.get_audio_source_type;
888 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
892 MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
896 MAS_LOGE("[ERROR] g_handle is not valid");
901 int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* appid, bool require)
904 if (NULL != g_handle) {
905 wakeup_manager_set_wake_word_audio_require_flag func = _wakeup_manager_interface.set_wake_word_audio_require_flag;
907 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
911 MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
915 MAS_LOGE("[ERROR] g_handle is not valid");
920 int multi_assistant_service_plugin_set_callbacks(void)
922 int ret = multi_assistant_service_plugin_set_wakeup_event_callback(__wakeup_event_cb, NULL);
924 MAS_LOGE("Fail to set wakeup event cb");
928 ret = multi_assistant_service_plugin_set_utterance_streaming_callback(__audio_streaming_cb, NULL);
930 MAS_LOGE("Fail to set utterance streaming cb");
934 ret = multi_assistant_service_plugin_set_previous_utterance_streaming_callback(__audio_streaming_cb, NULL);
936 MAS_LOGE("Fail to set previous utterance streaming cb");
940 ret = multi_assistant_service_plugin_set_follow_up_streaming_callback(__audio_streaming_cb, NULL);
942 MAS_LOGE("Fail to set follow-up streaming cb");
946 ret = multi_assistant_service_plugin_set_speech_status_callback(__speech_status_cb, NULL);
948 MAS_LOGE("Fail to set speech status changed cb");
952 ret = multi_assistant_service_plugin_set_error_callback(__error_cb, NULL);
954 MAS_LOGE("Fail to set error cb");
958 ret = multi_assistant_service_plugin_set_streaming_section_changed_callback(__streaming_section_changed_cb, NULL);
960 MAS_LOGE("Fail to set streaming section changed cb");
967 int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
970 if (NULL != g_handle) {
971 wakeup_manager_set_wakeup_event_callback func = _wakeup_manager_interface.set_wakeup_event_callback;
973 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
975 ret = func(callback, user_data);
977 MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
981 MAS_LOGE("[ERROR] g_handle is not valid");
986 int multi_assistant_service_plugin_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
989 if (NULL != g_handle) {
990 wakeup_manager_set_utterance_streaming_callback func = _wakeup_manager_interface.set_utterance_streaming_callback;
992 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
994 ret = func(callback, user_data);
996 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1000 MAS_LOGE("[ERROR] g_handle is not valid");
1005 int multi_assistant_service_plugin_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1008 if (NULL != g_handle) {
1009 wakeup_manager_set_previous_utterance_streaming_callback func = _wakeup_manager_interface.set_previous_utterance_streaming_callback;
1011 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
1013 ret = func(callback, user_data);
1015 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1019 MAS_LOGE("[ERROR] g_handle is not valid");
1024 int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1027 if (NULL != g_handle) {
1028 wakeup_manager_set_follow_up_streaming_callback func = _wakeup_manager_interface.set_follow_up_streaming_callback;
1030 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
1032 ret = func(callback, user_data);
1034 MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
1038 MAS_LOGE("[ERROR] g_handle is not valid");
1043 int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
1046 if (NULL != g_handle) {
1047 wakeup_manager_set_speech_status_callback func = _wakeup_manager_interface.set_speech_status_callback;
1049 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
1051 ret = func(callback, user_data);
1053 MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
1060 int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data)
1063 if (NULL != g_handle) {
1064 wakeup_manager_set_error_callback func = _wakeup_manager_interface.set_error_callback;
1066 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
1068 ret = func(callback, user_data);
1070 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1077 int multi_assistant_service_plugin_set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
1080 if (NULL != g_handle) {
1081 wakeup_manager_set_streaming_section_changed_callback func = _wakeup_manager_interface.set_streaming_section_changed_callback;
1083 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
1085 ret = func(callback, user_data);
1087 MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);