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;
499 int ttsd_server_finalize(int uid)
502 if (0 > ttsd_data_get_client_state(uid, &state)) {
503 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_finalize : uid is not valid ");
504 return TTSD_ERROR_INVALID_PARAMETER;
507 ttsd_server_stop(uid);
509 ttsd_player_destroy_instance(uid);
511 ttsd_data_delete_client(uid);
513 /* unload engine, if ref count of client is 0 */
514 if (0 == ttsd_data_get_client_count()) {
515 if (0 != ttsd_engine_agent_unload_current_engine()) {
516 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to unload current engine ");
518 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] unload current engine ");
522 return TTSD_ERROR_NONE;
525 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
528 if (0 > ttsd_data_get_client_state(uid, &state)) {
529 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : uid is not valid ");
530 return TTSD_ERROR_INVALID_PARAMETER;
533 /* check valid voice */
534 char* temp_lang = NULL;
535 ttsp_voice_type_e temp_type;
536 if (true != ttsd_engine_select_valid_voice((const char*)lang, (const ttsp_voice_type_e)voice_type, &temp_lang, &temp_type)) {
537 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to select valid voice ");
538 return TTSD_ERROR_INVALID_VOICE;
540 if (NULL == temp_lang)
546 data.lang = strdup(lang);
547 data.vctype = (ttsp_voice_type_e)voice_type;
549 data.speed = (ttsp_speed_e)speed;
550 data.utt_id = utt_id;
552 data.text = strdup(text);
554 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
555 if (0 != ttsd_data_add_speak_data(uid, data)) {
556 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_add_queue : Current state of uid is not 'ready' ");
557 return TTSD_ERROR_OPERATION_FAILED;
560 if (APP_STATE_PLAYING == state) {
561 /* check if engine use network */
562 if (ttsd_engine_agent_need_network()) {
563 if (false == ttsd_network_is_connected()) {
564 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network.");
565 return TTSD_ERROR_OPERATION_FAILED;
569 /* mode 2 for add text */
570 if (0 != __server_start_synthesis(uid, 2)) {
571 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail to schedule synthesis : uid(%d)", uid);
572 return TTSD_ERROR_OPERATION_FAILED;
576 return TTSD_ERROR_NONE;
579 Eina_Bool __send_interrupt_client(void *data)
581 int* uid = (int*)data;
584 int pid = ttsd_data_get_pid(*uid);
585 /* send message to client about changing state */
586 ttsdc_send_set_state_message (pid, *uid, APP_STATE_PAUSED);
592 int ttsd_server_play(int uid)
595 if (0 > ttsd_data_get_client_state(uid, &state)) {
596 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid(%d) is NOT valid ", uid);
597 return TTSD_ERROR_INVALID_PARAMETER;
600 if (APP_STATE_PLAYING == state) {
601 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state(%d) is 'play' ", uid);
602 return TTSD_ERROR_NONE;
605 /* check if engine use network */
606 if (ttsd_engine_agent_need_network()) {
607 if (false == ttsd_network_is_connected()) {
608 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
609 return TTSD_ERROR_OUT_OF_NETWORK;
613 int current_uid = ttsd_data_get_current_playing();
615 if (uid != current_uid && -1 != current_uid) {
616 /* Send interrupt message */
617 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
620 if (0 != ttsd_player_pause(current_uid)) {
621 SLOG(LOG_WARN, TAG_TTSD, "[Server ERROR] fail to ttsd_player_pause() : uid (%d)", current_uid);
625 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
627 int* temp_uid = (int*)malloc(sizeof(int));
628 *temp_uid = current_uid;
629 ecore_timer_add(0, __send_interrupt_client, temp_uid);
632 /* Change current play */
633 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
634 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to set state : uid(%d)", uid);
635 return TTSD_ERROR_OPERATION_FAILED;
638 if (0 != __server_play_internal(uid, state)) {
639 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to start synthesis : uid(%d)", uid);
640 return TTSD_ERROR_OPERATION_FAILED;
643 ecore_timer_add(0, __start_next_synthesis, NULL);
645 return TTSD_ERROR_NONE;
649 int ttsd_server_stop(int uid)
652 if (0 > ttsd_data_get_client_state(uid, &state)) {
653 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
654 return TTSD_ERROR_INVALID_PARAMETER;
658 ttsd_data_clear_data(uid);
660 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
661 ttsd_data_set_client_state(uid, APP_STATE_READY);
663 if (0 != ttsd_player_stop(uid))
664 SLOG(LOG_WARN, TAG_TTSD, "[Server] Fail to ttsd_player_stop()");
666 if (true == __server_get_is_synthesizing()) {
667 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] TTS-engine is running ");
670 ret = ttsd_engine_cancel_synthesis();
672 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
674 __server_set_is_synthesizing(false);
677 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is 'ready' ");
680 return TTSD_ERROR_NONE;
683 int ttsd_server_pause(int uid, int* utt_id)
686 if (0 > ttsd_data_get_client_state(uid, &state)) {
687 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_pause : uid is not valid ");
688 return TTSD_ERROR_INVALID_PARAMETER;
691 if (APP_STATE_PLAYING != state) {
692 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is not 'play' ");
693 return TTSD_ERROR_INVALID_STATE;
697 ret = ttsd_player_pause(uid);
699 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail player_pause() : ret(%d)", ret);
700 return TTSD_ERROR_OPERATION_FAILED;
703 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
705 return TTSD_ERROR_NONE;
708 int ttsd_server_get_support_voices(int uid, GList** voice_list)
711 if (0 > ttsd_data_get_client_state(uid, &state)) {
712 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] uid is not valid ");
713 return TTSD_ERROR_INVALID_PARAMETER;
717 if (0 != ttsd_engine_get_voice_list(voice_list)) {
718 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail ttsd_server_get_support_voices() ");
719 return TTSD_ERROR_OPERATION_FAILED;
722 SLOG(LOG_DEBUG, TAG_TTSD, "[Server SUCCESS] Get supported voices ");
724 return TTSD_ERROR_NONE;
727 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
730 if (0 > ttsd_data_get_client_state(uid, &state)) {
731 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] ttsd_server_get_current_voice : uid is not valid ");
732 return TTSD_ERROR_INVALID_PARAMETER;
735 /* get current voice */
736 int ret = ttsd_engine_get_default_voice(language, (ttsp_voice_type_e*)voice_type);
738 SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] fail ttsd_server_get_support_voices() ");
742 SLOG(LOG_DEBUG, TAG_TTSD, "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
744 return TTSD_ERROR_NONE;
749 * TTS Server Functions for Setting *
752 int ttsd_server_setting_initialize(int uid)
754 if (false == g_is_engine) {
755 if (0 != ttsd_engine_agent_initialize_current_engine()) {
756 SLOG(LOG_WARN, TAG_TTSD, "[Server Setting WARNING] No Engine !!! " );
758 return TTSD_ERROR_ENGINE_NOT_FOUND;
764 if (-1 != ttsd_setting_data_is_setting(uid)) {
765 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] pid has already been registered ");
766 return TTSD_ERROR_INVALID_PARAMETER;
769 if (0 == ttsd_data_get_client_count()) {
770 if( 0 != ttsd_engine_agent_load_current_engine() ) {
771 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to load current engine ");
772 return TTSD_ERROR_OPERATION_FAILED;
777 if (0 != ttsd_setting_data_add(uid)) {
778 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to add client info ");
779 return TTSD_ERROR_OPERATION_FAILED;
782 return TTSD_ERROR_NONE;
785 int ttsd_server_setting_finalize(int uid)
787 if (-1 == ttsd_setting_data_is_setting(uid)) {
788 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
789 return TTSD_ERROR_INVALID_PARAMETER;
792 ttsd_setting_data_delete(uid);
794 /* unload engine, if ref count of client is 0 */
795 if (0 == ttsd_data_get_client_count())
797 if (0 != ttsd_engine_agent_unload_current_engine())
798 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to unload current engine ");
800 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting SUCCESS] unload current engine ");
803 return TTSD_ERROR_NONE;
806 int ttsd_server_setting_get_engine_list(int uid, GList** engine_list)
808 if (-1 == ttsd_setting_data_is_setting(uid)) {
809 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
810 return TTSD_ERROR_INVALID_PARAMETER;
814 ret = ttsd_engine_setting_get_engine_list(engine_list);
816 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine list : result(%d)", ret);
820 return TTSD_ERROR_NONE;
823 int ttsd_server_setting_get_current_engine(int uid, char** engine_id)
825 if (-1 == ttsd_setting_data_is_setting(uid)) {
826 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
827 return TTSD_ERROR_INVALID_PARAMETER;
831 ret = ttsd_engine_setting_get_engine(engine_id);
833 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get current engine : result(%d) ", ret);
838 return TTSD_ERROR_NONE;
841 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
843 /* clear client data */
844 ttsd_data_clear_data(uid);
845 ttsd_data_set_client_state(uid, APP_STATE_READY);
848 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
850 ttsd_data_delete_client(uid);
856 int ttsd_server_setting_set_current_engine(int uid, const char* engine_id)
858 /* check if uid is valid */
859 if (-1 == ttsd_setting_data_is_setting(uid)) {
860 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
861 return TTSD_ERROR_INVALID_PARAMETER;
864 if (true == ttsd_engine_agent_is_same_engine(engine_id)) {
865 SLOG(LOG_DEBUG, TAG_TTSD, "[Server Setting] new engine is the same as current engine ");
866 return TTSD_ERROR_NONE;
869 /* stop all player */
870 ttsd_player_all_stop();
872 /* send interrupt message to all clients */
873 ttsd_data_foreach_clients(__get_client_cb, NULL);
877 ret = ttsd_engine_setting_set_engine(engine_id);
879 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set current engine : result(%d) ", ret);
883 return TTSD_ERROR_NONE;
886 int ttsd_server_setting_get_voice_list(int uid, char** engine_id, GList** voice_list)
888 /* check if uid is valid */
889 if (-1 == ttsd_setting_data_is_setting(uid)) {
890 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
891 return TTSD_ERROR_INVALID_PARAMETER;
894 /* get language list from engine */
896 ret = ttsd_engine_setting_get_voice_list(engine_id, voice_list);
898 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get voice list : result(%d)", ret);
902 return TTSD_ERROR_NONE;
905 int ttsd_server_setting_get_default_voice(int uid, char** language, ttsp_voice_type_e* vctype)
907 /* check if uid is valid */
908 if (-1 == ttsd_setting_data_is_setting(uid)) {
909 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
910 return TTSD_ERROR_INVALID_PARAMETER;
914 ret = ttsd_engine_setting_get_default_voice(language, vctype);
916 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] Fail to get default voice : result(%d) ", ret);
920 return TTSD_ERROR_NONE;
923 int ttsd_server_setting_set_default_voice(int uid, const char* language, int vctype)
925 /* check if uid is valid */
926 if (-1 == ttsd_setting_data_is_setting(uid)) {
927 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
928 return TTSD_ERROR_INVALID_PARAMETER;
931 /* set current language */
933 ret = ttsd_engine_setting_set_default_voice((const char*)language, (const ttsp_voice_type_e)vctype);
935 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default voice : result(%d) ", ret);
939 return TTSD_ERROR_NONE;
942 int ttsd_server_setting_get_engine_setting(int uid, char** engine_id, GList** engine_setting_list)
944 /* check if uid is valid */
945 if (-1 == ttsd_setting_data_is_setting(uid)) {
946 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
947 return TTSD_ERROR_INVALID_PARAMETER;
951 ret = ttsd_engine_setting_get_engine_setting_info(engine_id, engine_setting_list);
953 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get engine setting info : result(%d)", ret);
957 return TTSD_ERROR_NONE;
960 int ttsd_server_setting_set_engine_setting(int uid, const char* key, const char* value)
962 /* check if uid is valid */
963 if (-1 == ttsd_setting_data_is_setting(uid)) {
964 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
965 return TTSD_ERROR_INVALID_PARAMETER;
969 ret = ttsd_engine_setting_set_engine_setting(key, value);
971 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set engine setting info : result(%d)", ret);
975 return TTSD_ERROR_NONE;
978 int ttsd_server_setting_get_default_speed(int uid, int* default_speed)
980 /* check if uid is valid */
981 if (-1 == ttsd_setting_data_is_setting(uid)) {
982 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
983 return TTSD_ERROR_INVALID_PARAMETER;
986 /* get current speed */
988 ret = ttsd_engine_setting_get_default_speed((ttsp_speed_e*)default_speed);
990 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to get default speed : result(%d)", ret);
994 return TTSD_ERROR_NONE;
997 int ttsd_server_setting_set_default_speed(int uid, int default_speed)
999 /* check if uid is valid */
1000 if (-1 == ttsd_setting_data_is_setting(uid)) {
1001 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] uid is not valid (%s)", uid);
1002 return TTSD_ERROR_INVALID_PARAMETER;
1005 /* set default speed */
1007 ret = ttsd_engine_setting_set_default_speed((ttsp_speed_e)default_speed);
1009 SLOG(LOG_ERROR, TAG_TTSD, "[Server Setting ERROR] fail to set default speed : result(%d)", ret);
1013 return TTSD_ERROR_NONE;