return;
}
+static const char* __stt_get_state_string(stt_state_e state)
+{
+ //LCOV_EXCL_START
+ switch (state) {
+ case STT_STATE_CREATED: return "STT_STATE_CREATED";
+ case STT_STATE_READY: return "STT_STATE_READY";
+ case STT_STATE_RECORDING: return "STT_STATE_RECORDING";
+ case STT_STATE_PROCESSING: return "STT_STATE_PROCESSING";
+ default:
+ return "Invalid State";
+ }
+ //LCOV_EXCL_STOP
+}
+
static int __stt_check_handle(stt_h stt, stt_client_s** client)
{
RETVM_IF(NULL == stt, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
return STT_ERROR_NONE;
}
+static int __stt_check_precondition_with_state(stt_h stt, stt_client_s** client, stt_state_e state)
+{
+ int ret = __stt_check_precondition(stt, client);
+ if (STT_ERROR_NONE != ret)
+ return ret;
+ const char* state_string = __stt_get_state_string(state);
+ RETVM_IF(state != (*client)->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not %s", (*client)->current_state, state_string);
+ return STT_ERROR_NONE;
+}
+
int stt_create(stt_h* stt)
{
RETV_IF(0 != __stt_get_feature_enabled(), STT_ERROR_NOT_SUPPORTED);
int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
+ RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine");
- RETVM_IF(NULL == callback, 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 not CREATED", client->current_state);
-
client->supported_engine_cb = callback;
client->supported_engine_user_data = user_data;
int stt_get_engine(stt_h stt, char** engine_id)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
-
RETVM_IF(NULL == engine_id, 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 not CREATED", client->current_state);
+ SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
int ret = 0;
int stt_set_private_data(stt_h stt, const char* key, const char* data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
-
RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
+ SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE
int stt_get_private_data(stt_h stt, const char* key, char** data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
-
RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
+ SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
int ret = -1;
int count = 0;
int stt_prepare(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT");
- /* check state */
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
-
ecore_thread_main_loop_begin();
g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
ecore_thread_main_loop_end();
int stt_unprepare(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT");
- /* check state */
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
-
int ret = -1;
int count = 0;
while (0 != ret) {
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
-
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
+ SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
int ret;
char* current_engine_id = NULL;
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
-
RETVM_IF(NULL == language, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
+ SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
int ret = 0;
ret = stt_config_mgr_get_default_language(language);
int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == type || NULL == support, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- 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 = -1;
int count = 0;
int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
- /* check state */
- if (client->current_state != STT_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
- return STT_ERROR_INVALID_STATE;
- }
-
SLOG(LOG_INFO, TAG_STTC, "===== Set silence detection, supported(%d), type(%d)", client->silence_supported, type);
if (true == client->silence_supported) {
int stt_set_start_sound(stt_h stt, const char* filename)
{
+
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
-
RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
+
+ SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
int ret = -1;
int count = 0;
int stt_unset_start_sound(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND");
- /* check state */
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
-
int ret = -1;
int count = 0;
while (0 != ret) {
int stt_set_stop_sound(stt_h stt, const char* filename)
{
+
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
- SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
+ SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
int ret = -1;
int count = 0;
int stt_unset_stop_sound(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
if (STT_ERROR_NONE != temp)
return temp;
SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
int ret = -1;
int count = 0;
int stt_start(stt_h stt, const char* language, const char* type)
{
stt_client_s* client = NULL;
- int tmp = __stt_check_precondition(stt, &client);
- if (STT_ERROR_NONE != tmp) {
+ int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
+ if (STT_ERROR_NONE != tmp)
return tmp;
- }
- SLOG(LOG_INFO, TAG_STTC, "===== STT START");
- RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: 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: Current state(%d) is not READY", client->current_state);
+ SLOG(LOG_INFO, TAG_STTC, "===== STT START");
int ret = -1;
char appid[1024] = {0, };
int stt_stop(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING);
if (STT_ERROR_NONE != temp)
return temp;
SLOG(LOG_INFO, TAG_STTC, "===== STT STOP");
- RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state);
if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
int stt_get_recording_volume(stt_h stt, float* volume)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == volume, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
*volume = g_volume_db;
int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- if (callback == NULL)
- return STT_ERROR_INVALID_PARAMETER;
-
- if (STT_STATE_CREATED != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
- return STT_ERROR_INVALID_STATE;
- }
-
+ RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb");
client->recognition_result_cb = callback;
int stt_unset_recognition_result_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- if (STT_STATE_CREATED != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
- return STT_ERROR_INVALID_STATE;
- }
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset recognition result cb");
client->recognition_result_cb = NULL;
int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb");
client->state_changed_cb = callback;
int stt_unset_state_changed_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset state changed cb");
client->state_changed_cb = NULL;
int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb");
client->error_cb = callback;
int stt_unset_error_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset error cb");
client->error_cb = NULL;
int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb");
client->default_lang_changed_cb = callback;
int stt_unset_default_language_changed_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset default language changed cb");
client->default_lang_changed_cb = NULL;
int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb");
client->engine_changed_cb = callback;
int stt_unset_engine_changed_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset engine changed cb");
client->engine_changed_cb = NULL;
int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb");
client->speech_status_cb = callback;
int stt_unset_speech_status_cb(stt_h stt)
{
stt_client_s* client = NULL;
- int temp = __stt_check_precondition(stt, &client);
+ int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
if (STT_ERROR_NONE != temp)
return temp;
- RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
-
SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset speech status cb");
client->speech_status_cb = NULL;
int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate)
{
stt_client_s* client = NULL;
- int tmp = __stt_check_precondition(stt, &client);
- if (STT_ERROR_NONE != tmp) {
+ int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
+ if (STT_ERROR_NONE != tmp)
return tmp;
- }
- RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
+ RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE");
- /* check state */
- if (client->current_state != STT_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
- return STT_ERROR_INVALID_STATE;
- }
-
if (STT_INTERNAL_STATE_NONE != client->internal_state) {
SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
return STT_ERROR_IN_PROGRESS_TO_RECORDING;