From f1cfffcad666a03d0c82ca1061d266c48eb7269c Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Wed, 19 Jul 2023 13:32:38 +0900 Subject: [PATCH] Move functions about audio streaming to public header file Change-Id: Ibb6a5473aabdb36d7936a79fc99b66d36025e3da Signed-off-by: Suyeon Hwang --- client/stt.c | 90 ++++++++++++++++-------- include/stt.h | 184 +++++++++++++++++++++++++++++++++++++++---------- include/stt_internal.h | 14 ---- 3 files changed, 212 insertions(+), 76 deletions(-) diff --git a/client/stt.c b/client/stt.c index 5b74583..8a37d80 100644 --- a/client/stt.c +++ b/client/stt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -43,8 +44,6 @@ static void __stt_notify_error(void *data); static Ecore_Timer* g_connect_timer = NULL; static float g_volume_db = 0; -static int g_feature_enabled = -1; - static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER; static cynara *p_cynara = NULL; @@ -62,40 +61,79 @@ static sound_stream_ducking_h g_alarm_stream_ducking; #define SND_MGR_DUCKING_DURATION 500 -static int __stt_get_feature_enabled() +static bool is_stt_feature_enabled() { - if (0 == g_feature_enabled) { + static atomic_int stt_feature_enabled = -1; + + if (0 == stt_feature_enabled) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; + return false; //LCOV_EXCL_STOP - } else if (-1 == g_feature_enabled) { + } else if (-1 == stt_feature_enabled) { bool stt_supported = false; - bool mic_supported = false; if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); - return STT_ERROR_NOT_SUPPORTED; + return false; //LCOV_EXCL_STOP } + if (false == stt_supported) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + stt_feature_enabled = 0; + return false; + //LCOV_EXCL_STOP + } + + stt_feature_enabled = 1; + } + + return true; +} + +static bool is_mic_feature_enabled() +{ + static atomic_int mic_feature_enabled = -1; + + if (0 == mic_feature_enabled) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return false; + //LCOV_EXCL_STOP + } else if (-1 == mic_feature_enabled) { + bool mic_supported = false; + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); - return STT_ERROR_NOT_SUPPORTED; + return false; //LCOV_EXCL_STOP } - if (false == stt_supported || false == mic_supported) { + if (false == mic_supported) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - g_feature_enabled = 0; - return STT_ERROR_NOT_SUPPORTED; + mic_feature_enabled = 0; + return false; //LCOV_EXCL_STOP } - g_feature_enabled = 1; + mic_feature_enabled = 1; + } + + return true; +} + +static int __stt_get_feature_enabled() +{ + if (false == is_stt_feature_enabled() || false == is_mic_feature_enabled()) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } return STT_ERROR_NONE; @@ -1182,12 +1220,10 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support int stt_get_audio_format(stt_h stt, stt_audio_type_e* type, int* rate, int* num_of_channels) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, &client); - if (STT_ERROR_NONE != temp) - return temp; - + RETV_IF(false == is_stt_feature_enabled(), STT_ERROR_NOT_SUPPORTED); + RETV_IF(STT_ERROR_NONE != __stt_check_handle(stt, &client), STT_ERROR_INVALID_PARAMETER); RETVM_IF(NULL == type || NULL == rate || NULL == num_of_channels, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); - RETVM_IF(client->current_state == STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is CREATED", client->current_state); + RETVM_IF(client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = STT_ERROR_OPERATION_FAILED; int count = 0; @@ -1454,9 +1490,9 @@ int stt_stop(stt_h stt) int stt_start_audio_streaming(stt_h stt, const char* language, const char* type) { stt_client_s* client = NULL; - int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); - if (STT_ERROR_NONE != tmp) - return tmp; + RETV_IF(false == is_stt_feature_enabled(), STT_ERROR_NOT_SUPPORTED); + RETV_IF(STT_ERROR_NONE != __stt_check_handle(stt, &client), STT_ERROR_INVALID_PARAMETER); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not READY", client->current_state); RETVM_IF(STT_INTERNAL_STATE_NONE != client->internal_state, STT_ERROR_IN_PROGRESS_TO_RECORDING, "[ERROR] Invalid State : Internal state is NOT none : %d", client->current_state); SLOG(LOG_INFO, TAG_STTC, "===== STT START AUDIO STREAMING"); @@ -1494,9 +1530,9 @@ int stt_start_audio_streaming(stt_h stt, const char* language, const char* type) int stt_send_audio_streaming(stt_h stt, const char* data, size_t data_size) { stt_client_s* client = NULL; - int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING); - if (STT_ERROR_NONE != tmp) - return tmp; + RETV_IF(false == is_stt_feature_enabled(), STT_ERROR_NOT_SUPPORTED); + RETV_IF(STT_ERROR_NONE != __stt_check_handle(stt, &client), STT_ERROR_INVALID_PARAMETER); + RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not RECORDING", client->current_state); SLOG(LOG_INFO, TAG_STTC, "===== STT SEND AUDIO STREAMING"); @@ -1527,9 +1563,9 @@ int stt_send_audio_streaming(stt_h stt, const char* data, size_t data_size) int stt_stop_audio_streaming(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING); - if (STT_ERROR_NONE != temp) - return temp; + RETV_IF(false == is_stt_feature_enabled(), STT_ERROR_NOT_SUPPORTED); + RETV_IF(STT_ERROR_NONE != __stt_check_handle(stt, &client), STT_ERROR_INVALID_PARAMETER); + RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not RECORDING", client->current_state); SLOG(LOG_INFO, TAG_STTC, "===== STT STOP AUDIO STREAMING"); diff --git a/include/stt.h b/include/stt.h index f21c4bb..7734c1e 100755 --- a/include/stt.h +++ b/include/stt.h @@ -206,6 +206,15 @@ typedef enum { /** +* @brief Enumerations of audio type. +* @since_tizen 8.0 +*/ +typedef enum { + STT_AUDIO_TYPE_RAW_S16 = 0, /**< Signed 16-bit audio sample */ + STT_AUDIO_TYPE_RAW_U8, /**< Unsigned 8-bit audio sample */ +} stt_audio_type_e; + +/** * @brief A structure of STT handle. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ @@ -355,7 +364,7 @@ typedef void (*stt_speech_status_cb)(stt_h stt, stt_speech_status_e status, void * @privilege %http://tizen.org/privilege/recorder * @remarks If the function succeeds, @a stt handle must be released with stt_destroy(). * @param[out] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_OUT_OF_MEMORY Out of memory @@ -375,7 +384,7 @@ int stt_create(stt_h* stt); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -395,7 +404,7 @@ int stt_destroy(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Success * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -418,7 +427,7 @@ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, v * @remarks If the function is success, @a engine_id must be released using free(). * @param[in] stt The STT handle * @param[out] engine_id Engine ID - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Success * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -441,7 +450,7 @@ int stt_get_engine(stt_h stt, char** engine_id); * @remarks A privilege (%http://tizen.org/privilege/appmanager.launch) is necessary since 3.0. * @param[in] stt The STT handle * @param[in] engine_id Engine ID - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Success * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -465,7 +474,7 @@ int stt_set_engine(stt_h stt, const char* engine_id); * However, if the user wants to apply the 3rd party's engine, the credential may be necessary. In that case, please follow the policy provided by the corresponding engine. * @param[in] stt The STT handle * @param[in] credential The app credential - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Success * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -488,7 +497,7 @@ int stt_set_credential(stt_h stt, const char* credential); * @param[in] stt The STT handle * @param[in] key The field name of private data * @param[in] data The data for set - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -511,7 +520,7 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data); * @param[in] stt The STT handle * @param[in] key The field name of private data * @param[out] data The data field of private data - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -530,7 +539,7 @@ int stt_get_private_data(stt_h stt, const char* key, char** data); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -551,7 +560,7 @@ int stt_prepare(stt_h stt); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -573,7 +582,7 @@ int stt_unprepare(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -599,7 +608,7 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac * If the function succeeds, @a language must be released using free() when it is no longer required. * @param[in] stt The STT handle * @param[out] language The language - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -618,7 +627,7 @@ int stt_get_default_language(stt_h stt, char** language); * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle * @param[out] state The current STT state - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -639,7 +648,7 @@ int stt_get_state(stt_h stt, stt_state_e* state); * If the function succeeds, @a err_msg must be released using free() when it is no longer required. * @param[in] stt The STT handle * @param[out] err_msg The current error message - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -660,7 +669,7 @@ int stt_get_error_message(stt_h stt, char** err_msg); * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL) * @param[out] support The result status @c true = supported, * @c false = not supported - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -680,7 +689,7 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle * @param[in] type The option type - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -701,7 +710,7 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type); * @remarks Sound file type should be wav type. * @param[in] stt The STT handle * @param[in] filename The sound file path - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -720,7 +729,7 @@ int stt_set_start_sound(stt_h stt, const char* filename); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -741,7 +750,7 @@ int stt_unset_start_sound(stt_h stt); * @remarks Sound file type should be wav type. * @param[in] stt The STT handle * @param[in] filename The sound file path - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -760,7 +769,7 @@ int stt_set_stop_sound(stt_h stt, const char* filename); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -783,7 +792,7 @@ int stt_unset_stop_sound(stt_h stt); * @param[in] stt The STT handle * @param[in] language The language selected from stt_foreach_supported_languages() * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL) - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -810,8 +819,9 @@ int stt_start(stt_h stt, const char* language, const char* type); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder + * @remarks This function can only stop recording started by stt_start(). * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -826,6 +836,7 @@ int stt_start(stt_h stt, const char* language, const char* type); * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). * If this function succeeds, the STT state will be #STT_STATE_PROCESSING. * If you call this function again before state changes, you will receive #STT_ERROR_IN_PROGRESS_TO_PROCESSING. + * If you call this function after starting recording by stt_start_audio_streaming(), you will receive #STT_ERROR_OPERATION_FAILED. * After processing of engine, stt_result_cb() is called. * @see stt_start() * @see stt_cancel() @@ -842,7 +853,7 @@ int stt_stop(stt_h stt); * @remarks This function cancels recording and engine cancels recognition processing. * After successful cancel, stt_state_changed_cb() is called otherwise if error is occurred, stt_error_cb() is called. * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -871,7 +882,7 @@ int stt_cancel(stt_h stt); * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle * @param[out] volume Recording volume - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -895,7 +906,7 @@ int stt_get_recording_volume(stt_h stt, float* volume); * @param[in] stt The STT handle * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -918,7 +929,7 @@ int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* us * @param[in] stt The STT handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -938,7 +949,7 @@ int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -959,7 +970,7 @@ int stt_unset_recognition_result_cb(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -979,7 +990,7 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1000,7 +1011,7 @@ int stt_unset_state_changed_cb(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1020,7 +1031,7 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1041,7 +1052,7 @@ int stt_unset_error_cb(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1061,7 +1072,7 @@ int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_ * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1080,7 +1091,7 @@ int stt_unset_default_language_changed_cb(stt_h stt); * @param[in] stt The STT handle * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1097,7 +1108,7 @@ int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* u * @brief Unsets the callback function. * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif * @param[in] stt The STT handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #STT_ERROR_NONE Successful * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter @@ -1150,6 +1161,109 @@ int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* use int stt_unset_speech_status_cb(stt_h stt); +/** + * @brief Starts audio streaming and recognition asynchronously. + * @since_tizen 8.0 + * @remarks This function starts audio streaming in the STT service. + * This work continues until stt_stop_audio_streaming(), stt_cancel() or silence detected by engine. + * @param[in] stt The STT handle + * @param[in] language The language selected from stt_foreach_supported_languages() (e.g. #NULL(Automatic), 'en_US') + * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_OPERATION_FAILED Operation failure + * @retval #STT_ERROR_RECORDER_BUSY Recorder busy + * @retval #STT_ERROR_INVALID_LANGUAGE Invalid language + * @retval #STT_ERROR_IN_PROGRESS_TO_RECORDING Progress to recording is not finished + * @pre The state should be #STT_STATE_READY. + * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). + * If this function succeeds, the STT state will be #STT_STATE_RECORDING. + * If you call this function again before state changes, you will receive #STT_ERROR_IN_PROGRESS_TO_RECORDING. + * @see stt_stop_audio_streaming() + * @see stt_send_audio_streaming() + * @see stt_cancel() + * @see stt_state_changed_cb() +*/ +int stt_start_audio_streaming(stt_h stt, const char* language, const char* type); + + +/** + * @brief Sends audio data to STT engine. + * @since_tizen 8.0 + * @remarks The audio format of @a data should satisfy the audio format from stt_get_audio_format(). + * @param[in] stt The STT handle + * @param[in] data The raw PCM data + * @param[in] data_size The number of bytes of @a data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_OPERATION_FAILED Operation failure + * @retval #STT_ERROR_IN_PROGRESS_TO_READY Progress to ready is not finished + * @retval #STT_ERROR_IN_PROGRESS_TO_RECORDING Progress to recording is not finished + * @pre The state should be #STT_STATE_RECORDING. + * @post If you call this function after starting recording by stt_start(), you will receive #STT_ERROR_OPERATION_FAILED. + * @see stt_start_audio_streaming() + * @see stt_stop_audio_streaming() + * @see stt_cancel() + * @see stt_get_audio_format() +*/ +int stt_send_audio_streaming(stt_h stt, const char* data, size_t data_size); + + +/** + * @brief Finishes the audio streaming and starts recognition processing in engine asynchronously. + * @since_tizen 8.0 + * @remarks This function can only stop recording started by stt_start_audio_streaming(). + * @param[in] stt The STT handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_OPERATION_FAILED Operation failure + * @retval #STT_ERROR_IN_PROGRESS_TO_READY Progress to ready is not finished + * @retval #STT_ERROR_IN_PROGRESS_TO_PROCESSING Progress to processing is not finished + * @pre The state should be #STT_STATE_RECORDING. + * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). + * If this function succeeds, the STT state will be #STT_STATE_PROCESSING. + * If you call this function again before state changes, you will receive #STT_ERROR_IN_PROGRESS_TO_PROCESSING. + * If you call this function after starting recording by stt_start(), you will receive #STT_ERROR_OPERATION_FAILED. + * After processing of engine, stt_result_cb() is called. + * @see stt_start_audio_streaming() + * @see stt_cancel() + * @see stt_state_changed_cb() +*/ +int stt_stop_audio_streaming(stt_h stt); + + +/** + * @brief Gets the recognizable audio format information. + * @since_tizen 8.0 + * @param[in] stt The STT handle + * @param[out] type The audio type + * @param[out] rate The sample rates + * @param[out] num_of_channels The number of channels + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_OPERATION_FAILED Operation failure + * @pre The state should be #STT_STATE_READY. + * @see stt_send_audio_streaming() +*/ +int stt_get_audio_format(stt_h stt, stt_audio_type_e* type, int* rate, int* num_of_channels); + + #ifdef __cplusplus } #endif diff --git a/include/stt_internal.h b/include/stt_internal.h index 0e8589c..a742b7a 100644 --- a/include/stt_internal.h +++ b/include/stt_internal.h @@ -31,14 +31,6 @@ extern "C" /** -* @brief Enumerations of audio type. -*/ -typedef enum { - STT_AUDIO_TYPE_RAW_S16 = 0, /**< Signed 16-bit audio sample */ - STT_AUDIO_TYPE_RAW_U8, /**< Unsigned 8-bit audio sample */ -} stt_audio_type_e; - -/** * @brief Enumerations of system volume event. */ typedef enum { @@ -238,12 +230,6 @@ int stt_set_audio_type(stt_h stt, const char *audio_id); int stt_get_audio_type(stt_h stt, char **audio_id); -int stt_start_audio_streaming(stt_h stt, const char* language, const char* type); -int stt_send_audio_streaming(stt_h stt, const char* data, size_t data_size); -int stt_stop_audio_streaming(stt_h stt); -int stt_get_audio_format(stt_h stt, stt_audio_type_e* type, int* rate, int* num_of_channels); - - #ifdef __cplusplus } #endif -- 2.7.4