[ACR-1449] Add new api to set audio type 01/213401/9 accepted/tizen/unified/20190923.011238 submit/tizen/20190918.020339 submit/tizen/20190920.110113 submit/tizen/20190920.151549
authorwn.jang <wn.jang@samsung.com>
Thu, 5 Sep 2019 04:18:26 +0000 (13:18 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Wed, 18 Sep 2019 02:01:40 +0000 (02:01 +0000)
Change-Id: I447e56b41af16cfa116ce07dbb4f3afb33a61aea

common/stt_engine.c
common/stt_engine.h
include/stte.h
server/sttd_engine_agent.c
server/sttd_engine_agent.h
server/sttd_recorder.c
server/stte.c

index 57944a2..532381d 100644 (file)
@@ -41,6 +41,8 @@ static bool g_is_from_lib = false;
 static stt_engine_result_cb g_result_cb = NULL;
 static stte_private_data_set_cb g_set_private_data_cb = NULL;
 static stte_private_data_requested_cb g_get_private_data_cb = NULL;
 static stt_engine_result_cb g_result_cb = NULL;
 static stte_private_data_set_cb g_set_private_data_cb = NULL;
 static stte_private_data_requested_cb g_get_private_data_cb = NULL;
+static stte_audio_type_cb g_set_audio_type_cb = NULL;
+static void* g_set_audio_type_user_data = NULL;
 
 
 static int __stt_set_engine_from(bool is_from_lib)
 
 
 static int __stt_set_engine_from(bool is_from_lib)
@@ -472,7 +474,7 @@ int stt_engine_support_recognition_type(const char* type, bool* support)
        return ret;
 }
 
        return ret;
 }
 
