Merge "Add internal method to play pcm data" into tizen
authorWonnam Jang <wn.jang@samsung.com>
Thu, 11 May 2017 05:52:22 +0000 (05:52 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 11 May 2017 05:52:22 +0000 (05:52 +0000)
1  2 
client/tts.c
common/tts_defs.h
server/ttsd_server.c

diff --combined client/tts.c
@@@ -34,8 -34,6 +34,8 @@@ static int g_feature_enabled = -1
  
  static bool g_err_callback_status = false;
  
 +static int g_max_text_size = -1;
 +
  /* Function definition */
  static Eina_Bool __tts_notify_state_changed(void *data);
  static Eina_Bool __tts_notify_error(void *data);
@@@ -139,33 -137,6 +139,33 @@@ void __tts_config_voice_changed_cb(cons
        return;
  }
  
 +static Eina_Bool __reconnect_by_engine_changed(void* data)
 +{
 +      tts_h tts = (tts_h)data;
 +
 +      tts_client_s* client = tts_client_get(tts);
 +      if (NULL == client) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
 +              return EINA_FALSE;
 +      }
 +
 +      if (TTS_STATE_READY != client->current_state) {
 +              usleep(10000);
 +              return EINA_TRUE;
 +      }
 +
 +      int ret = tts_unprepare(tts);
 +      if (0 != ret) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
 +      }
 +      ret = tts_prepare(tts);
 +      if (0 != ret) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
 +      }
 +
 +      return EINA_FALSE;
 +}
 +
  void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
  {
        tts_h tts = (tts_h)user_data;
                if (0 != ret) {
                        SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
                }
 -              ret = tts_unprepare(tts);
 -              if (0 != ret) {
 -                      SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
 -              }
 -              ret = tts_prepare(tts);
 -              if (0 != ret) {
 -                      SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
 -              }
 +
 +              ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
        } else if (TTS_STATE_READY == client->current_state) {
                ret = tts_unprepare(tts);
                if (0 != ret) {
@@@ -252,7 -229,7 +252,7 @@@ int tts_create(tts_h* tts
                return __tts_convert_config_error_code(ret);
        }
  
 -      ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL);
 +      ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
@@@ -889,13 -866,7 +889,13 @@@ int tts_get_max_text_size(tts_h tts, un
                return TTS_ERROR_INVALID_STATE;
        }
  
 -      *size = TTS_MAX_TEXT_SIZE;
 +//    *size = TTS_MAX_TEXT_SIZE;
 +      if (0 != tts_config_mgr_get_max_text_size(size)) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
 +              return TTS_ERROR_INVALID_PARAMETER;
 +      }
 +
 +      g_max_text_size = (int)*size;
  
        SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
        return TTS_ERROR_NONE;
