+ if (0 != stt_client_set_current_recognition(uid)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT is busy because of recording or processing");
+ if (NULL != sound) free(sound);
+ return STTD_ERROR_RECORDER_BUSY;
+ }
+
+ /* engine start recognition */
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s)",
+ uid, lang, recognition_type);
+ if (NULL != sound)
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] start sound : %s", sound);
+
+ /* 1. Set audio session */
+ ret = sttd_recorder_set_audio_session();
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set session : %d", ret);
+ if (NULL != sound) free(sound);
+ return ret;
+ }
+
+ bool is_sound_done = false;
+
+ /* 2. Request wav play */
+ if (NULL != sound) {
+ int id = 0;
+ intptr_t puid = (intptr_t)uid;
+ ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)puid, &id);
+ if (WAV_PLAYER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+ is_sound_done = true;
+ }
+ free(sound);
+ sound = NULL;
+ } else {
+ is_sound_done = true;
+ }
+
+ /* 3. Create recorder & engine initialize */
+ ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, appid, credential, NULL);
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ sttd_recorder_unset_audio_session();
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
+ return ret;
+ }
+
+ if (0 != strcmp(STTE_RECOGNITION_TYPE_FREE_PARTIAL, recognition_type)) {
+ g_recording_timer = ecore_timer_add(g_recording_timeout, __stop_by_recording_timeout, NULL);
+ }
+
+ /* change uid state */
+ sttd_client_set_state(uid, APP_STATE_RECORDING);
+
+ g_recording_log_count = 0;
+
+ if (true == is_sound_done) {
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] No sound play");
+
+ ret = sttd_engine_agent_recognize_start_recorder(uid);
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ sttd_recorder_unset_audio_session();
+
+ sttd_engine_agent_recognize_cancel();
+ ecore_timer_del(g_recording_timer);
+ sttd_client_set_state(uid, APP_STATE_READY);
+
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
+ return ret;
+ }
+
+ /* Notify uid state change */
+ sttdc_send_set_state(uid, APP_STATE_RECORDING);
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
+ return STTD_RESULT_STATE_DONE;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Wait sound finish");
+
+ return STTD_RESULT_STATE_NOT_DONE;