-int stt_engine_get_audio_type(stte_audio_type_e* types, int* rate, int* channels)
+int stt_engine_get_audio_format(stte_audio_type_e* types, int* rate, int* channels)
 {
        if (NULL == types || NULL == rate || NULL == channels) {
                SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
 {
        if (NULL == types || NULL == rate || NULL == channels) {
                SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
@@ -844,3 +846,38 @@ int stt_engine_set_private_data_requested_cb(stte_private_data_requested_cb priv
 
        return 0;
 }
 
        return 0;
 }
+
+int stt_engine_set_audio_type(const char* audio_type)
+{
+       if (NULL == audio_type) {
+               SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+               return STTE_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_INFO, stt_tag(), "[Engine Info] set audio type (%s)", audio_type);
+
+       int ret = STTE_ERROR_NONE;
+       if (NULL != g_set_audio_type_cb) {
+               ret = g_set_audio_type_cb(audio_type, g_set_audio_type_user_data);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set audio type, ret(%d)", ret);
+               }
+       } else {
+               SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] There's no set audio function)");
+       }
+
+       return ret;
+}
+
+int stt_engine_set_audio_type_set_cb(stte_audio_type_cb audio_type_set_cb, void* user_data)
+{
+       if (NULL == audio_type_set_cb) {
+               SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+               return STTE_ERROR_INVALID_PARAMETER;
+       }
+
+       g_set_audio_type_cb = audio_type_set_cb;
+       g_set_audio_type_user_data = user_data;
+
+       return 0;
+}
\ No newline at end of file
index f8b1a08..b345aed 100644 (file)
@@ -61,7 +61,7 @@ int stt_engine_need_app_credential(bool* need);
 
 int stt_engine_support_recognition_type(const char* type, bool* support);
 
 
 int stt_engine_support_recognition_type(const char* type, bool* support);
 
-int stt_engine_get_audio_type(stte_audio_type_e* types, int* rate, int* channels);
+int stt_engine_get_audio_format(stte_audio_type_e* types, int* rate, int* channels);
 
 /* Set option */
 int stt_engine_set_silence_detection(bool value);
 
 /* Set option */
 int stt_engine_set_silence_detection(bool value);
@@ -100,6 +100,9 @@ int stt_engine_set_private_data_set_cb(stte_private_data_set_cb private_data_set
 
 int stt_engine_set_private_data_requested_cb(stte_private_data_requested_cb private_data_requested_cb, void* user_data);
 
 
 int stt_engine_set_private_data_requested_cb(stte_private_data_requested_cb private_data_requested_cb, void* user_data);
 
+int stt_engine_set_audio_type(const char* audio_type);
+
+int stt_engine_set_audio_type_set_cb(stte_audio_type_cb audio_type_set_cb, void* user_data);
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
index c4f0c7a..655aebb 100755 (executable)
@@ -156,6 +156,20 @@ typedef enum {
 
 
 /**
 
 
 /**
+ * @brief Definition of audio ID that means audio source from bluetooth.
+ * @since_tizen 5.5
+ */
+#define STTE_AUDIO_ID_BLUETOOTH                "STT_AUDIO_ID_BLUETOOTH"
+
+
+/**
+ * @brief Definition of audio ID that means audio source from wifi.
+ * @since_tizen 5.5
+ */
+#define STTE_AUDIO_ID_WIFI             "STT_AUDIO_ID_WIFI"
+
+
+/**
 * @brief Called when STT engine provides the time stamp of result to the engine service user.
 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
 * @since_tizen 3.0
 * @brief Called when STT engine provides the time stamp of result to the engine service user.
 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
 * @since_tizen 3.0
@@ -528,6 +542,20 @@ typedef int (*stte_private_data_requested_cb)(const char* key, char** data);
 
 
 /**
 
 
 /**
+ * @brief Called when the engine service user sets audio recording type.
+ * @since_tizen 5.5
+ * @remarks The @a audio_type can be used only in the callback. To use outside, make a copy.
+ * @param[in] audio_type Current audio type (e.g. #STTE_AUDIO_ID_BLUETOOTH or #STTE_AUDIO_ID_WIFI)
+ * @param[in] user_data user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #VCE_ERROR_NONE Successful.
+ * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+ */
+typedef int (*stte_audio_type_cb)(const char* audio_type, void* user_data);
+
+
+/**
 * @brief A structure for the STT engine functions.
 * @details This structure contains essential callback functions for operating STT engine.
 * @since_tizen 3.0
 * @brief A structure for the STT engine functions.
 * @details This structure contains essential callback functions for operating STT engine.
 * @since_tizen 3.0
@@ -787,6 +815,39 @@ int stte_set_private_data_set_cb(stte_private_data_set_cb callback_func);
 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback_func);
 
 
 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback_func);
 
 
+/**
+* @brief Sets a callback function for setting the audio type.
+* @since_tizen 5.5
+* @remarks The stte_audio_type_cb() function is called when STT framework sets audio type to the STT engine.
+* @param[in] callback_func stte_audio_type_set event callback function
+* @param[in] user_data The user data passed to the callback function
+* @return @c 0 on success,
+*         otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+* @pre The stte_main() function should be invoked before this function is called.
+* @see stte_audio_type_cb()
+* @see stte_unset_audio_type_set_cb()
+*/
+int stte_set_audio_type_set_cb(stte_audio_type_cb callback_func, void* user_data);
+
+
+/**
+* @brief Unsets a callback function for setting the audio type.
+* @since_tizen 5.5
+* @return @c 0 on success,
+*         otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+* @pre The stte_main() function should be invoked before this function is called.
+* @see stte_set_audio_type_set_cb()
+*/
+int stte_unset_audio_type_set_cb(void);
+
+
 #ifdef __cplusplus
 }
 #endif
 #ifdef __cplusplus
 }
 #endif
index 9b68876..f6a7ac0 100644 (file)
@@ -361,7 +361,7 @@ int sttd_engine_agent_load_current_engine(stte_request_callback_s *callback)
        int rate;
        int channels;
 
        int rate;
        int channels;
 
-       ret = stt_engine_get_audio_type(&atype, &rate, &channels);
+       ret = stt_engine_get_audio_format(&atype, &rate, &channels);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", g_engine_info->engine_name);
                return ret;
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", g_engine_info->engine_name);
                return ret;
@@ -789,9 +789,9 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
        int rate;
        int channels;
 
        int rate;
        int channels;
 
-       ret = stt_engine_get_audio_type(&atype, &rate, &channels);
+       ret = stt_engine_get_audio_format(&atype, &rate, &channels);
        if (0 != ret) {
        if (0 != ret) {
-               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %s", g_engine_info->engine_name);
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio format : %s", g_engine_info->engine_name);
                return ret;
        }
 
                return ret;
        }
 
@@ -799,7 +799,7 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
 
        ret = sttd_recorder_create(atype, channels, rate);
        if (0 != ret) {
 
        ret = sttd_recorder_create(atype, channels, rate);
        if (0 != ret) {
-               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %s", g_engine_info->engine_name);
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create format : %s", g_engine_info->engine_name);
                return ret;
        }
 #endif
                return ret;
        }
 #endif
@@ -1246,3 +1246,30 @@ int __log_enginelist()
 
        return 0;
 }
 
        return 0;
 }
+
+int sttd_engine_agent_set_audio_type(const char* audio_type)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == g_engine_info) {
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of is not valid");
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (false == g_engine_info->is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_INFO, TAG_STTD, "[Server Info] Set audio type(%s)", audio_type);
+
+       int ret;
+       ret = stt_engine_set_audio_type(audio_type);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set audio type error(%d)", ret);
+       }
+       return ret;
+}
index 58058be..97ac59d 100644 (file)
@@ -120,6 +120,8 @@ int sttd_engine_agent_send_error(stte_error_e error, const char* msg);
 
 int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data);
 
 
 int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data);
 
