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"
33 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
34 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
35 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
36 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
37 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
38 #define TTS_TAG_CONFIG_LANGUAGE "language"
39 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
40 #define TTS_TAG_CONFIG_PITCH "pitch"
41 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
42 #define TTS_TAG_VOICE_TYPE_MALE "male"
43 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 extern char* tts_tag();
48 static xmlDocPtr g_config_doc = NULL;
49 char g_engine_id[128] = {0,};
50 char g_setting[128] = {0,};
51 char g_language[128] = {0,};
53 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
55 if (NULL == path || NULL == engine_info) {
56 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
61 xmlNodePtr cur = NULL;
65 doc = xmlParseFile(path);
67 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
71 cur = xmlDocGetRootElement(doc);
73 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
79 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
80 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
86 cur = cur->xmlChildrenNode;
88 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
94 /* alloc engine info */
95 tts_engine_info_s* temp;
96 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
98 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
107 temp->setting = NULL;
108 temp->pitch_support = false;
110 while (cur != NULL) {
111 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
112 key = xmlNodeGetContent(cur);
114 if (NULL != temp->name) {
118 temp->name = strdup((char*)key);
122 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
124 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
125 key = xmlNodeGetContent(cur);
127 if (NULL != temp->uuid) {
131 temp->uuid = strdup((char*)key);
135 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
137 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
138 key = xmlNodeGetContent(cur);
140 if (NULL != temp->setting) {
142 temp->setting = NULL;
144 temp->setting = strdup((char*)key);
148 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
150 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
151 xmlNodePtr voice_node = NULL;
152 voice_node = cur->xmlChildrenNode;
154 while (NULL != voice_node) {
155 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
156 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
157 if (NULL == temp_voice) {
158 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
162 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
164 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
165 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
166 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
167 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
168 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
169 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
171 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
176 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
182 key = xmlNodeGetContent(voice_node);
184 if (NULL != temp_voice->language) {
185 free(temp_voice->language);
186 temp_voice->language = NULL;
188 temp_voice->language = strdup((char*)key);
191 temp->voices = g_slist_append(temp->voices, temp_voice);
193 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
194 if (NULL != temp_voice) {
200 voice_node = voice_node->next;
202 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
203 key = xmlNodeGetContent(cur);
205 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
206 temp->pitch_support = true;
211 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
220 if (NULL == temp->name || NULL == temp->uuid) {
222 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
223 tts_parser_free_engine_info(temp);
232 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
234 if (NULL == engine_info) {
235 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
239 if (NULL != engine_info->name) {
240 free(engine_info->name);
241 engine_info->name = NULL;
243 if (NULL != engine_info->uuid) {
244 free(engine_info->uuid);
245 engine_info->uuid = NULL;
247 if (NULL != engine_info->setting) {
248 free(engine_info->setting);
249 engine_info->setting = NULL;
252 tts_config_voice_s *temp_voice;
253 temp_voice = g_slist_nth_data(engine_info->voices, 0);
255 while (NULL != temp_voice) {
256 if (NULL != temp_voice) {
257 if (NULL != temp_voice->language) {
258 free(temp_voice->language);
259 temp_voice->language = NULL;
261 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
266 temp_voice = g_slist_nth_data(engine_info->voices, 0);
269 if (NULL != engine_info) {
277 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
279 if (NULL == engine_info) {
280 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
284 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
285 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
286 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
287 if (NULL != engine_info->setting)
288 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
290 SLOG(LOG_DEBUG, tts_tag(), " voices");
292 tts_config_voice_s *temp_voice;
294 if (g_slist_length(engine_info->voices) > 0) {
295 /* Get a first item */
296 iter = g_slist_nth(engine_info->voices, 0);
299 while (NULL != iter) {
300 /*Get handle data from list*/
301 temp_voice = iter->data;
303 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
304 i, temp_voice->type, temp_voice->language);
307 iter = g_slist_next(iter);
311 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
314 SLOG(LOG_DEBUG, tts_tag(), "=====================");
319 int tts_parser_load_config(tts_config_s** config_info)
321 if (NULL == config_info) {
322 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
326 xmlDocPtr doc = NULL;
327 xmlNodePtr cur = NULL;
329 bool is_default_open = false;
331 /* For Thread safety */
334 if (0 != access(TTS_CONFIG, F_OK)) {
335 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
337 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
341 is_default_open = true;
345 while (NULL == doc) {
346 doc = xmlParseFile(TTS_CONFIG);
353 if (TTS_RETRY_COUNT == retry_count) {
354 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
361 cur = xmlDocGetRootElement(doc);
363 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
370 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
371 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
378 cur = cur->xmlChildrenNode;
380 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
387 /* alloc engine info */
389 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
391 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
398 memset(g_engine_id, '\0', sizeof(g_engine_id));
399 memset(g_setting, '\0', sizeof(g_setting));
400 memset(g_language, '\0', sizeof(g_language));
402 temp->engine_id = g_engine_id;
403 temp->setting = g_setting;
404 temp->language = g_language;
406 while (cur != NULL) {
407 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
408 key = xmlNodeGetContent(cur);
410 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
414 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
416 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
417 key = xmlNodeGetContent(cur);
419 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
423 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
425 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
426 key = xmlNodeGetContent(cur);
428 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
429 temp->auto_voice = true;
430 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
431 temp->auto_voice = false;
433 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
434 temp->auto_voice = true;
440 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
442 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
443 key = xmlNodeGetContent(cur);
445 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
446 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
447 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
448 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
449 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
450 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
452 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
453 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
459 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
461 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
462 key = xmlNodeGetContent(cur);
464 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
468 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
471 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
472 key = xmlNodeGetContent(cur);
474 temp->speech_rate = atoi((char*)key);
477 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
479 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
480 key = xmlNodeGetContent(cur);
482 temp->pitch = atoi((char*)key);
486 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
498 if (true == is_default_open) {
499 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
501 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
505 if (0 > chmod(TTS_CONFIG, 0666)) {
506 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
510 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
511 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
513 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
519 int tts_parser_unload_config(tts_config_s* config_info)
521 if (NULL != g_config_doc) {
522 xmlFreeDoc(g_config_doc);
525 if (NULL != config_info) {
536 int tts_parser_copy_xml(const char* original, const char* destination)
538 if (NULL == original || NULL == destination) {
539 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
543 xmlDocPtr doc = NULL;
544 doc = xmlParseFile(original);
546 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
550 int ret = xmlSaveFile(destination, doc);
552 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
556 if (0 > chmod(destination, 0666)) {
557 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
562 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
567 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
569 if (NULL == engine_id) {
570 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
574 xmlNodePtr cur = NULL;
575 cur = xmlDocGetRootElement(g_config_doc);
577 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
581 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
582 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
586 cur = cur->xmlChildrenNode;
588 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
592 while (cur != NULL) {
593 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
594 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
597 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
598 xmlNodeSetContent(cur, (const xmlChar *)language);
601 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
602 xmlNodeSetContent(cur, (const xmlChar *)setting);
605 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
607 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
608 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
609 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
610 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
617 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
619 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
625 int tts_parser_set_voice(const char* language, int type)
627 if (NULL == language) {
628 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
632 xmlNodePtr cur = NULL;
633 cur = xmlDocGetRootElement(g_config_doc);
635 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
639 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
640 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
644 cur = cur->xmlChildrenNode;
646 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
650 while (cur != NULL) {
651 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
652 xmlNodeSetContent(cur, (const xmlChar *)language);
655 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
657 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
658 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
659 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
661 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
662 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
670 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
672 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
678 int tts_parser_set_auto_voice(bool value)
680 xmlNodePtr cur = NULL;
681 cur = xmlDocGetRootElement(g_config_doc);
683 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
687 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
688 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
692 cur = cur->xmlChildrenNode;
694 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
698 while (cur != NULL) {
699 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
701 xmlNodeSetContent(cur, (const xmlChar *)"on");
702 } else if (false == value) {
703 xmlNodeSetContent(cur, (const xmlChar *)"off");
705 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
713 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
715 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
721 int tts_parser_set_speech_rate(int value)
723 xmlNodePtr cur = NULL;
724 cur = xmlDocGetRootElement(g_config_doc);
726 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
730 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
731 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
735 cur = cur->xmlChildrenNode;
737 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
741 while (cur != NULL) {
742 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
744 memset(temp, '\0', 10);
745 snprintf(temp, 10, "%d", value);
747 xmlNodeSetContent(cur, (const xmlChar *)temp);
749 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
756 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
758 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
764 int tts_parser_set_pitch(int value)
766 xmlNodePtr cur = NULL;
767 cur = xmlDocGetRootElement(g_config_doc);
769 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
773 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
774 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
778 cur = cur->xmlChildrenNode;
780 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
784 while (cur != NULL) {
785 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
787 memset(temp, '\0', 10);
788 snprintf(temp, 10, "%d", value);
789 xmlNodeSetContent(cur, (const xmlChar *)temp);
796 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
798 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
804 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
805 int* speech_rate, int* pitch)
807 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
808 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
812 xmlDocPtr doc = NULL;
813 xmlNodePtr cur_new = NULL;
814 xmlNodePtr cur_old = NULL;
820 while (NULL == doc) {
821 doc = xmlParseFile(TTS_CONFIG);
828 if (TTS_RETRY_COUNT == retry_count) {
829 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
834 cur_new = xmlDocGetRootElement(doc);
835 cur_old = xmlDocGetRootElement(g_config_doc);
836 if (cur_new == NULL || cur_old == NULL) {
837 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
843 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
844 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
845 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
851 cur_new = cur_new->xmlChildrenNode;
852 cur_old = cur_old->xmlChildrenNode;
853 if (cur_new == NULL || cur_old == NULL) {
854 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
860 while (cur_new != NULL && cur_old != NULL) {
861 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
862 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
863 key_old = xmlNodeGetContent(cur_old);
864 if (NULL != key_old) {
865 key_new = xmlNodeGetContent(cur_new);
866 if (NULL != key_new) {
867 if (0 != xmlStrcmp(key_old, key_new)) {
868 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
869 (char*)key_old, (char*)key_new);
870 if (NULL != *engine) {
874 *engine = strdup((char*)key_new);
883 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
885 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
886 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
887 key_old = xmlNodeGetContent(cur_old);
888 if (NULL != key_old) {
889 key_new = xmlNodeGetContent(cur_new);
890 if (NULL != key_new) {
891 if (0 != xmlStrcmp(key_old, key_new)) {
892 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
893 (char*)key_old, (char*)key_new);
894 if (NULL != *setting) {
898 *setting = strdup((char*)key_new);
907 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
909 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
910 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
911 key_old = xmlNodeGetContent(cur_old);
912 if (NULL != key_old) {
913 key_new = xmlNodeGetContent(cur_new);
914 if (NULL != key_new) {
915 if (0 != xmlStrcmp(key_old, key_new)) {
916 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
917 (char*)key_old, (char*)key_new);
918 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
931 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
933 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
934 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
935 key_old = xmlNodeGetContent(cur_old);
936 if (NULL != key_old) {
937 key_new = xmlNodeGetContent(cur_new);
938 if (NULL != key_new) {
939 if (0 != xmlStrcmp(key_old, key_new)) {
940 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
941 (char*)key_old, (char*)key_new);
942 if (NULL != *language) {
946 *language = strdup((char*)key_new);
955 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
957 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
958 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
959 key_old = xmlNodeGetContent(cur_old);
960 if (NULL != key_old) {
961 key_new = xmlNodeGetContent(cur_new);
962 if (NULL != key_new) {
963 if (0 != xmlStrcmp(key_old, key_new)) {
964 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
965 (char*)key_old, (char*)key_new);
966 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
967 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
968 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
969 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
970 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
971 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
973 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
983 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
985 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
986 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
987 key_old = xmlNodeGetContent(cur_old);
988 if (NULL != key_old) {
989 key_new = xmlNodeGetContent(cur_new);
990 if (NULL != key_new) {
991 if (0 != xmlStrcmp(key_old, key_new)) {
992 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
993 (char*)key_old, (char*)key_new);
994 *speech_rate = atoi((char*)key_new);
1003 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1005 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1006 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1007 key_old = xmlNodeGetContent(cur_old);
1008 if (NULL != key_old) {
1009 key_new = xmlNodeGetContent(cur_new);
1010 if (NULL != key_new) {
1011 if (0 != xmlStrcmp(key_old, key_new)) {
1012 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1013 (char*)key_old, (char*)key_new);
1014 *pitch = atoi((char*)key_new);
1023 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1029 cur_new = cur_new->next;
1030 cur_old = cur_old->next;
1033 if (NULL != g_config_doc) {
1034 xmlFreeDoc(g_config_doc);
1035 g_config_doc = NULL;