2 * Copyright (c) 2011 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 */
40 static bool g_is_next_synthesis;
42 /* Function definitions */
43 int __server_next_synthesis(int uid);
46 int __server_set_is_synthesizing(bool flag)
48 g_is_synthesizing = flag;
52 bool __server_get_current_synthesis()
54 return g_is_synthesizing;
57 int __server_send_error(int uid, int utt_id, int error_code)
59 int pid = ttsd_data_get_pid(uid);
62 if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) {
63 ttsd_data_delete_client(uid);
69 int __server_start_synthesis(int uid, int mode)
73 /* check if tts-engine is running */
74 if (true == __server_get_current_synthesis()) {
75 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] TTS-engine is running ");
78 if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
79 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
82 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Out of memory : utterance ");
83 return TTSD_ERROR_OUT_OF_MEMORY;
87 utt->uttid = sdata.utt_id;
89 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
90 SLOG(LOG_DEBUG, TAG_TTSD, "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
91 SLOG(LOG_DEBUG, TAG_TTSD, "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
92 SLOG(LOG_DEBUG, TAG_TTSD, "Text : %s", sdata.text);
93 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
95 __server_set_is_synthesizing(true);
97 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
99 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
101 __server_set_is_synthesizing(false);
103 result = TTSD_ERROR_OPERATION_FAILED;
108 __server_send_error(uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
109 ttsd_server_stop(uid);
111 int pid = ttsd_data_get_pid(uid);
112 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
115 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] SUCCESS to start synthesis");
118 if(sdata.text != NULL)
122 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Text List is EMPTY!! ");
129 int __server_play_internal(int uid, app_state_e state)
133 /* - input uid is current play */
137 if (APP_STATE_PAUSED == state) {
139 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
141 /* resume player and start speech synthesis */
142 if (0 != ttsd_player_resume(uid)) {
143 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] fail to ttsd_player_resume()");
146 /* mode 1 for play */
147 ret = __server_start_synthesis(uid, 1);
149 } else if(APP_STATE_READY == state) {
150 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] uid(%d) is 'Ready' state : Next step is start synthesis ", uid);
152 /* mode 1 for play */
153 ret = __server_start_synthesis(uid, 1);
161 int __server_next_synthesis(int uid)
163 SLOG(LOG_DEBUG, TAG_TTSD, "===== START NEXT SYNTHESIS & PLAY");
165 /* get current playing client */
166 int current_uid = ttsd_data_get_current_playing();
168 if (0 > current_uid) {
169 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current uid is not valid");
170 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
171 SLOG(LOG_DEBUG, TAG_TTSD, " ");
175 if (true == __server_get_current_synthesis()) {
176 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Engine has already been running. ");
177 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
178 SLOG(LOG_DEBUG, TAG_TTSD, " ");
182 /* synthesize next text */
184 if (0 == ttsd_data_get_speak_data(current_uid, &sdata)) {
186 utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
189 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to allocate memory : utterance ");
191 __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OUT_OF_MEMORY);
192 return TTSD_ERROR_OUT_OF_MEMORY;
195 utt->uid = current_uid;
196 utt->uttid = sdata.utt_id;
198 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
199 SLOG(LOG_DEBUG, TAG_TTSD, "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
200 SLOG(LOG_DEBUG, TAG_TTSD, "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
201 SLOG(LOG_DEBUG, TAG_TTSD, "Text : %s", sdata.text);
202 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------------------------------------------");
204 __server_set_is_synthesizing(true);
207 ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
209 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
211 __server_set_is_synthesizing(false);
213 __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
217 ttsd_server_stop(current_uid);
219 int pid = ttsd_data_get_pid(current_uid);
220 ttsdc_send_set_state_message(pid, current_uid, APP_STATE_READY);
223 if(sdata.text != NULL)
227 if (0 != ttsd_player_play(current_uid)) {
228 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] __synthesis_result_callback : fail ttsd_player_play() ");
230 /* success playing */
231 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Success to start player");
234 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
235 SLOG(LOG_DEBUG, TAG_TTSD, " ");
241 * TTS Server Callback Functions
244 int __player_result_callback(player_event_e event, int uid, int utt_id)
247 case PLAYER_EMPTY_SOUND_QUEUE:
248 /* check whether synthesis is running */
249 if (false == __server_get_current_synthesis()) {
250 /* check text queue is empty */
251 if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
252 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER Callback] all play completed ");
258 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER Callback ERROR] callback : player error ");
260 __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
263 case PLAYER_END_OF_PLAYING:
270 Eina_Bool __start_next_synthesis(void *data)
272 /* get current play */
273 int uid = ttsd_data_is_current_playing();
278 if (true == g_is_next_synthesis) {
279 SLOG(LOG_DEBUG, TAG_TTSD, "===== NEXT SYNTHESIS START");
280 __server_next_synthesis(uid);
281 SLOG(LOG_DEBUG, TAG_TTSD, "===== ");
282 SLOG(LOG_DEBUG, TAG_TTSD, " ");
284 g_is_next_synthesis = false;
290 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
292 SLOG(LOG_DEBUG, TAG_TTSD, "===== SYNTHESIS RESULT CALLBACK START");
294 utterance_t* utt_get_param;
295 utt_get_param = (utterance_t*)user_data;
297 int uid = utt_get_param->uid;
298 int uttid = utt_get_param->uttid;
300 if (NULL == utt_get_param) {
301 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] User data is NULL " );
302 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
303 SLOG(LOG_DEBUG, TAG_TTSD, " ");
307 /* Synthesis is success */
308 if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
310 if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_START");
311 if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
312 if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
314 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
315 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] uttid is NOT valid !!!! " );
316 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
317 SLOG(LOG_DEBUG, TAG_TTSD, " ");
323 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) ",
324 uid, uttid, data, data_size);
327 sound_data_s temp_data;
328 temp_data.data = (char*)g_malloc0( sizeof(char) * data_size );
329 memcpy(temp_data.data, data, data_size);
331 temp_data.data_size = data_size;
332 temp_data.utt_id = utt_get_param->uttid;
333 temp_data.event = event;
335 ttsp_audio_type_e audio_type;
339 if (ttsd_engine_get_audio_format(&audio_type, &rate, &channels)) {
340 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to get audio format ");
341 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
342 SLOG(LOG_DEBUG, TAG_TTSD, " ");
346 temp_data.audio_type = audio_type;
347 temp_data.rate = rate;
348 temp_data.channels = channels;
350 if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
351 SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] Fail to add sound data : uid(%d)", utt_get_param->uid);
354 if (event == TTSP_RESULT_EVENT_FINISH) {
355 __server_set_is_synthesizing(false);
357 g_is_next_synthesis = true;
361 else if (event == TTSP_RESULT_EVENT_CANCEL) {
362 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
363 __server_set_is_synthesizing(false);
365 g_is_next_synthesis = true;
369 SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : etc");
371 __server_set_is_synthesizing(false);
373 g_is_next_synthesis = true;
376 if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
377 if (NULL != utt_get_param)
381 SLOG(LOG_DEBUG, TAG_TTSD, "===== SYNTHESIS RESULT CALLBACK END");
382 SLOG(LOG_DEBUG, TAG_TTSD, " ");
391 int ttsd_initialize()
393 if (ttsd_config_initialize()) {
394 SLOG(LOG_ERROR, TAG_TTSD, "[Server WARNING] Fail to initialize config.");
398 if (ttsd_player_init(__player_result_callback)) {
399 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to initialize player init.");
400 return TTSD_ERROR_OPERATION_FAILED;
403 /* Engine Agent initialize */
404 if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
405 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to engine agent initialize.");
406 return TTSD_ERROR_OPERATION_FAILED;
409 /* set current engine */
410 if (0 != ttsd_engine_agent_initialize_current_engine()) {
411 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] No Engine !!!" );
418 return TTSD_ERROR_NONE;
422 bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
426 result = ttsdc_send_hello(pid, uid);
429 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] uid(%d) should be removed.", uid);
430 ttsd_server_finalize(uid);
431 } else if (-1 == result) {
432 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Hello result has error");
439 Eina_Bool ttsd_cleanup_client(void *data)
441 SLOG(LOG_DEBUG, TAG_TTSD, "===== CLEAN UP CLIENT START");
442 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
443 SLOG(LOG_DEBUG, TAG_TTSD, "=====");
444 SLOG(LOG_DEBUG, TAG_TTSD, " ");
450 * TTS Server Functions for Client
453 int ttsd_server_initialize(int pid, int uid)
455 if (false == g_is_engine) {
456 if (0 != ttsd_engine_agent_initialize_current_engine()) {
457 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] No Engine !!! " );
460 return TTSD_ERROR_ENGINE_NOT_FOUND;
466 if (-1 != ttsd_data_is_client(uid)) {
467 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Uid has already been registered ");
468 return TTSD_ERROR_INVALID_PARAMETER;
471 if (0 == ttsd_data_get_client_count()) {
472 if (0 != ttsd_engine_agent_load_current_engine()) {
473 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to load current engine ");
474 return TTSD_ERROR_OPERATION_FAILED;
478 if (0 != ttsd_data_new_client(pid, uid)) {
479 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to add client info ");
480 return TTSD_ERROR_OPERATION_FAILED;
483 if (0 != ttsd_player_create_instance(uid)) {
484 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to create player ");
485 return TTSD_ERROR_OPERATION_FAILED;
488 return TTSD_ERROR_NONE;
492 int ttsd_server_finalize(int uid)
495 if (0 > ttsd_data_get_client_state(uid, &state)) {
496 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_finalize : uid is not valid ");
497 return TTSD_ERROR_INVALID_PARAMETER;
500 ttsd_server_stop(uid);
502 ttsd_player_destroy_instance(uid);
504 ttsd_data_delete_client(uid);
506 /* unload engine, if ref count of client is 0 */
507 if (0 == ttsd_data_get_client_count()) {
508 if (0 != ttsd_engine_agent_unload_current_engine()) {
509 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to unload current engine ");
511 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] unload current engine ");
515 return TTSD_ERROR_NONE;
518 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
521 if (0 > ttsd_data_get_client_state(uid, &state)) {
522 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
523 return TTSD_ERROR_INVALID_PARAMETER;
526 /* check valid voice */
527 char* temp_lang = NULL;
528 ttsp_voice_type_e temp_type;
529 if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
530 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to select valid voice ");
531 return TTSD_ERROR_INVALID_VOICE;
533 if (NULL == temp_lang)
539 data.lang = strdup(lang);
540 data.vctype = (ttsp_voice_type_e)voice_type;
542 data.speed = (ttsp_speed_e)speed;
543 data.utt_id = utt_id;
545 data.text = strdup(text);
547 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
548 if (0 != ttsd_data_add_speak_data(uid, data)) {
549 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
550 return TTSD_ERROR_OPERATION_FAILED;
553 if (APP_STATE_PLAYING == state) {
554 /* check if engine use network */
555 if (ttsd_engine_agent_need_network()) {
556 if (false == ttsd_network_is_connected()) {
557 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network.");
558 return TTSD_ERROR_OPERATION_FAILED;
562 /* mode 2 for add text */
563 if (0 != __server_start_synthesis(uid, 2)) {
564 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to schedule synthesis : uid(%d)", uid);
565 return TTSD_ERROR_OPERATION_FAILED;
569 return TTSD_ERROR_NONE;
572 Eina_Bool __send_interrupt_client(void *data)
574 int* uid = (int*)data;
577 int pid = ttsd_data_get_pid(*uid);
578 /* send message to client about changing state */
579 ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
585 int ttsd_server_play(int uid)
588 if (0 > ttsd_data_get_client_state(uid, &state)) {
589 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid(%d) is NOT valid ", uid);
590 return TTSD_ERROR_INVALID_PARAMETER;
593 if (APP_STATE_PLAYING == state) {
594 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state(%d) is 'play' ", uid);
595 return TTSD_ERROR_NONE;
598 /* check if engine use network */
599 if (ttsd_engine_agent_need_network()) {
600 if (false == ttsd_network_is_connected()) {
601 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
602 return TTSD_ERROR_OUT_OF_NETWORK;
606 int current_uid = ttsd_data_get_current_playing();
608 if (uid != current_uid && -1 != current_uid) {
609 /* Send interrupt message */
610 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
613 if (0 != ttsd_player_pause(current_uid)) {
614 SLOG(LOG_WARN, TAG_TTSD, "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
618 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
620 int* temp_uid = (int*)malloc(sizeof(int));
621 *temp_uid = current_uid;
622 ecore_timer_add(0, __send_interrupt_client, temp_uid);
625 /* Change current play */
626 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
627 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to set state : uid(%d)", uid);
628 return TTSD_ERROR_OPERATION_FAILED;
631 if (0 != __server_play_internal(uid, state)) {
632 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to start synthesis : uid(%d)", uid);
633 return TTSD_ERROR_OPERATION_FAILED;
637 ecore_timer_add(0, __start_next_synthesis, NULL);
639 return TTSD_ERROR_NONE;
643 int ttsd_server_stop(int uid)
646 if (0 > ttsd_data_get_client_state(uid, &state)) {
647 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
648 return TTSD_ERROR_INVALID_PARAMETER;
652 ttsd_data_clear_data(uid);
654 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
655 ttsd_data_set_client_state(uid, APP_STATE_READY);
657 if (0 != ttsd_player_stop(uid))
658 SLOG(LOG_WARN, TAG_TTSD, "[Server] Fail to ttsd_player_stop()");
660 if (true == __server_get_current_synthesis()) {
661 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] TTS-engine is running ");
664 ret = ttsd_engine_cancel_synthesis();
666 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
668 __server_set_is_synthesizing(false);
671 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is 'ready' ");
674 return TTSD_ERROR_NONE;
677 int ttsd_server_pause(int uid, int* utt_id)
680 if (0 > ttsd_data_get_client_state(uid, &state)) {
681 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_pause : uid is not valid ");
682 return TTSD_ERROR_INVALID_PARAMETER;
685 if (APP_STATE_PLAYING != state) {
686 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is not 'play' ");
687 return TTSD_ERROR_INVALID_STATE;
691 ret = ttsd_player_pause(uid);
693 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail player_pause() : ret(%d)", ret);
694 return TTSD_ERROR_OPERATION_FAILED;
697 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
699 return TTSD_ERROR_NONE;
702 int ttsd_server_get_support_voices(int uid, GList** voice_list)
705 if (0 > ttsd_data_get_client_state(uid, &state)) {
706 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
707 return TTSD_ERROR_INVALID_PARAMETER;
711 if (0 != ttsd_engine_get_voice_list(voice_list)) {
712 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail ttsd_server_get_support_voices() ");
713 return TTSD_ERROR_OPERATION_FAILED;
716 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] Get supported voices ");
718 return TTSD_ERROR_NONE;
721 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
724 if (0 > ttsd_data_get_client_state(uid, &state)) {
725 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
726 return TTSD_ERROR_INVALID_PARAMETER;
729 /* get current voice */
730 int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
732 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail ttsd_server_get_support_voices() ");
736 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
738 return TTSD_ERROR_NONE;
743 * TTS Server Functions for Setting *
746 int ttsd_server_setting_initialize(int uid)
748 if (false == g_is_engine) {
749 if (0 != ttsd_engine_agent_initialize_current_engine()) {
750 SLOG(LOG_WARN, TAG_TTSD, "[Server Setting WARNING] No Engine !!! " );
752 return TTSD_ERROR_ENGINE_NOT_FOUND;
758 if (-1 != ttsd_setting_data_is_setting(uid)) {
759 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] pid has already been registered ");
760 return TTSD_ERROR_INVALID_PARAMETER;
763 if (0 == ttsd_data_get_client_count()) {
764 if( 0 != ttsd_engine_agent_load_current_engine() ) {
765 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to load current engine ");
766 return TTSD_ERROR_OPERATION_FAILED;
771 if (0 != ttsd_setting_data_add(uid)) {
772 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to add client info ");
773 return TTSD_ERROR_OPERATION_FAILED;
776 return TTSD_ERROR_NONE;
779 int ttsd_server_setting_finalize(int uid)
781 if (-1 == ttsd_setting_data_is_setting(uid)) {
782 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
783 return TTSD_ERROR_INVALID_PARAMETER;
786 ttsd_setting_data_delete(uid);
788 /* unload engine, if ref count of client is 0 */
789 if (0 == ttsd_data_get_client_count())
791 if (0 != ttsd_engine_agent_unload_current_engine())
792 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to unload current engine ");
794 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting SUCCESS] unload current engine ");
797 return TTSD_ERROR_NONE;
800 int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
802 if (-1 == ttsd_setting_data_is_setting(uid)) {
803 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
804 return TTSD_ERROR_INVALID_PARAMETER;
808 ret = ttsd_engine_setting_get_engine_list(engine_list);
810 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
814 return TTSD_ERROR_NONE;
817 int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
819 if (-1 == ttsd_setting_data_is_setting(uid)) {
820 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
821 return TTSD_ERROR_INVALID_PARAMETER;
825 ret = ttsd_engine_setting_get_engine(engine_id);
827 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
832 return TTSD_ERROR_NONE;
835 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
837 /* clear client data */
838 ttsd_data_clear_data(uid);
839 ttsd_data_set_client_state(uid, APP_STATE_READY);
842 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
844 ttsd_data_delete_client(uid);
850 int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
852 /* check if uid is valid */
853 if (-1 == ttsd_setting_data_is_setting(uid)) {
854 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
855 return TTSD_ERROR_INVALID_PARAMETER;
858 if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
859 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting] new engine is the same as current engine ");
860 return TTSD_ERROR_NONE;
863 /* stop all player */
864 ttsd_player_all_stop();
866 /* send interrupt message to all clients */
867 ttsd_data_foreach_clients(__get_client_cb, NULL);
871 ret = ttsd_engine_setting_set_engine(engine_id);
873 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
877 return TTSD_ERROR_NONE;
880 int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
882 /* check if uid is valid */
883 if (-1 == ttsd_setting_data_is_setting(uid)) {
884 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
885 return TTSD_ERROR_INVALID_PARAMETER;
888 /* get language list from engine */
890 ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
892 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
896 return TTSD_ERROR_NONE;
899 int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
901 /* check if uid is valid */
902 if (-1 == ttsd_setting_data_is_setting(uid)) {
903 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
904 return TTSD_ERROR_INVALID_PARAMETER;
908 ret = ttsd_engine_setting_get_default_voice(language, vctype);
910 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
914 return TTSD_ERROR_NONE;
917 int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
919 /* check if uid is valid */
920 if (-1 == ttsd_setting_data_is_setting(uid)) {
921 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
922 return TTSD_ERROR_INVALID_PARAMETER;
925 /* set current language */
927 ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
929 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
933 return TTSD_ERROR_NONE;
936 int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
938 /* check if uid is valid */
939 if (-1 == ttsd_setting_data_is_setting(uid)) {
940 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
941 return TTSD_ERROR_INVALID_PARAMETER;
945 ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
947 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
951 return TTSD_ERROR_NONE;
954 int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
956 /* check if uid is valid */
957 if (-1 == ttsd_setting_data_is_setting(uid)) {
958 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
959 return TTSD_ERROR_INVALID_PARAMETER;
963 ret = ttsd_engine_setting_set_engine_setting(key, value);
965 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
969 return TTSD_ERROR_NONE;
972 int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
974 /* check if uid is valid */
975 if (-1 == ttsd_setting_data_is_setting(uid)) {
976 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
977 return TTSD_ERROR_INVALID_PARAMETER;
980 /* get current speed */
982 ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
984 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
988 return TTSD_ERROR_NONE;
991 int ttsd_server_setting_set_default_speed(int uid, int default_speed)
993 /* check if uid is valid */
994 if (-1 == ttsd_setting_data_is_setting(uid)) {
995 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
996 return TTSD_ERROR_INVALID_PARAMETER;
999 /* set default speed */
1001 ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
1003 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
1007 return TTSD_ERROR_NONE;