+int sttd_engine_agent_set_audio_type(const char* audio_type);
+
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
index 90639b2..751ee73 100644 (file)
 #include "sttd_dbus.h"
 #include "sttd_recorder.h"
 #include "sttd_main.h"
 #include "sttd_dbus.h"
 #include "sttd_recorder.h"
 #include "sttd_main.h"
+#include "sttd_engine_agent.h"
 
 
+#define STTE_AUDIO_ID_NONE             "STT_AUDIO_ID_NONE"             /**< None audio id */
+#ifdef TV_FFV_MODE
+#define STTE_AUDIO_ID_FFV              "STT_FARFIELD_VOICE_VD"
+#endif
 
 #define FRAME_LENGTH 320
 #define BUFFER_LENGTH FRAME_LENGTH * 2
 
 #define FRAME_LENGTH 320
 #define BUFFER_LENGTH FRAME_LENGTH * 2
@@ -70,6 +75,8 @@ static int g_buffer_count;
 
 static int g_stream_focus_id;
 
 
 static int g_stream_focus_id;
 
+static bool g_is_set_audio_type = false;
+
 #ifdef TV_FFV_MODE
 farfield_voice_h g_farfieldvoice_h = NULL;
 #endif
 #ifdef TV_FFV_MODE
 farfield_voice_h g_farfieldvoice_h = NULL;
 #endif
@@ -107,6 +114,11 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void
        }
 
        if (NULL != g_audio_cb) {
        }
 
        if (NULL != g_audio_cb) {
+               if (false == g_is_set_audio_type) {
+                       sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_BLUETOOTH);
+                       g_is_set_audio_type = true;
+               }
+
                if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to read audio");
                        sttd_recorder_stop();
                if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to read audio");
                        sttd_recorder_stop();
@@ -143,6 +155,11 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void
 #ifdef TV_FFV_MODE
 static void _ffv_audio_function_cb(void* data, unsigned int length, void* user_data)
 {
 #ifdef TV_FFV_MODE
 static void _ffv_audio_function_cb(void* data, unsigned int length, void* user_data)
 {
+       if (false == g_is_set_audio_type) {
+               sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_FFV);
+               g_is_set_audio_type = true;
+       }
+
        if (0 == g_buffer_count % 50) {
                SLOG(LOG_INFO, TAG_STTD, "[Recorder INFO] farfield audio function callback is invoked");
 
        if (0 == g_buffer_count % 50) {
                SLOG(LOG_INFO, TAG_STTD, "[Recorder INFO] farfield audio function callback is invoked");
 
@@ -637,6 +654,9 @@ int sttd_recorder_stop()
        SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
        pthread_mutex_lock(&sttd_audio_in_handle_mutex);
 
        SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
        pthread_mutex_lock(&sttd_audio_in_handle_mutex);
 
+       g_is_set_audio_type = false;
+       sttd_engine_agent_set_audio_type(STTE_AUDIO_ID_NONE);
+
        /* Check engine id is valid */
        if (NULL == g_recorder) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
        /* Check engine id is valid */
        if (NULL == g_recorder) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
index a293006..4827465 100755 (executable)
@@ -98,7 +98,7 @@ int stte_set_private_data_set_cb(stte_private_data_set_cb callback)
        int ret = STTE_ERROR_NONE;
        ret = stt_engine_set_private_data_set_cb(callback, NULL);
        if (0 != ret) {
        int ret = STTE_ERROR_NONE;
        ret = stt_engine_set_private_data_set_cb(callback, NULL);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data set callback");
        }
        return ret;
 }
        }
        return ret;
 }
@@ -108,7 +108,31 @@ int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback)
        int ret = STTE_ERROR_NONE;
        ret = stt_engine_set_private_data_requested_cb(callback, NULL);
        if (0 != ret) {
        int ret = STTE_ERROR_NONE;
        ret = stt_engine_set_private_data_requested_cb(callback, NULL);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data requested callback");
        }
        return ret;
 }
        }
        return ret;
 }
+
+int stte_set_audio_type_set_cb(stte_audio_type_cb callback, void* user_data)
+{
+       SLOG(LOG_INFO, TAG_STTD, "[Server Info] Set audio type set callback");
+
+       int ret = STTE_ERROR_NONE;
+       ret = stt_engine_set_audio_type_set_cb(callback, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set audio type set");
+       }
+       return ret;
+}
+
+int stte_unset_audio_type_set_cb(void)
+{
+       SLOG(LOG_INFO, TAG_STTD, "[Server Info] Unset audio type set callback");
+
+       int ret = STTE_ERROR_NONE;
+       ret = stt_engine_set_audio_type_set_cb(NULL, NULL);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset audio type set");
+       }
+       return ret;
+}
\ No newline at end of file