+
+int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
+{
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == callback)
+ 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;
+ }
+
+ client->speech_status_cb = callback;
+ client->speech_status_user_data = user_data;
+
+ return 0;
+}
+
+int stt_unset_speech_status_cb(stt_h stt)
+{
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ 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;
+ }
+
+ client->speech_status_cb = NULL;
+ client->speech_status_user_data = NULL;
+
+ return 0;
+}
+
+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;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+ if (NULL == filepath) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ SLOG(LOG_DEBUG, 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;
+ }
+
+ int ret = -1;
+ char appid[128] = {0, };
+ ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+
+ if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
+ }
+
+ char* temp = NULL;
+ if (NULL == language) {
+ temp = strdup("default");
+ } else {
+ temp = strdup(language);
+ }
+
+ if (NULL == temp) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+ return STT_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (true == client->credential_needed && NULL == client->credential) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
+ free(temp);
+ temp = NULL;
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+
+ client->internal_state = STT_INTERNAL_STATE_STARTING;
+ ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
+ client->internal_state = STT_INTERNAL_STATE_NONE;
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
+ }
+
+ free(temp);
+ temp = NULL;
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return ret;
+}
+
+int stt_cancel_file(stt_h stt)
+{
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL FILE");
+
+ /* check state */
+ if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
+ return STT_ERROR_INVALID_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);
+ return STT_ERROR_IN_PROGRESS_TO_RECORDING;
+ } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
+ return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
+ } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
+ return STT_ERROR_IN_PROGRESS_TO_READY;
+ }
+
+ client->internal_state = STT_INTERNAL_STATE_CANCELING;
+ int ret = stt_dbus_request_cancel_file(client->uid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
+ client->internal_state = STT_INTERNAL_STATE_NONE;
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return ret;
+}
+