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"
47 extern char* tts_tag();
49 static xmlDocPtr g_config_doc = NULL;
50 char g_engine_id[128] = {0,};
51 char g_setting[128] = {0,};
52 char g_language[128] = {0,};
54 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
56 if (NULL == path || NULL == engine_info) {
57 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
62 xmlNodePtr cur = NULL;
66 doc = xmlParseFile(path);
68 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
72 cur = xmlDocGetRootElement(doc);
74 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
80 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
81 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
87 cur = cur->xmlChildrenNode;
89 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
95 /* alloc engine info */
96 tts_engine_info_s* temp;
97 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
99 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
108 temp->setting = NULL;
109 temp->pitch_support = false;
112 while (cur != NULL) {
113 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
114 key = xmlNodeGetContent(cur);
116 if (NULL != temp->name) {
120 temp->name = strdup((char*)key);
124 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
126 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
127 key = xmlNodeGetContent(cur);
129 if (NULL != temp->uuid) {
133 temp->uuid = strdup((char*)key);
137 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
139 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
140 key = xmlNodeGetContent(cur);
142 if (NULL != temp->setting) {
144 temp->setting = NULL;
146 temp->setting = strdup((char*)key);
150 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
152 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
153 xmlNodePtr voice_node = NULL;
154 voice_node = cur->xmlChildrenNode;
156 while (NULL != voice_node) {
157 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
158 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
159 if (NULL == temp_voice) {
160 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
164 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
166 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
167 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
168 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
169 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
170 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
171 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
173 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
178 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
184 key = xmlNodeGetContent(voice_node);
186 if (NULL != temp_voice->language) {
187 free(temp_voice->language);
188 temp_voice->language = NULL;
190 temp_voice->language = strdup((char*)key);
193 temp->voices = g_slist_append(temp->voices, temp_voice);
195 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
196 if (NULL != temp_voice) {
202 voice_node = voice_node->next;
204 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
205 key = xmlNodeGetContent(cur);
207 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
208 temp->pitch_support = true;
213 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
215 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
216 key = xmlNodeGetContent(cur);
218 temp->text_size = atoi((char*)key);
221 SLOG(LOG_INFO, tts_tag(), "[INFO] text size is unlimited.");
231 if (NULL == temp->name || NULL == temp->uuid) {
233 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
234 tts_parser_free_engine_info(temp);
243 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
245 if (NULL == engine_info) {
246 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
250 if (NULL != engine_info->name) {
251 free(engine_info->name);
252 engine_info->name = NULL;
254 if (NULL != engine_info->uuid) {
255 free(engine_info->uuid);
256 engine_info->uuid = NULL;
258 if (NULL != engine_info->setting) {
259 free(engine_info->setting);
260 engine_info->setting = NULL;
263 tts_config_voice_s *temp_voice;
264 temp_voice = g_slist_nth_data(engine_info->voices, 0);
266 while (NULL != temp_voice) {
267 if (NULL != temp_voice) {
268 if (NULL != temp_voice->language) {
269 free(temp_voice->language);
270 temp_voice->language = NULL;
272 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
277 temp_voice = g_slist_nth_data(engine_info->voices, 0);
280 if (NULL != engine_info) {
288 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
290 if (NULL == engine_info) {
291 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
295 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
296 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
297 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
298 if (NULL != engine_info->setting)
299 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
301 SLOG(LOG_DEBUG, tts_tag(), " voices");
303 tts_config_voice_s *temp_voice;
305 if (g_slist_length(engine_info->voices) > 0) {
306 /* Get a first item */
307 iter = g_slist_nth(engine_info->voices, 0);
310 while (NULL != iter) {
311 /*Get handle data from list*/
312 temp_voice = iter->data;
314 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
315 i, temp_voice->type, temp_voice->language);
318 iter = g_slist_next(iter);
322 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
325 SLOG(LOG_DEBUG, tts_tag(), "=====================");
330 int tts_parser_load_config(tts_config_s** config_info)
332 if (NULL == config_info) {
333 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
337 xmlDocPtr doc = NULL;
338 xmlNodePtr cur = NULL;
340 bool is_default_open = false;
342 /* For Thread safety */
345 if (0 != access(TTS_CONFIG, F_OK)) {
346 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
348 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
352 is_default_open = true;
356 while (NULL == doc) {
357 doc = xmlParseFile(TTS_CONFIG);
364 if (TTS_RETRY_COUNT == retry_count) {
365 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
372 cur = xmlDocGetRootElement(doc);
374 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
381 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
382 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
389 cur = cur->xmlChildrenNode;
391 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
398 /* alloc engine info */
400 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
402 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
409 memset(g_engine_id, '\0', sizeof(g_engine_id));
410 memset(g_setting, '\0', sizeof(g_setting));
411 memset(g_language, '\0', sizeof(g_language));
413 temp->engine_id = g_engine_id;
414 temp->setting = g_setting;
415 temp->language = g_language;
417 while (cur != NULL) {
418 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
419 key = xmlNodeGetContent(cur);
421 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
425 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
427 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
428 key = xmlNodeGetContent(cur);
430 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
434 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
436 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
437 key = xmlNodeGetContent(cur);
439 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
440 temp->auto_voice = true;
441 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
442 temp->auto_voice = false;
444 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
445 temp->auto_voice = true;
451 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
453 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
454 key = xmlNodeGetContent(cur);
456 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
457 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
458 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
459 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
460 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
461 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
463 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
464 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
470 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
472 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
473 key = xmlNodeGetContent(cur);
475 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
479 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
482 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
483 key = xmlNodeGetContent(cur);
485 temp->speech_rate = atoi((char*)key);
488 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
490 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
491 key = xmlNodeGetContent(cur);
493 temp->pitch = atoi((char*)key);
497 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
509 if (true == is_default_open) {
510 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
512 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
516 if (0 > chmod(TTS_CONFIG, 0666)) {
517 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
521 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
522 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
524 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
530 int tts_parser_unload_config(tts_config_s* config_info)
532 if (NULL != g_config_doc) {
533 xmlFreeDoc(g_config_doc);
536 if (NULL != config_info) {
547 int tts_parser_copy_xml(const char* original, const char* destination)
549 if (NULL == original || NULL == destination) {
550 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
554 xmlDocPtr doc = NULL;
555 doc = xmlParseFile(original);
557 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
561 int ret = xmlSaveFile(destination, doc);
563 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
567 if (0 > chmod(destination, 0666)) {
568 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
573 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
578 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
580 if (NULL == engine_id) {
581 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
585 xmlNodePtr cur = NULL;
586 cur = xmlDocGetRootElement(g_config_doc);
588 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
592 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
593 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
597 cur = cur->xmlChildrenNode;
599 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
603 while (cur != NULL) {
604 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
605 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
608 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
609 xmlNodeSetContent(cur, (const xmlChar *)language);
612 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
613 xmlNodeSetContent(cur, (const xmlChar *)setting);
616 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
618 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
619 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
620 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
621 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
628 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
630 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
636 int tts_parser_set_voice(const char* language, int type)
638 if (NULL == language) {
639 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
643 xmlNodePtr cur = NULL;
644 cur = xmlDocGetRootElement(g_config_doc);
646 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
650 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
651 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
655 cur = cur->xmlChildrenNode;
657 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
661 while (cur != NULL) {
662 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
663 xmlNodeSetContent(cur, (const xmlChar *)language);
666 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
668 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
669 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
670 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
672 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
673 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
681 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
683 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
689 int tts_parser_set_auto_voice(bool value)
691 xmlNodePtr cur = NULL;
692 cur = xmlDocGetRootElement(g_config_doc);
694 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
698 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
699 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
703 cur = cur->xmlChildrenNode;
705 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
709 while (cur != NULL) {
710 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
712 xmlNodeSetContent(cur, (const xmlChar *)"on");
713 } else if (false == value) {
714 xmlNodeSetContent(cur, (const xmlChar *)"off");
716 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
724 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
726 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
732 int tts_parser_set_speech_rate(int value)
734 xmlNodePtr cur = NULL;
735 cur = xmlDocGetRootElement(g_config_doc);
737 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
741 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
742 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
746 cur = cur->xmlChildrenNode;
748 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
752 while (cur != NULL) {
753 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
755 memset(temp, '\0', 10);
756 snprintf(temp, 10, "%d", value);
758 xmlNodeSetContent(cur, (const xmlChar *)temp);
760 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
767 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
769 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
775 int tts_parser_set_pitch(int value)
777 xmlNodePtr cur = NULL;
778 cur = xmlDocGetRootElement(g_config_doc);
780 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
784 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
785 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
789 cur = cur->xmlChildrenNode;
791 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
795 while (cur != NULL) {
796 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
798 memset(temp, '\0', 10);
799 snprintf(temp, 10, "%d", value);
800 xmlNodeSetContent(cur, (const xmlChar *)temp);
807 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
809 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
815 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
816 int* speech_rate, int* pitch)
818 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
819 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
823 xmlDocPtr doc = NULL;
824 xmlNodePtr cur_new = NULL;
825 xmlNodePtr cur_old = NULL;
831 while (NULL == doc) {
832 doc = xmlParseFile(TTS_CONFIG);
839 if (TTS_RETRY_COUNT == retry_count) {
840 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
845 cur_new = xmlDocGetRootElement(doc);
846 cur_old = xmlDocGetRootElement(g_config_doc);
847 if (cur_new == NULL || cur_old == NULL) {
848 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
854 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
855 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
856 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
862 cur_new = cur_new->xmlChildrenNode;
863 cur_old = cur_old->xmlChildrenNode;
864 if (cur_new == NULL || cur_old == NULL) {
865 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
871 while (cur_new != NULL && cur_old != NULL) {
872 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
873 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
874 key_old = xmlNodeGetContent(cur_old);
875 if (NULL != key_old) {
876 key_new = xmlNodeGetContent(cur_new);
877 if (NULL != key_new) {
878 if (0 != xmlStrcmp(key_old, key_new)) {
879 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
880 (char*)key_old, (char*)key_new);
881 if (NULL != *engine) {
885 *engine = strdup((char*)key_new);
894 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
896 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
897 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
898 key_old = xmlNodeGetContent(cur_old);
899 if (NULL != key_old) {
900 key_new = xmlNodeGetContent(cur_new);
901 if (NULL != key_new) {
902 if (0 != xmlStrcmp(key_old, key_new)) {
903 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
904 (char*)key_old, (char*)key_new);
905 if (NULL != *setting) {
909 *setting = strdup((char*)key_new);
918 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
920 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
921 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
922 key_old = xmlNodeGetContent(cur_old);
923 if (NULL != key_old) {
924 key_new = xmlNodeGetContent(cur_new);
925 if (NULL != key_new) {
926 if (0 != xmlStrcmp(key_old, key_new)) {
927 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
928 (char*)key_old, (char*)key_new);
929 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
942 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
944 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
945 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
946 key_old = xmlNodeGetContent(cur_old);
947 if (NULL != key_old) {
948 key_new = xmlNodeGetContent(cur_new);
949 if (NULL != key_new) {
950 if (0 != xmlStrcmp(key_old, key_new)) {
951 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
952 (char*)key_old, (char*)key_new);
953 if (NULL != *language) {
957 *language = strdup((char*)key_new);
966 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
968 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
969 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
970 key_old = xmlNodeGetContent(cur_old);
971 if (NULL != key_old) {
972 key_new = xmlNodeGetContent(cur_new);
973 if (NULL != key_new) {
974 if (0 != xmlStrcmp(key_old, key_new)) {
975 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
976 (char*)key_old, (char*)key_new);
977 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
978 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
979 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
980 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
981 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
982 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
984 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
994 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
996 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
997 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
998 key_old = xmlNodeGetContent(cur_old);
999 if (NULL != key_old) {
1000 key_new = xmlNodeGetContent(cur_new);
1001 if (NULL != key_new) {
1002 if (0 != xmlStrcmp(key_old, key_new)) {
1003 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1004 (char*)key_old, (char*)key_new);
1005 *speech_rate = atoi((char*)key_new);
1014 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1016 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1017 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1018 key_old = xmlNodeGetContent(cur_old);
1019 if (NULL != key_old) {
1020 key_new = xmlNodeGetContent(cur_new);
1021 if (NULL != key_new) {
1022 if (0 != xmlStrcmp(key_old, key_new)) {
1023 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1024 (char*)key_old, (char*)key_new);
1025 *pitch = atoi((char*)key_new);
1034 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1040 cur_new = cur_new->next;
1041 cur_old = cur_old->next;
1044 if (NULL != g_config_doc) {
1045 xmlFreeDoc(g_config_doc);
1046 g_config_doc = NULL;