2 * Copyright (c) 2011-2014 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.
17 #include "ttsd_config.h"
18 #include "ttsd_data.h"
19 #include "ttsd_dbus.h"
20 #include "ttsd_dbus_server.h"
21 #include "ttsd_engine_agent.h"
22 #include "ttsd_main.h"
23 #include "ttsd_network.h"
24 #include "ttsd_player.h"
25 #include "ttsd_server.h"
30 TTSD_SYNTHESIS_CONTROL_DOING = 0,
31 TTSD_SYNTHESIS_CONTROL_DONE = 1,
32 TTSD_SYNTHESIS_CONTROL_EXPIRED = 2
33 }ttsd_synthesis_control_e;
40 /* If current engine exist */
41 static bool g_is_engine;
43 /* If engine is running */
44 static ttsd_synthesis_control_e g_synth_control;
46 static Ecore_Timer* g_wait_timer = NULL;
48 static utterance_t g_utt;
50 /* Function definitions */
51 static int __synthesis(int uid);
53 static int __server_set_synth_control(ttsd_synthesis_control_e control)
55 g_synth_control = control;
59 static ttsd_synthesis_control_e __server_get_synth_control()
61 return g_synth_control;
64 static Eina_Bool __wait_synthesis(void *data)
66 /* get current play */
67 int uid = ttsd_data_get_current_playing();
70 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
75 if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
76 /* Start next synthesis */
87 static int __synthesis(int uid)
89 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS START");
92 if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
94 if (NULL == sdata.lang || NULL == sdata.text) {
95 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Current data is NOT valid");
96 ttsd_server_stop(uid);
98 int pid = ttsd_data_get_pid(uid);
99 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
101 if (NULL != sdata.lang) free(sdata.lang);
107 g_utt.uttid = sdata.utt_id;
109 SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
110 SECURE_SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
111 SECURE_SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
112 SECURE_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, NULL);
119 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
121 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
123 ttsd_server_stop(uid);
125 int pid = ttsd_data_get_pid(uid);
126 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
128 g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
135 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS END");
136 SLOG(LOG_DEBUG, get_tag(), " ");
142 * TTS Server Callback Functions
144 int __synthesis_result_callback(ttsp_result_event_e event, const void* data, unsigned int data_size,
145 ttsp_audio_type_e audio_type, int rate, void *user_data)
147 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK START");
150 int uttid = g_utt.uttid;
152 /* Synthesis is success */
153 if (TTSP_RESULT_EVENT_START == event || TTSP_RESULT_EVENT_CONTINUE == event || TTSP_RESULT_EVENT_FINISH == event) {
155 if (TTSP_RESULT_EVENT_START == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_START");
156 if (TTSP_RESULT_EVENT_CONTINUE == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CONTINUE");
157 if (TTSP_RESULT_EVENT_FINISH == event) SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_FINISH");
159 if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
160 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
161 SECURE_SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
162 SLOG(LOG_DEBUG, get_tag(), "=====");
163 SLOG(LOG_DEBUG, get_tag(), " ");
167 SECURE_SLOG(LOG_DEBUG, get_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)",
168 uid, uttid, data, data_size, audio_type, rate);
170 if (rate <= 0 || audio_type < 0 || audio_type > TTSP_AUDIO_TYPE_MAX) {
171 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
172 SECURE_SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] audio data is invalid");
173 SLOG(LOG_DEBUG, get_tag(), "=====");
174 SLOG(LOG_DEBUG, get_tag(), " ");
179 sound_data_s temp_data;
180 temp_data.data = NULL;
182 temp_data.data_size = 0;
185 temp_data.data = (char*)calloc(data_size, sizeof(char));
186 memcpy(temp_data.data, data, data_size);
188 SLOG(LOG_ERROR, get_tag(), "Sound data is NULL");
191 temp_data.data_size = data_size;
192 temp_data.utt_id = uttid;
193 temp_data.event = event;
194 temp_data.audio_type = audio_type;
195 temp_data.rate = rate;
197 if (0 != ttsd_data_add_sound_data(uid, temp_data)) {
198 SECURE_SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
201 if (event == TTSP_RESULT_EVENT_FINISH) {
202 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
205 if (0 != ttsd_player_play(uid)) {
206 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
208 /* Change ready state */
209 ttsd_server_stop(uid);
212 tmp_pid = ttsd_data_get_pid(uid);
213 ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
216 SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_ERROR");
217 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
221 SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END");
222 SLOG(LOG_DEBUG, get_tag(), " ");
227 bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
229 /* clear client data */
230 ttsd_data_clear_data(uid);
231 ttsd_data_set_client_state(uid, APP_STATE_READY);
234 if ( 0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
236 ttsd_data_delete_client(uid);
242 void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param)
245 case TTS_CONFIG_TYPE_ENGINE:
247 if (NULL == str_param) {
248 SLOG(LOG_ERROR, get_tag(), "[Server] engine id from config is NULL");
253 if (true == ttsd_engine_agent_is_same_engine(str_param)) {
254 SLOG(LOG_DEBUG, get_tag(), "[Server Setting] new engine is the same as current engine");
255 ret = ttsd_engine_agent_unload_current_engine();
257 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to unload current engine : result(%d)", ret);
260 ret = ttsd_engine_agent_load_current_engine();
262 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine : result (%d)", ret);
267 /* stop all player */
268 ttsd_player_all_stop();
270 /* send interrupt message to all clients */
271 ttsd_data_foreach_clients(__get_client_cb, NULL);
273 ttsd_engine_cancel_synthesis();
276 ret = ttsd_engine_agent_set_default_engine(str_param);
278 SLOG(LOG_WARN, get_tag(), "[Server Setting WARNING] Fail to set current engine : result(%d)", ret);
284 case TTS_CONFIG_TYPE_VOICE:
286 if (NULL == str_param) {
287 SLOG(LOG_ERROR, get_tag(), "[Server] language from config is NULL");
291 char* out_lang = NULL;
295 if (true == ttsd_engine_select_valid_voice(str_param, int_param, &out_lang, &out_type)) {
296 SECURE_SLOG(LOG_ERROR, get_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
297 ret = ttsd_engine_agent_set_default_voice(out_lang, out_type);
299 SECURE_SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
301 /* Current language is not available */
302 SECURE_SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
304 if (NULL != out_lang) free(out_lang);
308 case TTS_CONFIG_TYPE_SPEED:
310 if (TTS_SPEED_MIN <= int_param && int_param <= TTS_SPEED_MAX) {
311 /* set default speed */
313 ret = ttsd_engine_agent_set_default_speed(int_param);
315 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set default speed : result(%d)", ret);
321 case TTS_CONFIG_TYPE_PITCH:
323 if (TTS_PITCH_MIN <= int_param && int_param <= TTS_PITCH_MAX) {
324 /* set default speed */
326 ret = ttsd_engine_agent_set_default_pitch(int_param);
328 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set default pitch : result(%d)", ret);
341 bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
343 SLOG(LOG_DEBUG, get_tag(), "=== Start to terminate client [%d] ===", uid);
344 ttsd_server_finalize(uid);
348 Eina_Bool ttsd_terminate_daemon(void *data)
350 ttsd_data_foreach_clients(__terminate_client, NULL);
354 void __screen_reader_changed_cb(bool value)
356 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
357 SLOG(LOG_DEBUG, get_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
358 ecore_timer_add(1, ttsd_terminate_daemon, NULL);
360 SLOG(LOG_DEBUG, get_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
369 int ttsd_initialize()
371 if (ttsd_config_initialize(__config_changed_cb)) {
372 SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config.");
376 if (ttsd_player_init()) {
377 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to initialize player init.");
378 return TTSD_ERROR_OPERATION_FAILED;
381 /* Engine Agent initialize */
382 if (0 != ttsd_engine_agent_init(__synthesis_result_callback)) {
383 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to engine agent initialize.");
384 return TTSD_ERROR_OPERATION_FAILED;
387 /* set current engine */
388 if (0 != ttsd_engine_agent_initialize_current_engine()) {
389 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!!" );
394 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
396 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
397 ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
400 ttsd_file_clean_up();
402 return TTSD_ERROR_NONE;
407 ttsd_config_finalize();
409 ttsd_player_release();
411 ttsd_engine_agent_release();
413 return TTSD_ERROR_NONE;
416 bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
418 char appid[128] = {0, };
419 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid))) {
420 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get app id");
423 if (0 < strlen(appid)) {
424 SECURE_SLOG(LOG_DEBUG, get_tag(), "[%d] is running app - %s", pid, appid);
426 SECURE_SLOG(LOG_DEBUG, get_tag(), "[%d] is daemon or no_running app", pid);
429 result = ttsdc_send_hello(pid, uid);
432 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) should be removed.", uid);
433 ttsd_server_finalize(uid);
434 } else if (-1 == result) {
435 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Hello result has error");
442 Eina_Bool ttsd_cleanup_client(void *data)
444 SLOG(LOG_DEBUG, get_tag(), "===== CLEAN UP CLIENT START");
445 ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
446 SLOG(LOG_DEBUG, get_tag(), "=====");
447 SLOG(LOG_DEBUG, get_tag(), " ");
453 * TTS Server Functions for Client
456 int ttsd_server_initialize(int pid, int uid)
458 if (false == g_is_engine) {
459 if (0 != ttsd_engine_agent_initialize_current_engine()) {
460 SLOG(LOG_WARN, get_tag(), "[Server WARNING] No Engine !!!");
463 return TTSD_ERROR_ENGINE_NOT_FOUND;
469 if (-1 != ttsd_data_is_client(uid)) {
470 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Uid has already been registered");
471 return TTSD_ERROR_NONE;
474 if (0 == ttsd_data_get_client_count()) {
475 if (0 != ttsd_engine_agent_load_current_engine()) {
476 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine");
477 return TTSD_ERROR_OPERATION_FAILED;
481 if (0 == ttsd_data_get_same_pid_client_count(pid)) {
482 if (0 != ttsd_file_msg_open_connection(pid)) {
483 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to open file message connection");
484 return TTSD_ERROR_OPERATION_FAILED;
488 if (0 != ttsd_data_new_client(pid, uid)) {
489 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info");
490 return TTSD_ERROR_OPERATION_FAILED;
493 if (0 != ttsd_player_create_instance(uid)) {
494 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to create player");
495 return TTSD_ERROR_OPERATION_FAILED;
498 return TTSD_ERROR_NONE;
501 static Eina_Bool __quit_ecore_loop(void *data)
503 ecore_main_loop_quit();
507 void __used_voice_cb(const char* lang, int type)
509 SLOG(LOG_DEBUG, get_tag(), "[Server] Request to unload voice (%s,%d)", lang, type);
510 if (0 != ttsd_engine_unload_voice(lang, type)) {
511 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to unload voice");
515 int ttsd_server_finalize(int uid)
518 if (0 > ttsd_data_get_client_state(uid, &state)) {
519 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
522 ttsd_server_stop(uid);
524 ttsd_player_destroy_instance(uid);
526 /* Need to unload voice when used voice is unregistered */
527 if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
528 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set used voice");
529 return TTSD_ERROR_OPERATION_FAILED;
532 int pid = ttsd_data_get_pid(uid);
534 ttsd_data_delete_client(uid);
536 if (0 == ttsd_data_get_same_pid_client_count(pid)) {
537 ttsd_file_msg_close_connection(pid);
540 /* unload engine, if ref count of client is 0 */
541 if (0 == ttsd_data_get_client_count()) {
542 SLOG(LOG_DEBUG, get_tag(), "[Server] Quit main loop");
543 ecore_timer_add(0, __quit_ecore_loop, NULL);
546 return TTSD_ERROR_NONE;
549 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id)
552 if (0 > ttsd_data_get_client_state(uid, &state)) {
553 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
554 return TTSD_ERROR_INVALID_PARAMETER;
557 /* check valid voice */
558 char* temp_lang = NULL;
560 if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
561 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to select valid voice");
562 if (NULL != temp_lang) free(temp_lang);
563 return TTSD_ERROR_INVALID_VOICE;
566 if (NULL == temp_lang) {
567 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to select valid voice : result lang is NULL");
568 return TTSD_ERROR_INVALID_VOICE;
573 data.lang = strdup(lang);
574 data.vctype = voice_type;
577 data.utt_id = utt_id;
579 data.text = strdup(text);
581 /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
582 if (0 != ttsd_data_add_speak_data(uid, data)) {
583 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add speak data");
584 if (NULL != temp_lang) free(temp_lang);
585 return TTSD_ERROR_OPERATION_FAILED;
588 if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
589 /* Request load voice */
590 SLOG(LOG_DEBUG, get_tag(), "[Server] Request to load voice");
591 if (0 != ttsd_engine_load_voice(temp_lang, temp_type)) {
592 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load voice");
596 if (NULL != temp_lang) free(temp_lang);
598 if (APP_STATE_PLAYING == state) {
599 /* check if engine use network */
600 if (ttsd_engine_agent_need_network()) {
601 if (false == ttsd_network_is_connected()) {
602 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network.");
603 return TTSD_ERROR_OPERATION_FAILED;
607 /* Check whether tts-engine is running or not */
608 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
609 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
615 return TTSD_ERROR_NONE;
618 Eina_Bool __send_interrupt_client(void *data)
622 int pid = ttsd_data_get_pid(uid);
624 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
625 /* send message to client about changing state */
626 ttsdc_send_set_state_message (pid, uid, APP_STATE_READY);
628 ttsdc_send_set_state_message (pid, uid, APP_STATE_PAUSED);
634 int ttsd_server_play(int uid)
637 if (0 > ttsd_data_get_client_state(uid, &state)) {
638 SECURE_SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid(%d) is NOT valid ", uid);
639 return TTSD_ERROR_INVALID_PARAMETER;
642 if (APP_STATE_PLAYING == state) {
643 SECURE_SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
644 return TTSD_ERROR_NONE;
647 /* check if engine use network */
648 if (ttsd_engine_agent_need_network()) {
649 if (false == ttsd_network_is_connected()) {
650 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Disconnect network. Current engine needs network service!!!.");
651 return TTSD_ERROR_OUT_OF_NETWORK;
655 int current_uid = ttsd_data_get_current_playing();
657 if (uid != current_uid && -1 != current_uid) {
658 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
659 /* Send interrupt message */
660 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
663 if (0 != ttsd_server_stop(current_uid)) {
664 SECURE_SLOG(LOG_WARN, get_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
667 ecore_timer_add(0, __send_interrupt_client, (void*)current_uid);
669 /* Default mode policy of interrupt is "Pause" */
671 /* Send interrupt message */
672 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
675 if (0 != ttsd_player_pause(current_uid)) {
676 SECURE_SLOG(LOG_WARN, get_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
680 ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
682 ecore_timer_add(0, __send_interrupt_client, (void*)current_uid);
686 /* Change current play */
687 if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
688 SECURE_SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
689 return TTSD_ERROR_OPERATION_FAILED;
692 if (APP_STATE_PAUSED == state) {
693 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
696 if (0 != ttsd_player_resume(uid)) {
697 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
701 /* Check whether tts-engine is running or not */
702 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
703 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
708 return TTSD_ERROR_NONE;
712 int ttsd_server_stop(int uid)
715 if (0 > ttsd_data_get_client_state(uid, &state)) {
716 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid");
717 return TTSD_ERROR_INVALID_PARAMETER;
720 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
721 if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
722 SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running");
725 ret = ttsd_engine_cancel_synthesis();
727 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
730 __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
732 if (0 != ttsd_player_stop(uid))
733 SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()");
735 ttsd_data_set_client_state(uid, APP_STATE_READY);
739 ttsd_data_clear_data(uid);
741 return TTSD_ERROR_NONE;
744 int ttsd_server_pause(int uid, int* utt_id)
747 if (0 > ttsd_data_get_client_state(uid, &state)) {
748 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
749 return TTSD_ERROR_INVALID_PARAMETER;
752 if (APP_STATE_PLAYING != state) {
753 SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is not 'play'");
754 return TTSD_ERROR_INVALID_STATE;
758 ret = ttsd_player_pause(uid);
760 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
761 return TTSD_ERROR_OPERATION_FAILED;
764 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
766 return TTSD_ERROR_NONE;
769 int ttsd_server_get_support_voices(int uid, GList** voice_list)
772 if (0 > ttsd_data_get_client_state(uid, &state)) {
773 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] uid is not valid");
774 return TTSD_ERROR_INVALID_PARAMETER;
778 if (0 != ttsd_engine_get_voice_list(voice_list)) {
779 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices()");
780 return TTSD_ERROR_OPERATION_FAILED;
783 SLOG(LOG_DEBUG, get_tag(), "[Server SUCCESS] Get supported voices");
785 return TTSD_ERROR_NONE;
788 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
791 if (0 > ttsd_data_get_client_state(uid, &state)) {
792 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
793 return TTSD_ERROR_INVALID_PARAMETER;
796 /* get current voice */
797 int ret = ttsd_engine_get_default_voice(language, voice_type);
799 SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail ttsd_server_get_support_voices()");
803 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Server] Get default language (%s), voice type(%d) ", *language, *voice_type);
805 return TTSD_ERROR_NONE;