2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
15 #include "ttsd_main.h"
16 #include "ttsd_player.h"
17 #include "ttsd_data.h"
18 #include "ttsd_engine_agent.h"
19 #include "ttsd_server.h"
20 #include "ttsd_dbus_server.h"
22 #include "ttsd_dbus.h"
23 #include "ttsd_config.h"
24 #include "ttsd_network.h"
32 /* If current engine exist */
33 static bool g_is_engine;
35 /* If engine is running */
36 static bool g_is_synthesizing;
38 /* If the daemon get the result */
39 static bool g_is_next_synthesis = false;
41 /* Function definitions */
42 int __server_next_synthesis(int uid);
45 int __server_set_is_synthesizing(bool flag)
47 g_is_synthesizing = flag;
51 bool __server_get_is_synthesizing()
53 return g_is_synthesizing;
56 int __server_set_is_next_synthesis(bool flag)
58 g_is_next_synthesis = flag;
62 bool __server_get_is_next_synthesis()
64 return g_is_next_synthesis;
67 int __server_send_error(int uid, int utt_id, int error_code)
69 int pid = ttsd_data_get_pid(uid);
72 if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) {
73 ttsd_data_delete_client(uid);
79 int __server_start_synthesis(int uid, int mode)
83 /* check if tts-engine is running */
84 if (true == __server_get_is_synthesizing()) {
85 SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
88 if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
89 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
92 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Out of memory : utterance ");
93 return TTSD_ERROR_OUT_OF_MEMORY;
97 utt->uttid = sdata.utt_id;
99 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
100 SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
101 SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
102 SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
103 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
105 __server_set_is_synthesizing(true);
107 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
109 SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
111 __server_set_is_synthesizing(false);
113 result = TTSD_ERROR_OPERATION_FAILED;
117 /* mode 2 : Add text in playing state */
119 __server_send_error(uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
120 //ttsd_config_save_error();
122 ttsd_server_stop(uid);
124 int pid = ttsd_data_get_pid(uid);
125 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
128 SLOG(LOG_DEBUG, get_tag(), "[Server] SUCCESS to start synthesis");
131 if(sdata.text != NULL)
135 SLOG(LOG_DEBUG, get_tag(), "[Server] Text List is EMPTY!! ");
142 int __server_play_internal(int uid, app_state_e state)
146 /* - input uid is current play */
150 if (APP_STATE_PAUSED == state) {
151 SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
153 /* resume player and start speech synthesis */
154 if (0 != ttsd_player_resume(uid)) {
155 SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()");
158 /* mode 1 for play */
159 ret = __server_start_synthesis(uid, 1);
161 } else if(APP_STATE_READY == state) {
162 SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Ready' state : Next step is start synthesis ", uid);
164 /* mode 1 for play */
165 ret = __server_start_synthesis(uid, 1);
173 int __server_next_synthesis(int uid)
175 SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START");
177 /* get current playing client */
178 int current_uid = ttsd_data_get_current_playing();
180 if (0 > current_uid) {
181 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid");
182 SLOG(LOG_DEBUG, get_tag(), "=====");
183 SLOG(LOG_DEBUG, get_tag(), " ");
187 if (true == __server_get_is_synthesizing()) {
188 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. ");
189 SLOG(LOG_DEBUG, get_tag(), "=====");
190 SLOG(LOG_DEBUG, get_tag(), " ");
194 /* synthesize next text */
196 if (0 == ttsd_data_get_speak_data(current_uid, &sdata)) {
198 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
201 SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] fail to allocate memory : utterance ", __FUNCTION__);
202 return TTSD_ERROR_OUT_OF_MEMORY;
205 utt->uid = current_uid;
206 utt->uttid = sdata.utt_id;
208 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
209 SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
210 SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
211 SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
212 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
214 __server_set_is_synthesizing(true);
217 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
219 SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
221 __server_set_is_synthesizing(false);
223 __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
227 ttsd_server_stop(current_uid);
229 int pid = ttsd_data_get_pid(current_uid);
230 ttsdc_send_set_state_message(pid, current_uid, APP_STATE_READY);
233 if(sdata.text != NULL)
236 SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
237 SLOG(LOG_DEBUG, get_tag(), "[Server] Text queue is empty.");
238 SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
241 if (0 != ttsd_player_play(current_uid)) {
242 SLOG(LOG_WARN, get_tag(), "[Server WARNING] __server_next_synthesis : fail ttsd_player_play() ");
244 /* success playing */
245 SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
248 SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY END");
249 SLOG(LOG_DEBUG, get_tag(), " ");
255 * TTS Server Callback Functions
258 int __player_result_callback(player_event_e event, int uid, int utt_id)
262 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR][%s] player result error", __FUNCTION__);
263 __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
266 case PLAYER_EMPTY_SOUND_QUEUE:
267 /* check whether synthesis is running */
268 if (false == __server_get_is_synthesizing()) {
269 /* check text queue is empty */
270 if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
271 SLOG(LOG_DEBUG, get_tag(), "[SERVER Callback] all play completed ");
276 case PLAYER_END_OF_PLAYING:
283 Eina_Bool __start_next_synthesis(void *data)
285 /* get current play */
286 int uid = ttsd_data_is_current_playing();
292 if (true == __server_get_is_next_synthesis()) {
293 __server_set_is_next_synthesis(false);
294 __server_next_synthesis(uid);
300 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
302 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK START");
304 utterance_t* utt_get_param;
305 utt_get_param = (utterance_t*)user_data;
307 if (NULL == utt_get_param) {
308 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] User data is NULL " );
309 SLOG(LOG_DEBUG, get_tag(), "=====");
310 SLOG(LOG_DEBUG, get_tag(), " ");
314 int uid = utt_get_param->uid;
315 int uttid = utt_get_param->uttid;
317 /* Synthesis is success */
318 if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
320 if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_START");
321 if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
322 if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
324 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
325 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
326 SLOG(LOG_DEBUG, get_tag(), "=====");
327 SLOG(LOG_DEBUG, get_tag(), " ");
332 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) ",
333 uid, uttid, data, data_size);
336 sound_data_s temp_data;
337 temp_data.data = (char*)g_malloc0( sizeof(char) * data_size );
338 memcpy(temp_data.data, data, data_size);
340 temp_data.data_size = data_size;
341 temp_data.utt_id = utt_get_param->uttid;
342 temp_data.event = event;
344 ttsp_audio_type_e audio_type;
348 if (ttsd_engine_get_audio_format(&audio_type, &rate, &channels)) {
349 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get audio format ");
350 SLOG(LOG_DEBUG, get_tag(), "=====");
351 SLOG(LOG_DEBUG, get_tag(), " ");
355 temp_data.audio_type = audio_type;
356 temp_data.rate = rate;
357 temp_data.channels = channels;
359 if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
360 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", utt_get_param->uid);
363 if (event == TTSP_RESULT_EVENT_FINISH) {
364 __server_set_is_synthesizing(false);
365 __server_set_is_next_synthesis(true);
369 else if (event == TTSP_RESULT_EVENT_CANCEL) {
370 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
371 __server_set_is_synthesizing(false);
372 __server_set_is_next_synthesis(true);
376 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event ERROR");
377 __server_set_is_synthesizing(false);
378 __server_set_is_next_synthesis(true);
381 if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
382 if (NULL != utt_get_param)
386 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END");
387 SLOG(LOG_DEBUG, get_tag(), " ");
392 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
394 /* clear client data */
395 ttsd_data_clear_data(uid);
396 ttsd_data_set_client_state(uid, APP_STATE_READY);
399 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
401 ttsd_data_delete_client(uid);
408 void __config_lang_changed_cb(const char* language, int type)
411 ttsp_voice_type_e out_type;
414 if (true == ttsd_engine_select_valid_voice(language, type, &out_lang, &out_type)) {
415 SLOG(LOG_ERROR, get_tag(), "[Server] vaild language : lang(%s), type(%d)", out_lang, out_type);
416 ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
418 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type);
420 if (NULL == out_lang)
423 /* Current language is not available */
424 if (true == ttsd_engine_select_valid_voice("en_US", type, &out_lang, &out_type)) {
425 ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
427 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type);
429 if (NULL == out_lang)
442 int ttsd_initialize()
444 if (ttsd_config_initialize(__config_lang_changed_cb)) {
445 SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config.");
449 if (ttsd_player_init(__player_result_callback)) {
450 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to initialize player init.");
451 return TTSD_ERROR_OPERATION_FAILED;
454 /* Engine Agent initialize */
455 if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
456 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to engine agent initialize.");
457 return TTSD_ERROR_OPERATION_FAILED;
460 /* set current engine */
461 if (0 != ttsd_engine_agent_initialize_current_engine()) {
462 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!!" );
467 return TTSD_ERROR_NONE;
472 ttsd_config_finalize();
474 ttsd_player_release();
476 ttsd_engine_agent_release();
478 return TTSD_ERROR_NONE;
481 bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
485 result = ttsdc_send_hello(pid, uid);
488 SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) should be removed.", uid);
489 ttsd_server_finalize(uid);
490 } else if (-1 == result) {
491 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Hello result has error");
498 Eina_Bool ttsd_cleanup_client(void *data)
500 SLOG(LOG_DEBUG, get_tag(), "===== CLEAN UP CLIENT START");
501 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
502 SLOG(LOG_DEBUG, get_tag(), "=====");
503 SLOG(LOG_DEBUG, get_tag(), " ");
509 * TTS Server Functions for Client
512 int ttsd_server_initialize(int pid, int uid)
514 if (false == g_is_engine) {
515 if (0 != ttsd_engine_agent_initialize_current_engine()) {
516 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!! " );
519 return TTSD_ERROR_ENGINE_NOT_FOUND;
525 if (-1 != ttsd_data_is_client(uid)) {
526 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Uid has already been registered ");
527 return TTSD_ERROR_INVALID_PARAMETER;
530 if (0 == ttsd_data_get_client_count()) {
531 if (0 != ttsd_engine_agent_load_current_engine()) {
532 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine ");
533 return TTSD_ERROR_OPERATION_FAILED;
536 /* Check system language */
537 ttsd_config_update_language();
540 if (0 != ttsd_data_new_client(pid, uid)) {
541 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info ");
542 return TTSD_ERROR_OPERATION_FAILED;
545 if (0 != ttsd_player_create_instance(uid)) {
546 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to create player ");
547 return TTSD_ERROR_OPERATION_FAILED;
550 return TTSD_ERROR_NONE;
553 static Eina_Bool __quit_ecore_loop(void *data)
555 ecore_main_loop_quit();
556 SLOG(LOG_DEBUG, get_tag(), "[Server] quit ecore main loop");
560 int ttsd_server_finalize(int uid)
563 if (0 > ttsd_data_get_client_state(uid, &state)) {
564 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid ");
565 return TTSD_ERROR_INVALID_PARAMETER;
568 ttsd_server_stop(uid);
570 ttsd_player_destroy_instance(uid);
572 ttsd_data_delete_client(uid);
574 /* unload engine, if ref count of client is 0 */
575 if (0 == ttsd_data_get_client_count()) {
576 ecore_timer_add(0, __quit_ecore_loop, NULL);
579 return TTSD_ERROR_NONE;
582 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
585 if (0 > ttsd_data_get_client_state(uid, &state)) {
586 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
587 return TTSD_ERROR_INVALID_PARAMETER;
590 /* check valid voice */
591 char* temp_lang = NULL;
592 ttsp_voice_type_e temp_type;
593 if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
594 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to select valid voice ");
595 return TTSD_ERROR_INVALID_VOICE;
597 if (NULL == temp_lang)
603 data.lang = strdup(lang);
604 data.vctype = (ttsp_voice_type_e)voice_type;
606 data.speed = (ttsp_speed_e)speed;
607 data.utt_id = utt_id;
609 data.text = strdup(text);
611 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
612 if (0 != ttsd_data_add_speak_data(uid, data)) {
613 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
614 return TTSD_ERROR_OPERATION_FAILED;
617 if (APP_STATE_PLAYING == state) {
618 /* check if engine use network */
619 if (ttsd_engine_agent_need_network()) {
620 if (false == ttsd_network_is_connected()) {
621 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
622 return TTSD_ERROR_OPERATION_FAILED;
626 /* mode 2 for add text */
627 if (0 != __server_start_synthesis(uid, 2)) {
628 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to schedule synthesis : uid(%d)", uid);
629 return TTSD_ERROR_OPERATION_FAILED;
633 return TTSD_ERROR_NONE;
636 Eina_Bool __send_interrupt_client(void *data)
638 int* uid = (int*)data;
641 int pid = ttsd_data_get_pid(*uid);
642 /* send message to client about changing state */
643 ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
649 int ttsd_server_play(int uid)
652 if (0 > ttsd_data_get_client_state(uid, &state)) {
653 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
654 return TTSD_ERROR_INVALID_PARAMETER;
657 if (APP_STATE_PLAYING == state) {
658 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
659 return TTSD_ERROR_NONE;
662 /* check if engine use network */
663 if (ttsd_engine_agent_need_network()) {
664 if (false == ttsd_network_is_connected()) {
665 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
666 return TTSD_ERROR_OUT_OF_NETWORK;
670 int current_uid = ttsd_data_get_current_playing();
672 if (uid != current_uid && -1 != current_uid) {
673 /* Send interrupt message */
674 SLOG(LOG_DEBUG, get_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
677 if (0 != ttsd_player_pause(current_uid)) {
678 SLOG(LOG_WARN, get_tag(), "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
682 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
684 int* temp_uid = (int*)malloc(sizeof(int));
685 *temp_uid = current_uid;
686 ecore_timer_add(0, __send_interrupt_client, temp_uid);
689 /* Change current play */
690 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
691 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
692 return TTSD_ERROR_OPERATION_FAILED;
695 if (0 != __server_play_internal(uid, state)) {
696 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to start synthesis : uid(%d)", uid);
697 return TTSD_ERROR_OPERATION_FAILED;
700 ecore_timer_add(0, __start_next_synthesis, NULL);
702 return TTSD_ERROR_NONE;
706 int ttsd_server_stop(int uid)
709 if (0 > ttsd_data_get_client_state(uid, &state)) {
710 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
711 return TTSD_ERROR_INVALID_PARAMETER;
715 ttsd_data_clear_data(uid);
717 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
718 ttsd_data_set_client_state(uid, APP_STATE_READY);
720 if (0 != ttsd_player_stop(uid))
721 SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()");
723 if (true == __server_get_is_synthesizing()) {
724 SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
727 ret = ttsd_engine_cancel_synthesis();
729 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
731 __server_set_is_synthesizing(false);
734 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is 'ready' ");
737 return TTSD_ERROR_NONE;
740 int ttsd_server_pause(int uid, int* utt_id)
743 if (0 > ttsd_data_get_client_state(uid, &state)) {
744 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid ");
745 return TTSD_ERROR_INVALID_PARAMETER;
748 if (APP_STATE_PLAYING != state) {
749 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is not 'play' ");
750 return TTSD_ERROR_INVALID_STATE;
754 ret = ttsd_player_pause(uid);
756 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail player_pause() : ret(%d)", ret);
757 return TTSD_ERROR_OPERATION_FAILED;
760 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
762 return TTSD_ERROR_NONE;
765 int ttsd_server_get_support_voices(int uid, GList** voice_list)
768 if (0 > ttsd_data_get_client_state(uid, &state)) {
769 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
770 return TTSD_ERROR_INVALID_PARAMETER;
774 if (0 != ttsd_engine_get_voice_list(voice_list)) {
775 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() ");
776 return TTSD_ERROR_OPERATION_FAILED;
779 SLOG(LOG_DEBUG, get_tag(), "[Server SUCCESS] Get supported voices ");
781 return TTSD_ERROR_NONE;
784 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
787 if (0 > ttsd_data_get_client_state(uid, &state)) {
788 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
789 return TTSD_ERROR_INVALID_PARAMETER;
792 /* get current voice */
793 int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
795 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail ttsd_server_get_support_voices() ");
799 SLOG(LOG_DEBUG, get_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
801 return TTSD_ERROR_NONE;
806 * TTS Server Functions for Setting *
809 int ttsd_server_setting_initialize(int uid)
811 if (false == g_is_engine) {
812 if (0 != ttsd_engine_agent_initialize_current_engine()) {
813 SLOG(LOG_WARN, get_tag(), "[Server Setting WARNING] No Engine !!! " );
815 return TTSD_ERROR_ENGINE_NOT_FOUND;
821 if (-1 != ttsd_setting_data_is_setting(uid)) {
822 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] pid has already been registered ");
823 return TTSD_ERROR_INVALID_PARAMETER;
826 if (0 == ttsd_data_get_client_count()) {
827 if( 0 != ttsd_engine_agent_load_current_engine() ) {
828 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to load current engine ");
829 return TTSD_ERROR_OPERATION_FAILED;
834 if (0 != ttsd_setting_data_add(uid)) {
835 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to add client info ");
836 return TTSD_ERROR_OPERATION_FAILED;
839 return TTSD_ERROR_NONE;
842 int ttsd_server_setting_finalize(int uid)
844 if (-1 == ttsd_setting_data_is_setting(uid)) {
845 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
846 return TTSD_ERROR_INVALID_PARAMETER;
849 ttsd_setting_data_delete(uid);
851 /* unload engine, if ref count of client is 0 */
852 if (0 == ttsd_data_get_client_count()) {
853 ecore_timer_add(0, __quit_ecore_loop, NULL);
856 return TTSD_ERROR_NONE;
859 int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
861 if (-1 == ttsd_setting_data_is_setting(uid)) {
862 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
863 return TTSD_ERROR_INVALID_PARAMETER;
867 ret = ttsd_engine_setting_get_engine_list(engine_list);
869 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
873 return TTSD_ERROR_NONE;
876 int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
878 if (-1 == ttsd_setting_data_is_setting(uid)) {
879 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
880 return TTSD_ERROR_INVALID_PARAMETER;
884 ret = ttsd_engine_setting_get_engine(engine_id);
886 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
890 return TTSD_ERROR_NONE;
893 int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
895 /* check if uid is valid */
896 if (-1 == ttsd_setting_data_is_setting(uid)) {
897 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
898 return TTSD_ERROR_INVALID_PARAMETER;
901 if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
902 SLOG(LOG_DEBUG, get_tag(), "[Server Setting] new engine is the same as current engine ");
903 return TTSD_ERROR_NONE;
906 /* stop all player */
907 ttsd_player_all_stop();
909 /* send interrupt message to all clients */
910 ttsd_data_foreach_clients(__get_client_cb, NULL);
914 ret = ttsd_engine_setting_set_engine(engine_id);
916 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
920 return TTSD_ERROR_NONE;
923 int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
925 /* check if uid is valid */
926 if (-1 == ttsd_setting_data_is_setting(uid)) {
927 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
928 return TTSD_ERROR_INVALID_PARAMETER;
931 /* get language list from engine */
933 ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
935 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
939 return TTSD_ERROR_NONE;
942 int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
944 /* check if uid is valid */
945 if (-1 == ttsd_setting_data_is_setting(uid)) {
946 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
947 return TTSD_ERROR_INVALID_PARAMETER;
951 ret = ttsd_engine_setting_get_default_voice(language, vctype);
953 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
957 return TTSD_ERROR_NONE;
960 int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
962 /* check if uid is valid */
963 if (-1 == ttsd_setting_data_is_setting(uid)) {
964 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
965 return TTSD_ERROR_INVALID_PARAMETER;
968 /* set current language */
970 ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
972 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
976 return TTSD_ERROR_NONE;
979 int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
981 /* check if uid is valid */
982 if (-1 == ttsd_setting_data_is_setting(uid)) {
983 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
984 return TTSD_ERROR_INVALID_PARAMETER;
988 ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
990 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
994 return TTSD_ERROR_NONE;
997 int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
999 /* check if uid is valid */
1000 if (-1 == ttsd_setting_data_is_setting(uid)) {
1001 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
1002 return TTSD_ERROR_INVALID_PARAMETER;
1006 ret = ttsd_engine_setting_set_engine_setting(key, value);
1008 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
1012 return TTSD_ERROR_NONE;
1015 int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
1017 /* check if uid is valid */
1018 if (-1 == ttsd_setting_data_is_setting(uid)) {
1019 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
1020 return TTSD_ERROR_INVALID_PARAMETER;
1023 /* get current speed */
1025 ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
1027 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
1031 return TTSD_ERROR_NONE;
1034 int ttsd_server_setting_set_default_speed(int uid, int default_speed)
1036 /* check if uid is valid */
1037 if (-1 == ttsd_setting_data_is_setting(uid)) {
1038 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
1039 return TTSD_ERROR_INVALID_PARAMETER;
1042 /* set default speed */
1044 ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
1046 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
1050 return TTSD_ERROR_NONE;