#define TIME_DIFF(start, end) \
((uint64_t)((end).tv_sec - (start).tv_sec) * 1000000 + (((end).tv_nsec - (start).tv_nsec) / 1000)) / 1000
-static struct timespec g_request_playing, g_start_playing;
+static struct timespec g_request_playing, g_start_playing, g_finish_playing;
static double g_avg_latency;
static double g_min_latency;
static double g_max_latency;
static int g_file_num;
+static int g_total_data_size;
typedef struct {
unsigned int uid;
}
if (ttsd_data_get_synth_control() == TTSD_SYNTHESIS_CONTROL_DOING && ttsd_state_get_state() == TTSD_STATE_READY) {
+ int ret = vconf_set_bool(TTS_PLAYING_STATUS_KEY, 1);
+ SLOG(LOG_INFO, tts_tag(), "[Server] Synthesis starting. Set playing status (True). ret(%d)", ret);
+
ttsd_state_set_state(TTSD_STATE_SYNTHESIZING);
}
return 0;
}
+static int ttsd_convert_audio_type_to_bytes(ttse_audio_type_e audio_type)
+{
+ int ret = 0;
+ switch (audio_type) {
+ case TTSE_AUDIO_TYPE_RAW_S16:
+ ret = 2; // 16bit
+ break;
+ case TTSE_AUDIO_TYPE_RAW_U8:
+ ret = 1; // 8bit
+ break;
+ default:
+ ret = 2; // Default 16bit
+ break;
+ }
+ return ret;
+}
+
int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data)
{
SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency;
g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency;
g_file_num++;
+ g_total_data_size = 0;
+ g_total_data_size += data_size;
SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency);
} 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] Result Info : uid(%u), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
uid, uttid, data, data_size, audio_type, rate);
+
+ g_total_data_size += data_size;
+ int audio_type_bytes = ttsd_convert_audio_type_to_bytes(audio_type);
+ /* Calculate xRT */
+ clock_gettime(CLOCK_MONOTONIC_RAW, &g_finish_playing);
+ long long int time_processing = (uint64_t)TIME_DIFF(g_request_playing, g_finish_playing);
+ long long int time_speech = (long long int)(1000 * g_total_data_size * sizeof(short) / (rate * audio_type_bytes));
+ double xRT = (double)(time_processing) / (double)time_speech;
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] time_processing : %lld, time_speech : %lld, total data size: %d", time_processing, time_speech, g_total_data_size);
+ SLOG(LOG_INFO, tts_tag(), "[SERVER] xRT : %lf", xRT);
} else {
/*if (TTSE_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
+ g_total_data_size += data_size;
}
- /* add wav data */
- sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
- if (NULL == sound_data) {
- SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
- return TTSD_ERROR_OUT_OF_MEMORY;
- }
+ ttsd_playing_mode_e playing_mode = ttsd_data_get_playing_mode(uid);
+ SLOG(LOG_DEBUG, tts_tag(), "[SERVER] uid(%d), playing mode(%d)", uid, playing_mode);
+ if (TTSD_PLAYING_MODE_BY_SERVICE == playing_mode) {
+ /* add wav data */
+ sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
+ if (NULL == sound_data) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
- if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
- SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
- ttsd_data_destroy_sound_data(sound_data);
+ if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
+ SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
+ ttsd_data_destroy_sound_data(sound_data);
- return TTSD_ERROR_OPERATION_FAILED;
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+ } else { /* TTSD_PLAYING_MODE_BY_CLIENT */
+ /* send pcm data to client */
+ int tmp_pid = ttsd_data_get_pid(uid);
+ if (0 != ttsdc_ipc_send_pcm(tmp_pid, uid, uttid, event, data, data_size, audio_type, rate)) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to send pcm data to client");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
}
if (event == TTSE_RESULT_EVENT_FINISH) {