@@@ -1030,30 -1001,11 +1030,30 @@@ int tts_add_text(tts_h tts, const char
                return TTS_ERROR_INVALID_STATE;
        }
  
 -      if (TTS_MAX_TEXT_SIZE < strlen(text) || strlen(text) <= 0) {
 -              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
 -              SLOG(LOG_DEBUG, TAG_TTSC, "=====");
 -              SLOG(LOG_DEBUG, TAG_TTSC, " ");
 -              return TTS_ERROR_INVALID_PARAMETER;
 +      if (-1 == g_max_text_size) {
 +              SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
 +              if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
 +                      SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
 +                      return TTS_ERROR_INVALID_PARAMETER;
 +              }
 +      }
 +
 +      if (0 == g_max_text_size) {
 +              if (strlen(text) <= 0) {
 +                      SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d", g_max_text_size);
 +                      SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
 +                      SLOG(LOG_DEBUG, TAG_TTSC, "=====");
 +                      SLOG(LOG_DEBUG, TAG_TTSC, " ");
 +                      return TTS_ERROR_INVALID_PARAMETER;
 +              }
 +      } else {
 +              SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
 +              if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
 +                      SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
 +                      SLOG(LOG_DEBUG, TAG_TTSC, "=====");
 +                      SLOG(LOG_DEBUG, TAG_TTSC, " ");
 +                      return TTS_ERROR_INVALID_PARAMETER;
 +              }
        }
  
        if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
        }
  
        /* check valid utf8 */
 -      iconv_t *ict;
 -      ict = iconv_open("utf-8", "");
 -      if ((iconv_t)-1 == ict) {
 -              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init for text check");
 -              return TTS_ERROR_OPERATION_FAILED;
 -      }
 +      bool valid = false;
  
 -      size_t len = strlen(text);
 -      char *in_tmp = NULL;
 -      char in_buf[TTS_MAX_TEXT_SIZE];
 -      char *out_tmp = NULL;
 -      char out_buf[TTS_MAX_TEXT_SIZE];
 -      size_t len_tmp = sizeof(out_buf);
 +      DBusError err;
 +      dbus_error_init(&err);
  
 -      memset(in_buf, 0, TTS_MAX_TEXT_SIZE);
 -      snprintf(in_buf, TTS_MAX_TEXT_SIZE, "%s", text);
 -      in_tmp = in_buf;
 -
 -      memset(out_buf, 0, TTS_MAX_TEXT_SIZE);
 -      out_tmp = out_buf;
 +      valid = dbus_validate_utf8(text, &err);
 +      if (dbus_error_is_set(&err)) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
 +              dbus_error_free(&err);
 +              return TTS_ERROR_INVALID_PARAMETER;
 +      }
  
 -      size_t st;
 -      st = iconv(ict, &in_tmp, &len, &out_tmp, &len_tmp);
 -      if ((size_t)-1 == st) {
 -              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", in_buf);
 -              iconv_close(ict);
 +      if (valid != true) {
 +              SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
                return TTS_ERROR_INVALID_PARAMETER;
        }
 -      iconv_close(ict);
 -      SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - Converted text is '%s'", out_buf);
 +      SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
  
        /* change default language value */
        char* temp = NULL;
        int ret = -1;
        int count = 0;
        while (0 != ret) {
 -              ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
 +              ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
                if (0 != ret) {
                        if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
@@@ -2366,3 -2331,202 +2366,202 @@@ int tts_unset_engine_changed_cb(tts_h t
        return 0;
  }
  
+ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
+ {
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+       SLOG(LOG_INFO, TAG_TTSC, "===== Add pcm tts");
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       if (TTS_STATE_PLAYING != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
+               if (0 != ret) {
+                       if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       return TTS_ERROR_NONE;
+ }
+ int tts_play_pcm(tts_h tts)
+ {
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+       SLOG(LOG_INFO, TAG_TTSC, "===== Play pcm tts");
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_play_pcm(client->uid);
+               if (0 != ret) {
+                       if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_PLAYING;
+       if (NULL != client->state_changed_cb) {
+               tts_client_use_callback(client);
+               client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+               tts_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+       }
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       return TTS_ERROR_NONE;
+ }
+ int tts_stop_pcm(tts_h tts)
+ {
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+       SLOG(LOG_INFO, TAG_TTSC, "===== Stop pcm tts");
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       if (TTS_STATE_PLAYING != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_stop_pcm(client->uid);
+               if (0 != ret) {
+                       if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_READY;
+       if (NULL != client->state_changed_cb) {
+               tts_client_use_callback(client);
+               client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+               tts_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+       }
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       return TTS_ERROR_NONE;
+ }
diff --combined common/tts_defs.h
@@@ -56,6 -56,9 +56,9 @@@ extern "C" 
  #define TTS_METHOD_PLAY                       "tts_method_play"
  #define TTS_METHOD_STOP                       "tts_method_stop"
  #define TTS_METHOD_PAUSE              "tts_method_pause"
+ #define TTS_METHOD_PLAY_PCM           "tts_method_play_pcm"
+ #define TTS_METHOD_STOP_PCM           "tts_method_stop_pcm"
+ #define TTS_METHOD_ADD_PCM            "tts_method_add_pcm"
  
  #define TTS_METHOD_SET_PRIVATE_DATA   "tts_method_set_private_data"
  #define TTS_METHOD_GET_PRIVATE_DATA   "tts_method_get_private_data"
  #define TTS_PITCH_NORMAL      8
  #define TTS_PITCH_MAX         15
  
 -#define TTS_MAX_TEXT_SIZE     2000
 +//#define TTS_MAX_TEXT_SIZE   2000
  
  #define TTS_FEATURE_PATH      "tizen.org/feature/speech.synthesis"
  
diff --combined server/ttsd_server.c
@@@ -74,6 -74,7 +74,6 @@@ static Eina_Bool __wait_synthesis(void 
  
        if (uid > 0) {
                if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
 -                      usleep(100000);
                        return EINA_TRUE;
                } else {
                        g_wait_timer = NULL;
@@@ -149,7 -150,7 +149,7 @@@ static int __synthesis(int uid, const c
                        int pid = ttsd_data_get_pid(uid);
                        ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
                } else {
 -                      g_wait_timer = ecore_timer_add(0, __wait_synthesis, (void*)credential);
 +                      g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
                }
  
                if (NULL != speak_data) {
@@@ -894,7 -895,6 +894,6 @@@ int ttsd_server_play(int uid, const cha
        return TTSD_ERROR_NONE;
  }
  
  int ttsd_server_stop(int uid)
  {
        app_state_e state;
@@@ -1068,4 -1068,165 +1067,165 @@@ int ttsd_set_private_data_requested_cb(
        return ret;
  }
  
+ int ttsd_server_play_pcm(int uid)
+ {
+       app_state_e state;
+       if (0 > ttsd_data_get_client_state(uid, &state)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid  ", uid);
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+       if (APP_STATE_PLAYING == state) {
+               SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
+               return TTSD_ERROR_NONE;
+       }
+       int current_uid = ttsd_data_get_current_playing();
+       SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
+       if (uid != current_uid && -1 != current_uid) {
+               if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+                       /* Send interrupt message */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
+                       /* pause player */
+                       if (0 != ttsd_server_stop(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
+                       }
+                       if (0 != ttsd_player_stop(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
+                       }
+                       intptr_t pcurrent_uid = (intptr_t)current_uid;
+                       ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+               } else {
+                       /* Default mode policy of interrupt is "Pause" */
+                       /* Send interrupt message */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
+                       /* pause player */
+                       if (0 != ttsd_player_pause(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
+                       }
+                       /* change state */
+                       ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
+                       intptr_t pcurrent_uid = (intptr_t)current_uid;
+                       ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+               }
+       }
+       /* Change current play */
+       if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+       return TTSD_ERROR_NONE;
+ }
+ int ttsd_server_stop_pcm(int uid)
+ {
+       app_state_e state;
+       if (0 > ttsd_data_get_client_state(uid, &state)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+       SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
  
+       if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
+               if (0 != ttsd_player_clear(uid))
+                       SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
+               ttsd_data_set_client_state(uid, APP_STATE_READY);
+       }
+       /* Reset all data */
+       ttsd_data_clear_data(uid);
+       return TTSD_ERROR_NONE;
+ }
+ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
+ {
+       SLOG(LOG_DEBUG, tts_tag(), "===== ADD PCM");
+       int uttid = -1;
+       /* Synthesis is success */
+       if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
+               if (TTSE_RESULT_EVENT_START == event) {
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
+                       SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
+                               uid, uttid, data, data_size, audio_type, rate);
+               } else if (TTSE_RESULT_EVENT_FINISH == event) {
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
+                       SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
+                               uid, uttid, data, data_size, audio_type, rate);
+               } else {
+                       /*if (TTSE_RESULT_EVENT_CONTINUE == event)  SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
+               }
+               if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
+                       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
+                       SLOG(LOG_DEBUG, tts_tag(), "=====");
+                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       return TTSD_ERROR_INVALID_PARAMETER;
+               }
+               /* add wav data */
+               sound_data_s* temp_sound_data = NULL;
+               temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
+               if (NULL == temp_sound_data) {
+                       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+                       return TTSD_ERROR_OUT_OF_MEMORY;
+               }
+               temp_sound_data->data = NULL;
+               temp_sound_data->rate = 0;
+               temp_sound_data->data_size = 0;
+               if (0 < data_size) {
+                       temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
+                       if (NULL != temp_sound_data->data) {
+                               memcpy(temp_sound_data->data, data, data_size);
+                               temp_sound_data->data_size = data_size;
+                               SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
+                                       uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
+                       } else {
+                               SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
+                       }
+               } else {
+                       SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
+               }
+               temp_sound_data->utt_id = uttid;
+               temp_sound_data->event = event;
+               temp_sound_data->audio_type = audio_type;
+               temp_sound_data->rate = rate;
+               if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
+                       SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
+               }
+               if (0 != ttsd_player_play(uid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
+                       /* Change ready state */
+                       ttsd_server_stop(uid);
+                       int tmp_pid;
+                       tmp_pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+               }
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
+       }
+       SLOG(LOG_DEBUG, tts_tag(), "=====");
+       return TTSD_ERROR_NONE;
+ }