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;
50 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
52 if (NULL == path || NULL == engine_info) {
53 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
58 xmlNodePtr cur = NULL;
62 doc = xmlParseFile(path);
67 cur = xmlDocGetRootElement(doc);
69 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
74 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
75 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
80 cur = cur->xmlChildrenNode;
82 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
87 /* alloc engine info */
88 tts_engine_info_s* temp;
89 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
91 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
100 temp->pitch_support = false;
102 while (cur != NULL) {
103 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
104 key = xmlNodeGetContent(cur);
106 if (NULL != temp->name) free(temp->name);
107 temp->name = strdup((char*)key);
110 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
112 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
113 key = xmlNodeGetContent(cur);
115 if (NULL != temp->uuid) free(temp->uuid);
116 temp->uuid = strdup((char*)key);
119 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
121 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
122 key = xmlNodeGetContent(cur);
124 if (NULL != temp->setting) free(temp->setting);
125 temp->setting = strdup((char*)key);
128 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
130 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
131 xmlNodePtr voice_node = NULL;
132 voice_node = cur->xmlChildrenNode;
134 while (NULL != voice_node) {
135 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
137 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
138 if (NULL == temp_voice) {
139 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
143 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
145 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
146 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
147 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
148 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
149 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
150 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
152 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
156 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
159 key = xmlNodeGetContent(voice_node);
161 if (NULL != temp_voice->language) free(temp_voice->language);
162 temp_voice->language = strdup((char*)key);
164 temp->voices = g_slist_append(temp->voices, temp_voice);
166 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
167 if (NULL != temp_voice) {
172 voice_node = voice_node->next;
174 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
175 key = xmlNodeGetContent(cur);
177 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
178 temp->pitch_support = true;
182 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
190 if (NULL == temp->name || NULL == temp->uuid) {
192 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
193 tts_parser_free_engine_info(temp);
202 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
204 if (NULL == engine_info) {
205 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
209 if (NULL != engine_info->name) free(engine_info->name);
210 if (NULL != engine_info->uuid) free(engine_info->uuid);
211 if (NULL != engine_info->setting) free(engine_info->setting);
213 tts_config_voice_s *temp_voice;
214 temp_voice = g_slist_nth_data(engine_info->voices, 0);
216 while (NULL != temp_voice) {
217 if (NULL != temp_voice) {
218 if (NULL != temp_voice->language) free(temp_voice->language);
219 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
223 temp_voice = g_slist_nth_data(engine_info->voices, 0);
226 if (NULL != engine_info) free(engine_info);
231 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
233 if (NULL == engine_info) {
234 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
238 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
239 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
240 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
241 if (NULL != engine_info->setting)
242 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
244 SLOG(LOG_DEBUG, tts_tag(), " voices");
246 tts_config_voice_s *temp_voice;
248 if (g_slist_length(engine_info->voices) > 0) {
249 /* Get a first item */
250 iter = g_slist_nth(engine_info->voices, 0);
253 while (NULL != iter) {
254 /*Get handle data from list*/
255 temp_voice = iter->data;
257 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
258 i, temp_voice->type, temp_voice->language);
261 iter = g_slist_next(iter);
265 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
268 SLOG(LOG_DEBUG, tts_tag(), "=====================");
273 int tts_parser_load_config(tts_config_s** config_info)
275 if (NULL == config_info) {
276 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
280 xmlDocPtr doc = NULL;
281 xmlNodePtr cur = NULL;
283 bool is_default_open = false;
285 if (0 != access(TTS_CONFIG, F_OK)) {
286 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
288 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
291 is_default_open = true;
295 while (NULL == doc) {
296 doc = xmlParseFile(TTS_CONFIG);
303 if (TTS_RETRY_COUNT == retry_count) {
304 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
310 cur = xmlDocGetRootElement(doc);
312 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
317 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
318 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
323 cur = cur->xmlChildrenNode;
325 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
330 /* alloc engine info */
332 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
334 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
339 temp->engine_id = NULL;
340 temp->setting = NULL;
341 temp->language = NULL;
343 while (cur != NULL) {
344 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
345 key = xmlNodeGetContent(cur);
347 if (NULL != temp->engine_id) free(temp->engine_id);
348 temp->engine_id = strdup((char*)key);
351 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
353 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
354 key = xmlNodeGetContent(cur);
356 if (NULL != temp->setting) free(temp->setting);
357 temp->setting = strdup((char*)key);
360 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
363 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
364 key = xmlNodeGetContent(cur);
366 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
367 temp->auto_voice = true;
368 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
369 temp->auto_voice = false;
371 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
372 temp->auto_voice = true;
377 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
379 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
380 key = xmlNodeGetContent(cur);
382 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
383 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
384 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
385 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
386 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
387 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
389 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
390 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
395 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
397 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
398 key = xmlNodeGetContent(cur);
400 if (NULL != temp->language) free(temp->language);
401 temp->language = strdup((char*)key);
404 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
407 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
408 key = xmlNodeGetContent(cur);
410 temp->speech_rate = atoi((char*)key);
413 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
415 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
416 key = xmlNodeGetContent(cur);
418 temp->pitch = atoi((char*)key);
421 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
433 if (true == is_default_open) {
434 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
436 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
440 if (0 > chmod(TTS_CONFIG, 0666)) {
441 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
445 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
446 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
448 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
454 int tts_parser_unload_config(tts_config_s* config_info)
456 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
457 if (NULL != config_info) {
458 if (NULL != config_info->engine_id) free(config_info->engine_id);
459 if (NULL != config_info->setting) free(config_info->setting);
460 if (NULL != config_info->language) free(config_info->language);
468 int tts_parser_copy_xml(const char* original, const char* destination)
470 if (NULL == original || NULL == destination) {
471 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
475 xmlDocPtr doc = NULL;
476 doc = xmlParseFile(original);
478 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
482 int ret = xmlSaveFile(destination, doc);
484 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
488 if (0 > chmod(destination, 0666)) {
489 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
493 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
498 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
500 if (NULL == engine_id) {
501 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
505 xmlNodePtr cur = NULL;
506 cur = xmlDocGetRootElement(g_config_doc);
508 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
512 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
513 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
517 cur = cur->xmlChildrenNode;
519 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
523 while (cur != NULL) {
524 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
525 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
528 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
529 xmlNodeSetContent(cur, (const xmlChar *)language);
532 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
533 xmlNodeSetContent(cur, (const xmlChar *)setting);
536 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
538 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
539 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
540 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
541 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
548 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
550 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
556 int tts_parser_set_voice(const char* language, int type)
558 if (NULL == language) {
559 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
563 xmlNodePtr cur = NULL;
564 cur = xmlDocGetRootElement(g_config_doc);
566 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
570 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
571 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
575 cur = cur->xmlChildrenNode;
577 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
581 while (cur != NULL) {
582 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
583 xmlNodeSetContent(cur, (const xmlChar *)language);
586 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
588 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
589 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
590 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
592 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
593 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
601 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
603 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
609 int tts_parser_set_auto_voice(bool value)
611 xmlNodePtr cur = NULL;
612 cur = xmlDocGetRootElement(g_config_doc);
614 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
618 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
619 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
623 cur = cur->xmlChildrenNode;
625 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
629 while (cur != NULL) {
630 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
632 xmlNodeSetContent(cur, (const xmlChar *)"on");
633 } else if (false == value) {
634 xmlNodeSetContent(cur, (const xmlChar *)"off");
636 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
644 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
646 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
652 int tts_parser_set_speech_rate(int value)
654 xmlNodePtr cur = NULL;
655 cur = xmlDocGetRootElement(g_config_doc);
657 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
661 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
662 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
666 cur = cur->xmlChildrenNode;
668 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
672 while (cur != NULL) {
673 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
675 memset(temp, '\0', 10);
676 snprintf(temp, 10, "%d", value);
678 xmlNodeSetContent(cur, (const xmlChar *)temp);
680 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
687 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
689 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
695 int tts_parser_set_pitch(int value)
697 xmlNodePtr cur = NULL;
698 cur = xmlDocGetRootElement(g_config_doc);
700 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
704 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
705 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
709 cur = cur->xmlChildrenNode;
711 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
715 while (cur != NULL) {
716 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
718 memset(temp, '\0', 10);
719 snprintf(temp, 10, "%d", value);
720 xmlNodeSetContent(cur, (const xmlChar *)temp);
727 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
729 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
735 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
736 int* speech_rate, int* pitch)
738 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
739 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
743 xmlDocPtr doc = NULL;
744 xmlNodePtr cur_new = NULL;
745 xmlNodePtr cur_old = NULL;
751 while (NULL == doc) {
752 doc = xmlParseFile(TTS_CONFIG);
759 if (TTS_RETRY_COUNT == retry_count) {
760 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
765 cur_new = xmlDocGetRootElement(doc);
766 cur_old = xmlDocGetRootElement(g_config_doc);
767 if (cur_new == NULL || cur_old == NULL) {
768 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
773 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
774 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
775 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
780 cur_new = cur_new->xmlChildrenNode;
781 cur_old = cur_old->xmlChildrenNode;
782 if (cur_new == NULL || cur_old == NULL) {
783 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
788 while (cur_new != NULL && cur_old != NULL) {
789 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
790 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
791 key_old = xmlNodeGetContent(cur_old);
792 if (NULL != key_old) {
793 key_new = xmlNodeGetContent(cur_new);
794 if (NULL != key_new) {
795 if (0 != xmlStrcmp(key_old, key_new)) {
796 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
797 (char*)key_old, (char*)key_new);
798 if (NULL != *engine) free(*engine);
799 *engine = strdup((char*)key_new);
806 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
808 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
809 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
810 key_old = xmlNodeGetContent(cur_old);
811 if (NULL != key_old) {
812 key_new = xmlNodeGetContent(cur_new);
813 if (NULL != key_new) {
814 if (0 != xmlStrcmp(key_old, key_new)) {
815 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
816 (char*)key_old, (char*)key_new);
817 if (NULL != *setting) free(*setting);
818 *setting = strdup((char*)key_new);
825 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
827 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
828 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
829 key_old = xmlNodeGetContent(cur_old);
830 if (NULL != key_old) {
831 key_new = xmlNodeGetContent(cur_new);
832 if (NULL != key_new) {
833 if (0 != xmlStrcmp(key_old, key_new)) {
834 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
835 (char*)key_old, (char*)key_new);
836 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
847 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
849 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
850 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
851 key_old = xmlNodeGetContent(cur_old);
852 if (NULL != key_old) {
853 key_new = xmlNodeGetContent(cur_new);
854 if (NULL != key_new) {
855 if (0 != xmlStrcmp(key_old, key_new)) {
856 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
857 (char*)key_old, (char*)key_new);
858 if (NULL != *language) free(*language);
859 *language = strdup((char*)key_new);
866 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
868 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
869 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
870 key_old = xmlNodeGetContent(cur_old);
871 if (NULL != key_old) {
872 key_new = xmlNodeGetContent(cur_new);
873 if (NULL != key_new) {
874 if (0 != xmlStrcmp(key_old, key_new)) {
875 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
876 (char*)key_old, (char*)key_new);
877 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
878 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
879 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
880 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
881 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
882 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
884 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
892 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
894 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
895 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
896 key_old = xmlNodeGetContent(cur_old);
897 if (NULL != key_old) {
898 key_new = xmlNodeGetContent(cur_new);
899 if (NULL != key_new) {
900 if (0 != xmlStrcmp(key_old, key_new)) {
901 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
902 (char*)key_old, (char*)key_new);
903 *speech_rate = atoi((char*)key_new);
910 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
912 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
913 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
914 key_old = xmlNodeGetContent(cur_old);
915 if (NULL != key_old) {
916 key_new = xmlNodeGetContent(cur_new);
917 if (NULL != key_new) {
918 if (0 != xmlStrcmp(key_old, key_new)) {
919 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
920 (char*)key_old, (char*)key_new);
921 *pitch = atoi((char*)key_new);
928 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
934 cur_new = cur_new->next;
935 cur_old = cur_old->next;
938 xmlFreeDoc(g_config_doc);