From: Ji-hoon Lee Date: Fri, 7 Feb 2020 04:35:42 +0000 (+0900) Subject: Add APIs for adding/removing wake words X-Git-Tag: submit/tizen/20200408.110745^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9492d63128c0da100d377a292293be0bf2b73dc;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add APIs for adding/removing wake words Change-Id: Ia801deacb430d5430db811f9950e31e34be4f12c --- diff --git a/client/ma.c b/client/ma.c index 194850b..cd4a949 100644 --- a/client/ma.c +++ b/client/ma.c @@ -2294,4 +2294,82 @@ int ma_unset_voice_key_status_changed_cb(void) return MA_ERROR_NONE; } +int ma_add_wake_word(const char* wake_word, const char *language) { + MA_SLOGD("[Manager] Add wake word"); + + if (0 != __ma_get_feature_enabled()) { + MA_SLOGD("@@@ [Manager] not supported"); + return MA_ERROR_NOT_SUPPORTED; + } + + if (NULL == wake_word || NULL == language) { + MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_PARAMETER; + } + + ma_state_e state; + if (0 != ma_client_get_client_state(g_ma, &state)) { + MA_SLOGE("[ERROR] A handle is not available"); + MA_SLOGD("@@@"); + return MA_ERROR_INVALID_STATE; + } + + if (state != MA_STATE_READY) { + MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); + MA_SLOGD("@@@"); + return MA_ERROR_INVALID_STATE; + } + + MA_SLOGI("[Client DEBUG] Add wake word : %s %s", wake_word, language); + + /* Add wake word */ + int pid = getpid(); + int ret = ma_dbus_add_wake_word(pid, wake_word, language); + if (0 != ret) { + MA_SLOGW("[WARNING] Failed to add wake word"); + } else { + MA_SLOGD("[DEBUG] Success to add"); + } + return ret; +} + +int ma_remove_wake_word(const char* wake_word, const char *language) { + MA_SLOGD("[Manager] Remove wake word"); + + if (0 != __ma_get_feature_enabled()) { + MA_SLOGD("@@@ [Manager] not supported"); + return MA_ERROR_NOT_SUPPORTED; + } + + if (NULL == wake_word || NULL == language) { + MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_PARAMETER; + } + + ma_state_e state; + if (0 != ma_client_get_client_state(g_ma, &state)) { + MA_SLOGE("[ERROR] A handle is not available"); + MA_SLOGD("@@@"); + return MA_ERROR_INVALID_STATE; + } + + if (state != MA_STATE_READY) { + MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); + MA_SLOGD("@@@"); + return MA_ERROR_INVALID_STATE; + } + + MA_SLOGI("[Client DEBUG] Remove wake word : %s %s", wake_word, language); + + /* Remove wake word */ + int pid = getpid(); + int ret = ma_dbus_remove_wake_word(pid, wake_word, language); + if (0 != ret) { + MA_SLOGW("[WARNING] Failed to remove wake word"); + } else { + MA_SLOGD("[DEBUG] Success to remove"); + } + return ret; +} + //LCOV_EXCL_STOP diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 0399c52..3163676 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -1642,3 +1642,163 @@ int ma_dbus_set_assistant_wakeup_language(int pid, const char* language) return 0; } + +int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language) +{ + if (0 != __dbus_check()) { + return MA_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_SERVER_SERVICE_NAME, + MA_SERVER_SERVICE_OBJECT_PATH, + MA_SERVER_SERVICE_INTERFACE, + MA_METHOD_ADD_WAKE_WORD); + + if (NULL == msg) { + MA_SLOGE("@@ Request multi-assistant add wake word : Fail to make message"); //LCOV_EXCL_LINE + return MA_ERROR_OPERATION_FAILED; + } else { + MA_SLOGD("[DEBUG] multi-assistant add wake word"); + } + + char* tmp_wake_word = NULL; + if (NULL != wake_word) { + tmp_wake_word = strdup(wake_word); + } else { + tmp_wake_word = strdup("#NULL"); + } + + char* tmp_language = NULL; + if (NULL != language) { + tmp_language = strdup(language); + } else { + tmp_language = strdup("#NULL"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &tmp_wake_word, + DBUS_TYPE_STRING, &tmp_language, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + DBusError error; + dbus_error_init (&error); + if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + if (dbus_error_is_set (&error)) { + MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE + dbus_error_free (&error); + } else { + MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE + } + if (NULL != tmp_wake_word) { + free(tmp_wake_word); + tmp_wake_word = NULL; + } + if (NULL != tmp_language) { + free(tmp_language); + tmp_language = NULL; + } + return MA_ERROR_OPERATION_FAILED; + } else { + MA_SLOGD("[Dbus DEBUG] Success to Send"); + dbus_connection_flush(g_conn_sender); + } + + if (NULL != tmp_wake_word) { + free(tmp_wake_word); + tmp_wake_word = NULL; + } + if (NULL != tmp_language) { + free(tmp_language); + tmp_language = NULL; + } + + dbus_message_unref(msg); + + return 0; +} + +int ma_dbus_remove_wake_word(int pid, const char* wake_word, const char* language) +{ + if (0 != __dbus_check()) { + return MA_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_SERVER_SERVICE_NAME, + MA_SERVER_SERVICE_OBJECT_PATH, + MA_SERVER_SERVICE_INTERFACE, + MA_METHOD_REMOVE_WAKE_WORD); + + if (NULL == msg) { + MA_SLOGE("@@ Request multi-assistant remove wake word : Fail to make message"); //LCOV_EXCL_LINE + return MA_ERROR_OPERATION_FAILED; + } else { + MA_SLOGD("[DEBUG] multi-assistant remove wake word"); + } + + char* tmp_wake_word = NULL; + if (NULL != wake_word) { + tmp_wake_word = strdup(wake_word); + } else { + tmp_wake_word = strdup("#NULL"); + } + + char* tmp_language = NULL; + if (NULL != language) { + tmp_language = strdup(language); + } else { + tmp_language = strdup("#NULL"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &tmp_wake_word, + DBUS_TYPE_STRING, &tmp_language, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + DBusError error; + dbus_error_init (&error); + if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + if (dbus_error_is_set (&error)) { + MA_SLOGE("[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE + dbus_error_free (&error); + } else { + MA_SLOGE("[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE + } + if (NULL != tmp_wake_word) { + free(tmp_wake_word); + tmp_wake_word = NULL; + } + if (NULL != tmp_language) { + free(tmp_language); + tmp_language = NULL; + } + return MA_ERROR_OPERATION_FAILED; + } else { + MA_SLOGD("[Dbus DEBUG] Success to Send"); + dbus_connection_flush(g_conn_sender); + } + + if (NULL != tmp_wake_word) { + free(tmp_wake_word); + tmp_wake_word = NULL; + } + if (NULL != tmp_language) { + free(tmp_language); + tmp_language = NULL; + } + + dbus_message_unref(msg); + + return 0; +} \ No newline at end of file diff --git a/client/ma_dbus.h b/client/ma_dbus.h index f74a1b5..c40c4f0 100644 --- a/client/ma_dbus.h +++ b/client/ma_dbus.h @@ -65,6 +65,10 @@ int ma_dbus_set_wake_word_audio_require_flag(int pid, bool require); int ma_dbus_set_assistant_wakeup_language(int pid, const char* language); +int ma_dbus_add_wake_word(int pid, const char* wake_word, const char* language); + +int ma_dbus_remove_wake_word(int pid, const char* wake_word, const char* language); + #ifdef __cplusplus } #endif diff --git a/common/ma_defs.h b/common/ma_defs.h index c646763..41b586d 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -82,6 +82,8 @@ extern "C" #define MA_METHOD_SEND_PREPROCESSING_RESULT "ma_method_send_preprocessing_result" #define MA_METHOD_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG "ma_method_set_wake_word_audio_require_flag" #define MA_METHOD_SET_ASSISTANT_WAKEUP_LANGUAGE "ma_method_set_assistant_wakeup_language" +#define MA_METHOD_ADD_WAKE_WORD "ma_method_add_wake_word" +#define MA_METHOD_REMOVE_WAKE_WORD "ma_method_remove_wake_word" #define MA_METHOD_ERROR "ma_method_error" #define MA_UI_METHOD_INITIALIZE "ma_ui_method_initialize" diff --git a/include/multi_assistant.h b/include/multi_assistant.h index 5bf251f..38a7646 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -783,6 +783,56 @@ int ma_set_voice_key_status_changed_cb(ma_voice_key_status_changed_cb callback, */ int ma_unset_voice_key_status_changed_cb(void); +/** + * @brief Adds a wake word used for activating assistant. + * @details Different pairs identify a different word. + * For example, <"Hi Tizen", "en_US"> and <"Hi Tizen", "en_GB"> + * are different words. If <"Hi Tizen", "en_US"> is added, then + * "Hi Tizen" will not wake the Tizen voice assistant if the + * wakeup language is set to "en_GB". <"Hi Tizen", "en_GB"> will + * have to be added for that.\n + * Adding the same word twice does not cause any error to be returned. + * @since_tizen 6.0 + * + * @param[in] wake_word The wake word to be added to the list of wake words + * @param[in] language The language code for which the word will be added. + * The language is identified by its code (e.g. "en_US"). + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MA_ERROR_NONE Successful + * @retval #MA_ERROR_NOT_SUPPORTED Not supported + * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MA_ERROR_INVALID_STATE Invalid state + * @retval #MA_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state should be #MA_STATE_READY. + */ +int ma_add_wake_word(const char* wake_word, const char *language); + +/** + * @brief Removes a wake word used for activating assistant. + * @details Different pairs identify a different word. + * For example, <"Hi Tizen", "en_US"> and <"Hi Tizen", "en_GB"> + * are different words.\n + * Removing a word not present on the list does not cause any error + * to be returned. + * @since_tizen 6.0 + * + * @param[in] wake_word The wake word to be removed from the list of wake words + * @param[in] language The language code for which the word will be removed. + * The language is identified by its code (e.g. "en_US"). + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MA_ERROR_NONE Successful + * @retval #MA_ERROR_NOT_SUPPORTED Not supported + * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MA_ERROR_INVALID_STATE Invalid state + * @retval #MA_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state should be #MA_STATE_READY. + */ +int ma_remove_wake_word(const char* wake_word, const char *language); + #ifdef __cplusplus } #endif