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"
27 TTSD_SYNTHESIS_CONTROL_DOING = 0,
28 TTSD_SYNTHESIS_CONTROL_DONE = 1,
29 TTSD_SYNTHESIS_CONTROL_EXPIRED = 2
30 }ttsd_synthesis_control_e;
37 /* If current engine exist */
38 static bool g_is_engine;
40 /* If engine is running */
41 static ttsd_synthesis_control_e g_synth_control;
43 static Ecore_Timer* g_wait_timer = NULL;
45 /* Function definitions */
46 int __server_next_synthesis(int uid);
49 int __server_set_synth_control(ttsd_synthesis_control_e control)
51 g_synth_control = control;
55 ttsd_synthesis_control_e __server_get_synth_control()
57 return g_synth_control;
60 int __server_send_error(int uid, int utt_id, int error_code)
62 int pid = ttsd_data_get_pid(uid);
65 if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) {
66 ttsd_data_delete_client(uid);
72 Eina_Bool __wait_synthesis(void *data)
74 /* get current play */
75 int uid = ttsd_data_is_current_playing();
78 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
82 if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
83 /* Start next synthesis */
84 __server_next_synthesis(uid);
94 int __synthesis(int uid)
97 if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
99 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
102 SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] fail to allocate memory : utterance ", __FUNCTION__);
103 return TTSD_ERROR_OUT_OF_MEMORY;
107 utt->uttid = sdata.utt_id;
109 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
110 SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
111 SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
112 SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
113 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
116 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
117 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
119 SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
121 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
123 ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis");
127 ttsd_server_stop(uid);
129 int pid = ttsd_data_get_pid(uid);
130 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
132 g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
135 if(sdata.text != NULL)
138 SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
139 SLOG(LOG_DEBUG, get_tag(), "[Server] Text queue is empty.");
140 SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
146 int __server_next_synthesis(int uid)
148 SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START");
150 /* get current playing client */
151 int current_uid = ttsd_data_get_current_playing();
153 if (0 > current_uid) {
154 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid");
155 SLOG(LOG_DEBUG, get_tag(), "=====");
156 SLOG(LOG_DEBUG, get_tag(), " ");
160 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
161 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. ");
162 SLOG(LOG_DEBUG, get_tag(), "=====");
163 SLOG(LOG_DEBUG, get_tag(), " ");
167 __synthesis(current_uid);
169 if (0 != ttsd_player_play(current_uid)) {
170 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
172 /* success playing */
173 SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
176 SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY END");
177 SLOG(LOG_DEBUG, get_tag(), " ");
183 * TTS Server Callback Functions
186 int __player_result_callback(player_event_e event, int uid, int utt_id)
190 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR][%s] player result error", __FUNCTION__);
191 __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
192 ttsd_config_save_error(uid, utt_id, NULL, -1, NULL, __FUNCTION__, __LINE__, "PLAYER_ERROR");
194 case PLAYER_EMPTY_SOUND_QUEUE:
195 /* check whether synthesis is running */
196 if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
197 /* check text queue is empty */
198 if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
199 SLOG(LOG_DEBUG, get_tag(), "[SERVER Callback] all play completed ");
204 case PLAYER_END_OF_PLAYING:
211 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
213 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK START");
215 utterance_t* utt_get_param;
216 utt_get_param = (utterance_t*)user_data;
218 if (NULL == utt_get_param) {
219 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] User data is NULL " );
220 SLOG(LOG_DEBUG, get_tag(), "=====");
221 SLOG(LOG_DEBUG, get_tag(), " ");
225 int uid = utt_get_param->uid;
226 int uttid = utt_get_param->uttid;
228 /* Synthesis is success */
229 if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
231 if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_START");
232 if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
233 if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
235 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
236 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
237 SLOG(LOG_DEBUG, get_tag(), "=====");
238 SLOG(LOG_DEBUG, get_tag(), " ");
243 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) ",
244 uid, uttid, data, data_size);
247 sound_data_s temp_data;
248 temp_data.data = (char*)g_malloc0( sizeof(char) * data_size );
249 memcpy(temp_data.data, data, data_size);
251 temp_data.data_size = data_size;
252 temp_data.utt_id = utt_get_param->uttid;
253 temp_data.event = event;
255 ttsp_audio_type_e audio_type;
259 if (ttsd_engine_get_audio_format(&audio_type, &rate, &channels)) {
260 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get audio format ");
261 SLOG(LOG_DEBUG, get_tag(), "=====");
262 SLOG(LOG_DEBUG, get_tag(), " ");
266 temp_data.audio_type = audio_type;
267 temp_data.rate = rate;
268 temp_data.channels = channels;
270 if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
271 SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", utt_get_param->uid);
274 if (event == TTSP_RESULT_EVENT_FINISH) {
275 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
277 } else if (event == TTSP_RESULT_EVENT_CANCEL) {
278 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
279 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
281 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_ERROR");
282 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
285 if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
286 if (NULL != utt_get_param)
290 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END");
291 SLOG(LOG_DEBUG, get_tag(), " ");
294 if (true == __server_get_is_next_synthesis()) {
295 __server_set_is_next_synthesis(false);
297 /* Do NOT work ecore timer because of This function is thread callbacked */
298 /* need to send dbus message event */
299 ttsd_send_start_next_synthesis();
306 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
308 /* clear client data */
309 ttsd_data_clear_data(uid);
310 ttsd_data_set_client_state(uid, APP_STATE_READY);
313 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
315 ttsd_data_delete_client(uid);
321 void __config_lang_changed_cb(const char* language, int type)
324 ttsp_voice_type_e out_type;
327 if (true == ttsd_engine_select_valid_voice(language, type, &out_lang, &out_type)) {
328 SLOG(LOG_ERROR, get_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
329 ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
331 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type);
333 if (NULL == out_lang)
336 /* Current language is not available */
337 if (true == ttsd_engine_select_valid_voice("en_US", type, &out_lang, &out_type)) {
338 ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
340 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
342 if (NULL == out_lang)
355 int ttsd_initialize()
357 if (ttsd_config_initialize(__config_lang_changed_cb)) {
358 SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config.");
362 if (ttsd_player_init(__player_result_callback)) {
363 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to initialize player init.");
364 return TTSD_ERROR_OPERATION_FAILED;
367 /* Engine Agent initialize */
368 if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
369 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to engine agent initialize.");
370 return TTSD_ERROR_OPERATION_FAILED;
373 /* set current engine */
374 if (0 != ttsd_engine_agent_initialize_current_engine()) {
375 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!!" );
380 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
382 return TTSD_ERROR_NONE;
387 ttsd_config_finalize();
389 ttsd_player_release();
391 ttsd_engine_agent_release();
393 return TTSD_ERROR_NONE;
396 bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
400 result = ttsdc_send_hello(pid, uid);
403 SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) should be removed.", uid);
404 ttsd_server_finalize(uid);
405 } else if (-1 == result) {
406 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Hello result has error");
413 Eina_Bool ttsd_cleanup_client(void *data)
415 SLOG(LOG_DEBUG, get_tag(), "===== CLEAN UP CLIENT START");
416 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
417 SLOG(LOG_DEBUG, get_tag(), "=====");
418 SLOG(LOG_DEBUG, get_tag(), " ");
424 * TTS Server Functions for Client
427 int ttsd_server_initialize(int pid, int uid)
429 if (false == g_is_engine) {
430 if (0 != ttsd_engine_agent_initialize_current_engine()) {
431 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!! " );
434 return TTSD_ERROR_ENGINE_NOT_FOUND;
440 if (-1 != ttsd_data_is_client(uid)) {
441 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Uid has already been registered ");
442 return TTSD_ERROR_INVALID_PARAMETER;
445 if (0 == ttsd_data_get_client_count()) {
446 if (0 != ttsd_engine_agent_load_current_engine()) {
447 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine ");
448 return TTSD_ERROR_OPERATION_FAILED;
450 /* Check system language */
451 ttsd_config_update_language();
454 if (0 == ttsd_data_get_same_pid_client_count(pid)) {
455 SLOG(LOG_DEBUG, get_tag(), "[Server] open file msg connection");
456 if (0 != ttsd_file_msg_open_connection(pid)) {
457 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to open file message connection");
458 return TTSD_ERROR_OPERATION_FAILED;
462 if (0 != ttsd_data_new_client(pid, uid)) {
463 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info ");
464 return TTSD_ERROR_OPERATION_FAILED;
467 if (0 != ttsd_player_create_instance(uid)) {
468 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to create player ");
469 return TTSD_ERROR_OPERATION_FAILED;
472 return TTSD_ERROR_NONE;
475 static Eina_Bool __quit_ecore_loop(void *data)
477 ecore_main_loop_quit();
478 SLOG(LOG_DEBUG, get_tag(), "[Server] quit ecore main loop");
482 int ttsd_server_finalize(int uid)
485 if (0 > ttsd_data_get_client_state(uid, &state)) {
486 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid ");
487 return TTSD_ERROR_INVALID_PARAMETER;
490 ttsd_server_stop(uid);
492 ttsd_player_destroy_instance(uid);
494 int pid = ttsd_data_get_pid(uid);
496 ttsd_data_delete_client(uid);
498 if (0 == ttsd_data_get_same_pid_client_count(pid)) {
499 SLOG(LOG_DEBUG, get_tag(), "[Sever] File msg close connection");
500 ttsd_file_msg_close_connection(pid);
503 /* unload engine, if ref count of client is 0 */
504 if (0 == ttsd_data_get_client_count()) {
505 ecore_timer_add(0, __quit_ecore_loop, NULL);
508 return TTSD_ERROR_NONE;
511 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
514 if (0 > ttsd_data_get_client_state(uid, &state)) {
515 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
516 return TTSD_ERROR_INVALID_PARAMETER;
519 /* check valid voice */
520 char* temp_lang = NULL;
521 ttsp_voice_type_e temp_type;
522 if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
523 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to select valid voice ");
524 return TTSD_ERROR_INVALID_VOICE;
526 if (NULL == temp_lang)
532 data.lang = strdup(lang);
533 data.vctype = (ttsp_voice_type_e)voice_type;
535 data.speed = (ttsp_speed_e)speed;
536 data.utt_id = utt_id;
538 data.text = strdup(text);
540 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
541 if (0 != ttsd_data_add_speak_data(uid, data)) {
542 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
543 return TTSD_ERROR_OPERATION_FAILED;
546 if (APP_STATE_PLAYING == state) {
547 /* check if engine use network */
548 if (ttsd_engine_agent_need_network()) {
549 if (false == ttsd_network_is_connected()) {
550 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
551 return TTSD_ERROR_OPERATION_FAILED;
555 /* Check whether tts-engine is running or not */
556 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
557 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
563 return TTSD_ERROR_NONE;
566 Eina_Bool __send_interrupt_client(void *data)
568 int* uid = (int*)data;
571 int pid = ttsd_data_get_pid(*uid);
572 /* send message to client about changing state */
573 ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
579 int ttsd_server_play(int uid)
582 if (0 > ttsd_data_get_client_state(uid, &state)) {
583 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
584 return TTSD_ERROR_INVALID_PARAMETER;
587 if (APP_STATE_PLAYING == state) {
588 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
589 return TTSD_ERROR_NONE;
592 /* check if engine use network */
593 if (ttsd_engine_agent_need_network()) {
594 if (false == ttsd_network_is_connected()) {
595 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
596 return TTSD_ERROR_OUT_OF_NETWORK;
600 int current_uid = ttsd_data_get_current_playing();
602 if (uid != current_uid && -1 != current_uid) {
603 /* Send interrupt message */
604 SLOG(LOG_DEBUG, get_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
607 if (0 != ttsd_player_pause(current_uid)) {
608 SLOG(LOG_WARN, get_tag(), "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
612 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
614 int* temp_uid = (int*)malloc(sizeof(int));
615 *temp_uid = current_uid;
616 ecore_timer_add(0, __send_interrupt_client, temp_uid);
619 /* Change current play */
620 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
621 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
622 return TTSD_ERROR_OPERATION_FAILED;
625 if (APP_STATE_PAUSED == state) {
626 SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
628 ttsd_player_state_e state;
629 if (0 != ttsd_player_get_state(uid, &state)) {
630 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get player state : uid(%d)", uid);
631 return TTSD_ERROR_OPERATION_FAILED;
634 if (TTSD_PLAYER_STATE_PAUSED == state) {
636 if (0 != ttsd_player_resume(uid)) {
637 SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()");
639 } else if (TTSD_PLAYER_STATE_NULL == state) {
640 if (0 != ttsd_player_play(uid)) {
641 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
643 /* Need to wait synthesis */
644 if (NULL == g_wait_timer)
645 g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
647 /* success playing */
648 SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
655 /* Check whether tts-engine is running or not */
656 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
657 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
662 return TTSD_ERROR_NONE;
666 int ttsd_server_stop(int uid)
669 if (0 > ttsd_data_get_client_state(uid, &state)) {
670 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
671 return TTSD_ERROR_INVALID_PARAMETER;
675 ttsd_data_clear_data(uid);
677 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
678 ttsd_data_set_client_state(uid, APP_STATE_READY);
680 if (0 != ttsd_player_stop(uid))
681 SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()");
683 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
684 SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
687 ret = ttsd_engine_cancel_synthesis();
689 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
692 if (NULL != g_wait_timer) {
693 SLOG(LOG_DEBUG, get_tag(), "Wait timer is deleted");
694 ecore_timer_del(g_wait_timer);
697 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
699 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is 'ready' ");
702 return TTSD_ERROR_NONE;
705 int ttsd_server_pause(int uid, int* utt_id)
708 if (0 > ttsd_data_get_client_state(uid, &state)) {
709 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid ");
710 return TTSD_ERROR_INVALID_PARAMETER;
713 if (APP_STATE_PLAYING != state) {
714 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is not 'play' ");
715 return TTSD_ERROR_INVALID_STATE;
719 ret = ttsd_player_pause(uid);
721 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail player_pause() : ret(%d)", ret);
722 return TTSD_ERROR_OPERATION_FAILED;
725 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
727 return TTSD_ERROR_NONE;
730 int ttsd_server_get_support_voices(int uid, GList** voice_list)
733 if (0 > ttsd_data_get_client_state(uid, &state)) {
734 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid ");
735 return TTSD_ERROR_INVALID_PARAMETER;
739 if (0 != ttsd_engine_get_voice_list(voice_list)) {
740 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices() ");
741 return TTSD_ERROR_OPERATION_FAILED;
744 SLOG(LOG_DEBUG, get_tag(), "[Server SUCCESS] Get supported voices ");
746 return TTSD_ERROR_NONE;
749 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
752 if (0 > ttsd_data_get_client_state(uid, &state)) {
753 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
754 return TTSD_ERROR_INVALID_PARAMETER;
757 /* get current voice */
758 int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
760 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail ttsd_server_get_support_voices() ");
764 SLOG(LOG_DEBUG, get_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
766 return TTSD_ERROR_NONE;
771 * Server API for Internal event
773 int ttsd_server_start_next_synthesis()
775 /* get current play */
776 int uid = ttsd_data_is_current_playing();
782 return __server_next_synthesis(uid);
787 * TTS Server Functions for Setting *
790 int ttsd_server_setting_initialize(int uid)
792 if (false == g_is_engine) {
793 if (0 != ttsd_engine_agent_initialize_current_engine()) {
794 SLOG(LOG_WARN, get_tag(), "[Server Setting WARNING] No Engine !!! " );
796 return TTSD_ERROR_ENGINE_NOT_FOUND;
802 if (-1 != ttsd_setting_data_is_setting(uid)) {
803 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] pid has already been registered ");
804 return TTSD_ERROR_INVALID_PARAMETER;
807 if (0 == ttsd_data_get_client_count()) {
808 if( 0 != ttsd_engine_agent_load_current_engine() ) {
809 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to load current engine ");
810 return TTSD_ERROR_OPERATION_FAILED;
815 if (0 != ttsd_setting_data_add(uid)) {
816 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to add client info ");
817 return TTSD_ERROR_OPERATION_FAILED;
820 return TTSD_ERROR_NONE;
823 int ttsd_server_setting_finalize(int uid)
825 if (-1 == ttsd_setting_data_is_setting(uid)) {
826 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
827 return TTSD_ERROR_INVALID_PARAMETER;
830 ttsd_setting_data_delete(uid);
832 /* unload engine, if ref count of client is 0 */
833 if (0 == ttsd_data_get_client_count()) {
834 ecore_timer_add(0, __quit_ecore_loop, NULL);
837 return TTSD_ERROR_NONE;
840 int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
842 if (-1 == ttsd_setting_data_is_setting(uid)) {
843 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
844 return TTSD_ERROR_INVALID_PARAMETER;
848 ret = ttsd_engine_setting_get_engine_list(engine_list);
850 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
854 return TTSD_ERROR_NONE;
857 int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
859 if (-1 == ttsd_setting_data_is_setting(uid)) {
860 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
861 return TTSD_ERROR_INVALID_PARAMETER;
865 ret = ttsd_engine_setting_get_engine(engine_id);
867 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
871 return TTSD_ERROR_NONE;
874 int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
876 /* check if uid is valid */
877 if (-1 == ttsd_setting_data_is_setting(uid)) {
878 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
879 return TTSD_ERROR_INVALID_PARAMETER;
882 if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
883 SLOG(LOG_DEBUG, get_tag(), "[Server Setting] new engine is the same as current engine ");
884 return TTSD_ERROR_NONE;
887 /* stop all player */
888 ttsd_player_all_stop();
890 /* send interrupt message to all clients */
891 ttsd_data_foreach_clients(__get_client_cb, NULL);
893 ttsd_engine_cancel_synthesis();
897 ret = ttsd_engine_setting_set_engine(engine_id);
899 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
903 return TTSD_ERROR_NONE;
906 int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
908 /* check if uid is valid */
909 if (-1 == ttsd_setting_data_is_setting(uid)) {
910 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
911 return TTSD_ERROR_INVALID_PARAMETER;
914 /* get language list from engine */
916 ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
918 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
922 return TTSD_ERROR_NONE;
925 int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
927 /* check if uid is valid */
928 if (-1 == ttsd_setting_data_is_setting(uid)) {
929 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
930 return TTSD_ERROR_INVALID_PARAMETER;
934 ret = ttsd_engine_setting_get_default_voice(language, vctype);
936 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
940 return TTSD_ERROR_NONE;
943 int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
945 /* check if uid is valid */
946 if (-1 == ttsd_setting_data_is_setting(uid)) {
947 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
948 return TTSD_ERROR_INVALID_PARAMETER;
951 /* set current language */
953 ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
955 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
959 return TTSD_ERROR_NONE;
962 int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
964 /* check if uid is valid */
965 if (-1 == ttsd_setting_data_is_setting(uid)) {
966 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
967 return TTSD_ERROR_INVALID_PARAMETER;
971 ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
973 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
977 return TTSD_ERROR_NONE;
980 int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
982 /* check if uid is valid */
983 if (-1 == ttsd_setting_data_is_setting(uid)) {
984 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
985 return TTSD_ERROR_INVALID_PARAMETER;
989 ret = ttsd_engine_setting_set_engine_setting(key, value);
991 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
995 return TTSD_ERROR_NONE;
998 int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
1000 /* check if uid is valid */
1001 if (-1 == ttsd_setting_data_is_setting(uid)) {
1002 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
1003 return TTSD_ERROR_INVALID_PARAMETER;
1006 /* get current speed */
1008 ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
1010 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
1014 return TTSD_ERROR_NONE;
1017 int ttsd_server_setting_set_default_speed(int uid, int default_speed)
1019 /* check if uid is valid */
1020 if (-1 == ttsd_setting_data_is_setting(uid)) {
1021 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] uid is not valid (%s)", uid);
1022 return TTSD_ERROR_INVALID_PARAMETER;
1025 /* set default speed */
1027 ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
1029 SLOG(LOG_ERROR, get_tag(), "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
1033 return TTSD_ERROR_NONE;