2 * Copyright (c) 2011-2016 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.
20 #include "tts_config_parser.h"
24 #define TTS_TAG_ENGINE_BASE_TAG "tts-engine"
25 #define TTS_TAG_ENGINE_NAME "name"
26 #define TTS_TAG_ENGINE_ID "id"
27 #define TTS_TAG_ENGINE_SETTING "setting"
28 #define TTS_TAG_ENGINE_VOICE_SET "voices"
29 #define TTS_TAG_ENGINE_VOICE "voice"
30 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
31 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
32 #define TTS_TAG_ENGINE_TEXT_SIZE "text-size"
34 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
35 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
36 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
37 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
38 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
39 #define TTS_TAG_CONFIG_LANGUAGE "language"
40 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
41 #define TTS_TAG_CONFIG_PITCH "pitch"
42 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
43 #define TTS_TAG_VOICE_TYPE_MALE "male"
44 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 #define TTS_MAX_TEXT_SIZE 2000
48 extern char* tts_tag();
50 static xmlDocPtr g_config_doc = NULL;
51 char g_engine_id[128] = {0,};
52 char g_setting[128] = {0,};
53 char g_language[128] = {0,};
55 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
57 if (NULL == path || NULL == engine_info) {
58 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
62 bool isTextsize = false;
64 xmlNodePtr cur = NULL;
68 doc = xmlParseFile(path);
70 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
74 cur = xmlDocGetRootElement(doc);
76 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
82 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
83 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
89 cur = cur->xmlChildrenNode;
91 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
97 /* alloc engine info */
98 tts_engine_info_s* temp;
99 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
101 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
110 temp->setting = NULL;
111 temp->pitch_support = false;
114 while (cur != NULL) {
115 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
116 key = xmlNodeGetContent(cur);
118 if (NULL != temp->name) {
122 temp->name = strdup((char*)key);
126 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
128 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
129 key = xmlNodeGetContent(cur);
131 if (NULL != temp->uuid) {
135 temp->uuid = strdup((char*)key);
139 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
141 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
142 key = xmlNodeGetContent(cur);
144 if (NULL != temp->setting) {
146 temp->setting = NULL;
148 temp->setting = strdup((char*)key);
152 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
154 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
155 xmlNodePtr voice_node = NULL;
156 voice_node = cur->xmlChildrenNode;
158 while (NULL != voice_node) {
159 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
160 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
161 if (NULL == temp_voice) {
162 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
166 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
168 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
169 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
170 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
171 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
172 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
173 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
175 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
180 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
186 key = xmlNodeGetContent(voice_node);
188 if (NULL != temp_voice->language) {
189 free(temp_voice->language);
190 temp_voice->language = NULL;
192 temp_voice->language = strdup((char*)key);
195 temp->voices = g_slist_append(temp->voices, temp_voice);
197 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
198 if (NULL != temp_voice) {
204 voice_node = voice_node->next;
206 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
207 key = xmlNodeGetContent(cur);
209 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
210 temp->pitch_support = true;
215 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
217 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
219 key = xmlNodeGetContent(cur);
221 temp->text_size = atoi((char*)key);
224 SLOG(LOG_INFO, tts_tag(), "[INFO] text size is unlimited.");
231 if (false == isTextsize) {
232 temp->text_size = TTS_MAX_TEXT_SIZE;
238 if (NULL == temp->uuid) {
240 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
241 tts_parser_free_engine_info(temp);
250 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
252 if (NULL == engine_info) {
253 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
257 if (NULL != engine_info->name) {
258 free(engine_info->name);
259 engine_info->name = NULL;
261 if (NULL != engine_info->uuid) {
262 free(engine_info->uuid);
263 engine_info->uuid = NULL;
265 if (NULL != engine_info->setting) {
266 free(engine_info->setting);
267 engine_info->setting = NULL;
270 tts_config_voice_s *temp_voice;
271 temp_voice = g_slist_nth_data(engine_info->voices, 0);
273 while (NULL != temp_voice) {
274 if (NULL != temp_voice) {
275 if (NULL != temp_voice->language) {
276 free(temp_voice->language);
277 temp_voice->language = NULL;
279 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
284 temp_voice = g_slist_nth_data(engine_info->voices, 0);
287 if (NULL != engine_info) {
295 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
297 if (NULL == engine_info) {
298 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
302 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
303 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
304 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
305 if (NULL != engine_info->setting)
306 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
308 SLOG(LOG_DEBUG, tts_tag(), " voices");
310 tts_config_voice_s *temp_voice;
312 if (g_slist_length(engine_info->voices) > 0) {
313 /* Get a first item */
314 iter = g_slist_nth(engine_info->voices, 0);
317 while (NULL != iter) {
318 /*Get handle data from list*/
319 temp_voice = iter->data;
321 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
322 i, temp_voice->type, temp_voice->language);
325 iter = g_slist_next(iter);
329 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
332 SLOG(LOG_DEBUG, tts_tag(), "@@@");
337 int tts_parser_load_config(tts_config_s** config_info)
339 if (NULL == config_info) {
340 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
344 xmlDocPtr doc = NULL;
345 xmlNodePtr cur = NULL;
347 bool is_default_open = false;
349 /* For Thread safety */
352 if (0 != access(TTS_CONFIG, F_OK)) {
353 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
355 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
359 is_default_open = true;
363 while (NULL == doc) {
364 doc = xmlParseFile(TTS_CONFIG);
371 if (TTS_RETRY_COUNT == retry_count) {
372 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
373 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
375 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
379 is_default_open = true;
385 cur = xmlDocGetRootElement(doc);
387 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
394 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
395 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
402 cur = cur->xmlChildrenNode;
404 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
411 /* alloc engine info */
413 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
415 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
422 memset(g_engine_id, '\0', sizeof(g_engine_id));
423 memset(g_setting, '\0', sizeof(g_setting));
424 memset(g_language, '\0', sizeof(g_language));
426 temp->engine_id = g_engine_id;
427 temp->setting = g_setting;
428 temp->language = g_language;
430 while (cur != NULL) {
431 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
432 key = xmlNodeGetContent(cur);
434 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
438 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
440 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
441 key = xmlNodeGetContent(cur);
443 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
447 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
449 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
450 key = xmlNodeGetContent(cur);
452 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
453 temp->auto_voice = true;
454 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
455 temp->auto_voice = false;
457 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
458 temp->auto_voice = true;
464 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
466 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
467 key = xmlNodeGetContent(cur);
469 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
470 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
471 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
472 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
473 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
474 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
476 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
477 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
483 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
485 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
486 key = xmlNodeGetContent(cur);
488 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
492 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
495 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
496 key = xmlNodeGetContent(cur);
498 temp->speech_rate = atoi((char*)key);
501 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
503 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
504 key = xmlNodeGetContent(cur);
506 temp->pitch = atoi((char*)key);
510 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
522 if (true == is_default_open) {
526 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
532 if (TTS_RETRY_COUNT == retry_count) {
533 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
539 if (0 > chmod(TTS_CONFIG, 0600)) {
540 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
544 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
545 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
547 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
553 int tts_parser_unload_config(tts_config_s* config_info)
555 if (NULL != g_config_doc) {
556 xmlFreeDoc(g_config_doc);
559 if (NULL != config_info) {
570 int tts_parser_copy_xml(const char* original, const char* destination)
572 if (NULL == original || NULL == destination) {
573 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
577 xmlDocPtr doc = NULL;
578 doc = xmlParseFile(original);
580 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
584 int ret = xmlSaveFile(destination, doc);
586 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
588 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", destination);
592 if (0 > chmod(destination, 0600)) {
593 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
598 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
603 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
605 if (NULL == engine_id) {
606 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
610 xmlNodePtr cur = NULL;
611 cur = xmlDocGetRootElement(g_config_doc);
613 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
617 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
618 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
622 cur = cur->xmlChildrenNode;
624 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
628 while (cur != NULL) {
629 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
630 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
633 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
634 xmlNodeSetContent(cur, (const xmlChar *)language);
637 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
638 xmlNodeSetContent(cur, (const xmlChar *)setting);
641 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
643 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
644 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
645 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
646 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
653 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
655 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
657 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
663 int tts_parser_set_voice(const char* language, int type)
665 if (NULL == language) {
666 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
670 xmlNodePtr cur = NULL;
671 cur = xmlDocGetRootElement(g_config_doc);
673 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
677 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
678 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
682 cur = cur->xmlChildrenNode;
684 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
688 while (cur != NULL) {
689 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
690 xmlNodeSetContent(cur, (const xmlChar *)language);
693 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
695 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
696 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
697 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
699 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
700 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
708 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
710 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
712 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
718 int tts_parser_set_auto_voice(bool value)
720 xmlNodePtr cur = NULL;
721 cur = xmlDocGetRootElement(g_config_doc);
723 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
727 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
728 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
732 cur = cur->xmlChildrenNode;
734 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
738 while (cur != NULL) {
739 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
741 xmlNodeSetContent(cur, (const xmlChar *)"on");
742 } else if (false == value) {
743 xmlNodeSetContent(cur, (const xmlChar *)"off");
745 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
753 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
755 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
757 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
763 int tts_parser_set_speech_rate(int value)
765 xmlNodePtr cur = NULL;
766 cur = xmlDocGetRootElement(g_config_doc);
768 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
772 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
773 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
777 cur = cur->xmlChildrenNode;
779 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
783 while (cur != NULL) {
784 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
786 memset(temp, '\0', 10);
787 snprintf(temp, 10, "%d", value);
789 xmlNodeSetContent(cur, (const xmlChar *)temp);
791 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
798 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
800 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
802 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
808 int tts_parser_set_pitch(int value)
810 xmlNodePtr cur = NULL;
811 cur = xmlDocGetRootElement(g_config_doc);
813 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
817 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
818 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
822 cur = cur->xmlChildrenNode;
824 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
828 while (cur != NULL) {
829 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
831 memset(temp, '\0', 10);
832 snprintf(temp, 10, "%d", value);
833 xmlNodeSetContent(cur, (const xmlChar *)temp);
840 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
842 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
844 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
850 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
851 int* speech_rate, int* pitch)
853 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
854 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
858 xmlDocPtr doc = NULL;
859 xmlNodePtr cur_new = NULL;
860 xmlNodePtr cur_old = NULL;
866 while (NULL == doc) {
867 doc = xmlParseFile(TTS_CONFIG);
874 if (TTS_RETRY_COUNT == retry_count) {
875 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
880 cur_new = xmlDocGetRootElement(doc);
881 cur_old = xmlDocGetRootElement(g_config_doc);
882 if (cur_new == NULL || cur_old == NULL) {
883 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
889 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
890 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
891 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
897 cur_new = cur_new->xmlChildrenNode;
898 cur_old = cur_old->xmlChildrenNode;
899 if (cur_new == NULL || cur_old == NULL) {
900 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
906 while (cur_new != NULL && cur_old != NULL) {
907 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
908 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
909 key_old = xmlNodeGetContent(cur_old);
910 if (NULL != key_old) {
911 key_new = xmlNodeGetContent(cur_new);
912 if (NULL != key_new) {
913 if (0 != xmlStrcmp(key_old, key_new)) {
914 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
915 (char*)key_old, (char*)key_new);
916 if (NULL != *engine) {
920 *engine = strdup((char*)key_new);
929 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
931 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
932 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
933 key_old = xmlNodeGetContent(cur_old);
934 if (NULL != key_old) {
935 key_new = xmlNodeGetContent(cur_new);
936 if (NULL != key_new) {
937 if (0 != xmlStrcmp(key_old, key_new)) {
938 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
939 (char*)key_old, (char*)key_new);
940 if (NULL != *setting) {
944 *setting = strdup((char*)key_new);
953 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
955 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
956 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
957 key_old = xmlNodeGetContent(cur_old);
958 if (NULL != key_old) {
959 key_new = xmlNodeGetContent(cur_new);
960 if (NULL != key_new) {
961 if (0 != xmlStrcmp(key_old, key_new)) {
962 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
963 (char*)key_old, (char*)key_new);
964 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
977 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
979 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
980 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
981 key_old = xmlNodeGetContent(cur_old);
982 if (NULL != key_old) {
983 key_new = xmlNodeGetContent(cur_new);
984 if (NULL != key_new) {
985 if (0 != xmlStrcmp(key_old, key_new)) {
986 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
987 (char*)key_old, (char*)key_new);
988 if (NULL != *language) {
992 *language = strdup((char*)key_new);
1001 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1003 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1004 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1005 key_old = xmlNodeGetContent(cur_old);
1006 if (NULL != key_old) {
1007 key_new = xmlNodeGetContent(cur_new);
1008 if (NULL != key_new) {
1009 if (0 != xmlStrcmp(key_old, key_new)) {
1010 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
1011 (char*)key_old, (char*)key_new);
1012 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1013 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1014 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1015 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1016 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1017 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1019 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
1029 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1031 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1032 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1033 key_old = xmlNodeGetContent(cur_old);
1034 if (NULL != key_old) {
1035 key_new = xmlNodeGetContent(cur_new);
1036 if (NULL != key_new) {
1037 if (0 != xmlStrcmp(key_old, key_new)) {
1038 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1039 (char*)key_old, (char*)key_new);
1040 *speech_rate = atoi((char*)key_new);
1049 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1051 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1052 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1053 key_old = xmlNodeGetContent(cur_old);
1054 if (NULL != key_old) {
1055 key_new = xmlNodeGetContent(cur_new);
1056 if (NULL != key_new) {
1057 if (0 != xmlStrcmp(key_old, key_new)) {
1058 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1059 (char*)key_old, (char*)key_new);
1060 *pitch = atoi((char*)key_new);
1069 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1075 cur_new = cur_new->next;
1076 cur_old = cur_old->next;
1079 if (NULL != g_config_doc) {
1080 xmlFreeDoc(g_config_doc);
1081 g_config_doc = NULL;
1088 int tts_parser_reset()
1090 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1092 if (NULL != g_config_doc) {
1093 xmlFreeDoc(g_config_doc);
1094 g_config_doc = NULL;
1097 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1098 if (NULL == g_config_doc) {
1099 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1103 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1105 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save %s", TTS_CONFIG);