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;
52 bool __server_get_is_synthesizing()
54 return g_is_synthesizing;
57 int __server_set_is_next_synthesis(bool flag)
59 g_is_next_synthesis = flag;
64 bool __server_get_is_next_synthesis()
66 return g_is_next_synthesis;
69 int __server_send_error(int uid, int utt_id, int error_code)
71 int pid = ttsd_data_get_pid(uid);
74 if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) {
75 ttsd_data_delete_client(uid);
81 int __server_start_synthesis(int uid, int mode)
85 /* check if tts-engine is running */
86 if (true == __server_get_is_synthesizing()) {
87 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] TTS-engine is running ");
90 if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
91 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
94 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Out of memory : utterance ");
95 return TTSD_ERROR_OUT_OF_MEMORY;
99 utt->uttid = sdata.utt_id;
101 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
102 SLOG(LOG_DEBUG, TAG_TTSD, "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
103 SLOG(LOG_DEBUG, TAG_TTSD, "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
104 SLOG(LOG_DEBUG, TAG_TTSD, "Text : %s", sdata.text);
105 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
107 __server_set_is_synthesizing(true);
109 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
111 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
113 __server_set_is_synthesizing(false);
115 result = TTSD_ERROR_OPERATION_FAILED;
120 __server_send_error(uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
121 ttsd_server_stop(uid);
123 int pid = ttsd_data_get_pid(uid);
124 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
127 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] SUCCESS to start synthesis");
130 if(sdata.text != NULL)
134 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Text List is EMPTY!! ");
141 int __server_play_internal(int uid, app_state_e state)
145 /* - input uid is current play */
149 if (APP_STATE_PAUSED == state) {
151 SLOG(LOG_DEBUG, TAG_TTSD, "[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, TAG_TTSD, "[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, TAG_TTSD, "[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, TAG_TTSD, "===== 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, TAG_TTSD, "[Server WARNING] Current uid is not valid");
182 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
183 SLOG(LOG_DEBUG, TAG_TTSD, " ");
187 if (true == __server_get_is_synthesizing()) {
188 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Engine has already been running. ");
189 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
190 SLOG(LOG_DEBUG, TAG_TTSD, " ");
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, TAG_TTSD, "[Server ERROR] fail to allocate memory : utterance ");
203 __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OUT_OF_MEMORY);
204 return TTSD_ERROR_OUT_OF_MEMORY;
207 utt->uid = current_uid;
208 utt->uttid = sdata.utt_id;
210 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
211 SLOG(LOG_DEBUG, TAG_TTSD, "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
212 SLOG(LOG_DEBUG, TAG_TTSD, "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
213 SLOG(LOG_DEBUG, TAG_TTSD, "Text : %s", sdata.text);
214 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
216 __server_set_is_synthesizing(true);
219 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
221 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
223 __server_set_is_synthesizing(false);
225 __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
229 ttsd_server_stop(current_uid);
231 int pid = ttsd_data_get_pid(current_uid);
232 ttsdc_send_set_state_message(pid, current_uid, APP_STATE_READY);
235 if(sdata.text != NULL)
238 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] --------------------");
239 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Text queue is empty.");
240 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] --------------------");
243 if (0 != ttsd_player_play(current_uid)) {
244 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] __server_next_synthesis : fail ttsd_player_play() ");
246 /* success playing */
247 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Success to start player");
250 SLOG(LOG_DEBUG, TAG_TTSD, "===== NEXT SYNTHESIS & PLAY END");
251 SLOG(LOG_DEBUG, TAG_TTSD, " ");
257 * TTS Server Callback Functions
260 int __player_result_callback(player_event_e event, int uid, int utt_id)
263 case PLAYER_EMPTY_SOUND_QUEUE:
264 /* check whether synthesis is running */
265 if (false == __server_get_is_synthesizing()) {
266 /* check text queue is empty */
267 if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
268 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER Callback] all play completed ");
274 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER Callback ERROR] callback : player error ");
276 __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
279 case PLAYER_END_OF_PLAYING:
286 Eina_Bool __start_next_synthesis(void *data)
288 /* get current play */
289 int uid = ttsd_data_is_current_playing();
295 if (true == __server_get_is_next_synthesis()) {
296 __server_set_is_next_synthesis(false);
297 __server_next_synthesis(uid);
303 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
305 SLOG(LOG_DEBUG, TAG_TTSD, "===== SYNTHESIS RESULT CALLBACK START");
307 utterance_t* utt_get_param;
308 utt_get_param = (utterance_t*)user_data;
310 if (NULL == utt_get_param) {
311 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] User data is NULL " );
312 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
313 SLOG(LOG_DEBUG, TAG_TTSD, " ");
317 int uid = utt_get_param->uid;
318 int uttid = utt_get_param->uttid;
320 /* Synthesis is success */
321 if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
323 if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_START");
324 if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
325 if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
327 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
328 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
329 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
330 SLOG(LOG_DEBUG, TAG_TTSD, " ");
335 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) ",
336 uid, uttid, data, data_size);
339 sound_data_s temp_data;
340 temp_data.data = (char*)g_malloc0( sizeof(char) * data_size );
341 memcpy(temp_data.data, data, data_size);
343 temp_data.data_size = data_size;
344 temp_data.utt_id = utt_get_param->uttid;
345 temp_data.event = event;
347 ttsp_audio_type_e audio_type;
351 if (ttsd_engine_get_audio_format(&audio_type, &rate, &channels)) {
352 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to get audio format ");
353 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
354 SLOG(LOG_DEBUG, TAG_TTSD, " ");
358 temp_data.audio_type = audio_type;
359 temp_data.rate = rate;
360 temp_data.channels = channels;
362 if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
363 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] Fail to add sound data : uid(%d)", utt_get_param->uid);
366 if (event == TTSP_RESULT_EVENT_FINISH) {
367 __server_set_is_synthesizing(false);
368 __server_set_is_next_synthesis(true);
372 else if (event == TTSP_RESULT_EVENT_CANCEL) {
373 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
374 __server_set_is_synthesizing(false);
375 __server_set_is_next_synthesis(true);
379 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event ERROR");
380 __server_set_is_synthesizing(false);
381 __server_set_is_next_synthesis(true);
384 if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
385 if (NULL != utt_get_param)
389 SLOG(LOG_DEBUG, TAG_TTSD, "===== SYNTHESIS RESULT CALLBACK END");
390 SLOG(LOG_DEBUG, TAG_TTSD, " ");
399 int ttsd_initialize()
401 if (ttsd_config_initialize()) {
402 SLOG(LOG_ERROR, TAG_TTSD, "[Server WARNING] Fail to initialize config.");
406 if (ttsd_player_init(__player_result_callback)) {
407 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to initialize player init.");
408 return TTSD_ERROR_OPERATION_FAILED;
411 /* Engine Agent initialize */
412 if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
413 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to engine agent initialize.");
414 return TTSD_ERROR_OPERATION_FAILED;
417 /* set current engine */
418 if (0 != ttsd_engine_agent_initialize_current_engine()) {
419 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] No Engine !!!" );
425 return TTSD_ERROR_NONE;
429 bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
433 result = ttsdc_send_hello(pid, uid);
436 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] uid(%d) should be removed.", uid);
437 ttsd_server_finalize(uid);
438 } else if (-1 == result) {
439 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Hello result has error");
446 Eina_Bool ttsd_cleanup_client(void *data)
448 SLOG(LOG_DEBUG, TAG_TTSD, "===== CLEAN UP CLIENT START");
449 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
450 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
451 SLOG(LOG_DEBUG, TAG_TTSD, " ");
457 * TTS Server Functions for Client
460 int ttsd_server_initialize(int pid, int uid)
462 if (false == g_is_engine) {
463 if (0 != ttsd_engine_agent_initialize_current_engine()) {
464 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] No Engine !!! " );
467 return TTSD_ERROR_ENGINE_NOT_FOUND;
473 if (-1 != ttsd_data_is_client(uid)) {
474 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Uid has already been registered ");
475 return TTSD_ERROR_INVALID_PARAMETER;
478 if (0 == ttsd_data_get_client_count()) {
479 if (0 != ttsd_engine_agent_load_current_engine()) {
480 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to load current engine ");
481 return TTSD_ERROR_OPERATION_FAILED;
485 if (0 != ttsd_data_new_client(pid, uid)) {
486 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to add client info ");
487 return TTSD_ERROR_OPERATION_FAILED;
490 if (0 != ttsd_player_create_instance(uid)) {
491 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to create player ");
492 return TTSD_ERROR_OPERATION_FAILED;
495 return TTSD_ERROR_NONE;
498 static Eina_Bool __quit_ecore_loop(void *data)
500 ecore_main_loop_quit();
501 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] quit ecore main loop");
505 int ttsd_server_finalize(int uid)
508 if (0 > ttsd_data_get_client_state(uid, &state)) {
509 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_finalize : uid is not valid ");
510 return TTSD_ERROR_INVALID_PARAMETER;
513 ttsd_server_stop(uid);
515 ttsd_player_destroy_instance(uid);
517 ttsd_data_delete_client(uid);
519 /* unload engine, if ref count of client is 0 */
520 if (0 == ttsd_data_get_client_count()) {
521 if (0 != ttsd_engine_agent_release()) {
522 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to release engine agent");
524 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] release engine agent");
527 ecore_timer_add(0, __quit_ecore_loop, NULL);
530 return TTSD_ERROR_NONE;
533 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
536 if (0 > ttsd_data_get_client_state(uid, &state)) {
537 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
538 return TTSD_ERROR_INVALID_PARAMETER;
541 /* check valid voice */
542 char* temp_lang = NULL;
543 ttsp_voice_type_e temp_type;
544 if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
545 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to select valid voice ");
546 return TTSD_ERROR_INVALID_VOICE;
548 if (NULL == temp_lang)
554 data.lang = strdup(lang);
555 data.vctype = (ttsp_voice_type_e)voice_type;
557 data.speed = (ttsp_speed_e)speed;
558 data.utt_id = utt_id;
560 data.text = strdup(text);
562 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
563 if (0 != ttsd_data_add_speak_data(uid, data)) {
564 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
565 return TTSD_ERROR_OPERATION_FAILED;
568 if (APP_STATE_PLAYING == state) {
569 /* check if engine use network */
570 if (ttsd_engine_agent_need_network()) {
571 if (false == ttsd_network_is_connected()) {
572 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network.");
573 return TTSD_ERROR_OPERATION_FAILED;
577 /* mode 2 for add text */
578 if (0 != __server_start_synthesis(uid, 2)) {
579 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to schedule synthesis : uid(%d)", uid);
580 return TTSD_ERROR_OPERATION_FAILED;
584 return TTSD_ERROR_NONE;
587 Eina_Bool __send_interrupt_client(void *data)
589 int* uid = (int*)data;
592 int pid = ttsd_data_get_pid(*uid);
593 /* send message to client about changing state */
594 ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
600 int ttsd_server_play(int uid)
603 if (0 > ttsd_data_get_client_state(uid, &state)) {
604 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid(%d) is NOT valid ", uid);
605 return TTSD_ERROR_INVALID_PARAMETER;
608 if (APP_STATE_PLAYING == state) {
609 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state(%d) is 'play' ", uid);
610 return TTSD_ERROR_NONE;
613 /* check if engine use network */
614 if (ttsd_engine_agent_need_network()) {
615 if (false == ttsd_network_is_connected()) {
616 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
617 return TTSD_ERROR_OUT_OF_NETWORK;
621 int current_uid = ttsd_data_get_current_playing();
623 if (uid != current_uid && -1 != current_uid) {
624 /* Send interrupt message */
625 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
628 if (0 != ttsd_player_pause(current_uid)) {
629 SLOG(LOG_WARN, TAG_TTSD, "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
633 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
635 int* temp_uid = (int*)malloc(sizeof(int));
636 *temp_uid = current_uid;
637 ecore_timer_add(0, __send_interrupt_client, temp_uid);
640 /* Change current play */
641 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
642 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to set state : uid(%d)", uid);
643 return TTSD_ERROR_OPERATION_FAILED;
646 if (0 != __server_play_internal(uid, state)) {
647 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to start synthesis : uid(%d)", uid);
648 return TTSD_ERROR_OPERATION_FAILED;
651 ecore_timer_add(0, __start_next_synthesis, NULL);
653 return TTSD_ERROR_NONE;
657 int ttsd_server_stop(int uid)
660 if (0 > ttsd_data_get_client_state(uid, &state)) {
661 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
662 return TTSD_ERROR_INVALID_PARAMETER;
666 ttsd_data_clear_data(uid);
668 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
669 ttsd_data_set_client_state(uid, APP_STATE_READY);
671 if (0 != ttsd_player_stop(uid))
672 SLOG(LOG_WARN, TAG_TTSD, "[Server] Fail to ttsd_player_stop()");
674 if (true == __server_get_is_synthesizing()) {
675 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] TTS-engine is running ");
678 ret = ttsd_engine_cancel_synthesis();
680 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
682 __server_set_is_synthesizing(false);
685 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is 'ready' ");
688 return TTSD_ERROR_NONE;
691 int ttsd_server_pause(int uid, int* utt_id)
694 if (0 > ttsd_data_get_client_state(uid, &state)) {
695 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_pause : uid is not valid ");
696 return TTSD_ERROR_INVALID_PARAMETER;
699 if (APP_STATE_PLAYING != state) {
700 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is not 'play' ");
701 return TTSD_ERROR_INVALID_STATE;
705 ret = ttsd_player_pause(uid);
707 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail player_pause() : ret(%d)", ret);
708 return TTSD_ERROR_OPERATION_FAILED;
711 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
713 return TTSD_ERROR_NONE;
716 int ttsd_server_get_support_voices(int uid, GList** voice_list)
719 if (0 > ttsd_data_get_client_state(uid, &state)) {
720 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
721 return TTSD_ERROR_INVALID_PARAMETER;
725 if (0 != ttsd_engine_get_voice_list(voice_list)) {
726 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail ttsd_server_get_support_voices() ");
727 return TTSD_ERROR_OPERATION_FAILED;
730 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] Get supported voices ");
732 return TTSD_ERROR_NONE;
735 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
738 if (0 > ttsd_data_get_client_state(uid, &state)) {
739 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
740 return TTSD_ERROR_INVALID_PARAMETER;
743 /* get current voice */
744 int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
746 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail ttsd_server_get_support_voices() ");
750 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
752 return TTSD_ERROR_NONE;
757 * TTS Server Functions for Setting *
760 int ttsd_server_setting_initialize(int uid)
762 if (false == g_is_engine) {
763 if (0 != ttsd_engine_agent_initialize_current_engine()) {
764 SLOG(LOG_WARN, TAG_TTSD, "[Server Setting WARNING] No Engine !!! " );
766 return TTSD_ERROR_ENGINE_NOT_FOUND;
772 if (-1 != ttsd_setting_data_is_setting(uid)) {
773 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] pid has already been registered ");
774 return TTSD_ERROR_INVALID_PARAMETER;
777 if (0 == ttsd_data_get_client_count()) {
778 if( 0 != ttsd_engine_agent_load_current_engine() ) {
779 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to load current engine ");
780 return TTSD_ERROR_OPERATION_FAILED;
785 if (0 != ttsd_setting_data_add(uid)) {
786 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to add client info ");
787 return TTSD_ERROR_OPERATION_FAILED;
790 return TTSD_ERROR_NONE;
793 int ttsd_server_setting_finalize(int uid)
795 if (-1 == ttsd_setting_data_is_setting(uid)) {
796 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
797 return TTSD_ERROR_INVALID_PARAMETER;
800 ttsd_setting_data_delete(uid);
802 /* unload engine, if ref count of client is 0 */
803 if (0 == ttsd_data_get_client_count())
805 if (0 != ttsd_engine_agent_release()) {
806 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to release engine agent");
808 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting SUCCESS] Release engine agent");
810 ecore_timer_add(0, __quit_ecore_loop, NULL);
813 return TTSD_ERROR_NONE;
816 int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
818 if (-1 == ttsd_setting_data_is_setting(uid)) {
819 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
820 return TTSD_ERROR_INVALID_PARAMETER;
824 ret = ttsd_engine_setting_get_engine_list(engine_list);
826 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
830 return TTSD_ERROR_NONE;
833 int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
835 if (-1 == ttsd_setting_data_is_setting(uid)) {
836 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
837 return TTSD_ERROR_INVALID_PARAMETER;
841 ret = ttsd_engine_setting_get_engine(engine_id);
843 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
848 return TTSD_ERROR_NONE;
851 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
853 /* clear client data */
854 ttsd_data_clear_data(uid);
855 ttsd_data_set_client_state(uid, APP_STATE_READY);
858 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
860 ttsd_data_delete_client(uid);
866 int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
868 /* check if uid is valid */
869 if (-1 == ttsd_setting_data_is_setting(uid)) {
870 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
871 return TTSD_ERROR_INVALID_PARAMETER;
874 if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
875 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting] new engine is the same as current engine ");
876 return TTSD_ERROR_NONE;
879 /* stop all player */
880 ttsd_player_all_stop();
882 /* send interrupt message to all clients */
883 ttsd_data_foreach_clients(__get_client_cb, NULL);
887 ret = ttsd_engine_setting_set_engine(engine_id);
889 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
893 return TTSD_ERROR_NONE;
896 int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
898 /* check if uid is valid */
899 if (-1 == ttsd_setting_data_is_setting(uid)) {
900 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
901 return TTSD_ERROR_INVALID_PARAMETER;
904 /* get language list from engine */
906 ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
908 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
912 return TTSD_ERROR_NONE;
915 int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
917 /* check if uid is valid */
918 if (-1 == ttsd_setting_data_is_setting(uid)) {
919 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
920 return TTSD_ERROR_INVALID_PARAMETER;
924 ret = ttsd_engine_setting_get_default_voice(language, vctype);
926 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
930 return TTSD_ERROR_NONE;
933 int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
935 /* check if uid is valid */
936 if (-1 == ttsd_setting_data_is_setting(uid)) {
937 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
938 return TTSD_ERROR_INVALID_PARAMETER;
941 /* set current language */
943 ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
945 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
949 return TTSD_ERROR_NONE;
952 int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
954 /* check if uid is valid */
955 if (-1 == ttsd_setting_data_is_setting(uid)) {
956 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
957 return TTSD_ERROR_INVALID_PARAMETER;
961 ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
963 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
967 return TTSD_ERROR_NONE;
970 int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
972 /* check if uid is valid */
973 if (-1 == ttsd_setting_data_is_setting(uid)) {
974 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
975 return TTSD_ERROR_INVALID_PARAMETER;
979 ret = ttsd_engine_setting_set_engine_setting(key, value);
981 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
985 return TTSD_ERROR_NONE;
988 int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
990 /* check if uid is valid */
991 if (-1 == ttsd_setting_data_is_setting(uid)) {
992 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
993 return TTSD_ERROR_INVALID_PARAMETER;
996 /* get current speed */
998 ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
1000 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
1004 return TTSD_ERROR_NONE;
1007 int ttsd_server_setting_set_default_speed(int uid, int default_speed)
1009 /* check if uid is valid */
1010 if (-1 == ttsd_setting_data_is_setting(uid)) {
1011 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
1012 return TTSD_ERROR_INVALID_PARAMETER;
1015 /* set default speed */
1017 ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
1019 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
1023 return TTSD_ERROR_NONE;