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->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);
366 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
368 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
372 is_default_open = true;
378 cur = xmlDocGetRootElement(doc);
380 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
387 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
388 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
395 cur = cur->xmlChildrenNode;
397 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
404 /* alloc engine info */
406 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
408 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
415 memset(g_engine_id, '\0', sizeof(g_engine_id));
416 memset(g_setting, '\0', sizeof(g_setting));
417 memset(g_language, '\0', sizeof(g_language));
419 temp->engine_id = g_engine_id;
420 temp->setting = g_setting;
421 temp->language = g_language;
423 while (cur != NULL) {
424 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
425 key = xmlNodeGetContent(cur);
427 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
431 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
433 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
434 key = xmlNodeGetContent(cur);
436 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
440 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
442 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
443 key = xmlNodeGetContent(cur);
445 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
446 temp->auto_voice = true;
447 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
448 temp->auto_voice = false;
450 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
451 temp->auto_voice = true;
457 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
459 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
460 key = xmlNodeGetContent(cur);
462 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
463 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
464 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
465 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
466 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
467 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
469 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
470 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
476 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
478 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
479 key = xmlNodeGetContent(cur);
481 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
485 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
488 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
489 key = xmlNodeGetContent(cur);
491 temp->speech_rate = atoi((char*)key);
494 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
496 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
497 key = xmlNodeGetContent(cur);
499 temp->pitch = atoi((char*)key);
503 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
515 if (true == is_default_open) {
519 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
525 if (TTS_RETRY_COUNT == retry_count) {
526 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
532 if (0 > chmod(TTS_CONFIG, 0600)) {
533 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
537 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
538 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
540 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
546 int tts_parser_unload_config(tts_config_s* config_info)
548 if (NULL != g_config_doc) {
549 xmlFreeDoc(g_config_doc);
552 if (NULL != config_info) {
563 int tts_parser_copy_xml(const char* original, const char* destination)
565 if (NULL == original || NULL == destination) {
566 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
570 xmlDocPtr doc = NULL;
571 doc = xmlParseFile(original);
573 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
577 int ret = xmlSaveFile(destination, doc);
579 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
583 if (0 > chmod(destination, 0600)) {
584 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
589 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
594 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
596 if (NULL == engine_id) {
597 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
601 xmlNodePtr cur = NULL;
602 cur = xmlDocGetRootElement(g_config_doc);
604 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
608 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
609 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
613 cur = cur->xmlChildrenNode;
615 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
619 while (cur != NULL) {
620 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
621 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
624 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
625 xmlNodeSetContent(cur, (const xmlChar *)language);
628 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
629 xmlNodeSetContent(cur, (const xmlChar *)setting);
632 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
634 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
635 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
636 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
637 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
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_voice(const char* language, int type)
654 if (NULL == language) {
655 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
659 xmlNodePtr cur = NULL;
660 cur = xmlDocGetRootElement(g_config_doc);
662 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
666 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
667 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
671 cur = cur->xmlChildrenNode;
673 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
677 while (cur != NULL) {
678 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
679 xmlNodeSetContent(cur, (const xmlChar *)language);
682 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
684 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
685 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
686 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
688 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
689 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
697 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
699 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
705 int tts_parser_set_auto_voice(bool value)
707 xmlNodePtr cur = NULL;
708 cur = xmlDocGetRootElement(g_config_doc);
710 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
714 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
715 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
719 cur = cur->xmlChildrenNode;
721 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
725 while (cur != NULL) {
726 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
728 xmlNodeSetContent(cur, (const xmlChar *)"on");
729 } else if (false == value) {
730 xmlNodeSetContent(cur, (const xmlChar *)"off");
732 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
740 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
742 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
748 int tts_parser_set_speech_rate(int value)
750 xmlNodePtr cur = NULL;
751 cur = xmlDocGetRootElement(g_config_doc);
753 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
757 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
758 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
762 cur = cur->xmlChildrenNode;
764 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
768 while (cur != NULL) {
769 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
771 memset(temp, '\0', 10);
772 snprintf(temp, 10, "%d", value);
774 xmlNodeSetContent(cur, (const xmlChar *)temp);
776 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
783 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
785 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
791 int tts_parser_set_pitch(int value)
793 xmlNodePtr cur = NULL;
794 cur = xmlDocGetRootElement(g_config_doc);
796 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
800 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
801 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
805 cur = cur->xmlChildrenNode;
807 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
811 while (cur != NULL) {
812 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
814 memset(temp, '\0', 10);
815 snprintf(temp, 10, "%d", value);
816 xmlNodeSetContent(cur, (const xmlChar *)temp);
823 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
825 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
831 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
832 int* speech_rate, int* pitch)
834 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
835 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
839 xmlDocPtr doc = NULL;
840 xmlNodePtr cur_new = NULL;
841 xmlNodePtr cur_old = NULL;
847 while (NULL == doc) {
848 doc = xmlParseFile(TTS_CONFIG);
855 if (TTS_RETRY_COUNT == retry_count) {
856 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
861 cur_new = xmlDocGetRootElement(doc);
862 cur_old = xmlDocGetRootElement(g_config_doc);
863 if (cur_new == NULL || cur_old == NULL) {
864 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
870 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
871 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
872 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
878 cur_new = cur_new->xmlChildrenNode;
879 cur_old = cur_old->xmlChildrenNode;
880 if (cur_new == NULL || cur_old == NULL) {
881 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
887 while (cur_new != NULL && cur_old != NULL) {
888 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
889 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
890 key_old = xmlNodeGetContent(cur_old);
891 if (NULL != key_old) {
892 key_new = xmlNodeGetContent(cur_new);
893 if (NULL != key_new) {
894 if (0 != xmlStrcmp(key_old, key_new)) {
895 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
896 (char*)key_old, (char*)key_new);
897 if (NULL != *engine) {
901 *engine = strdup((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_ENGINE_SETTING)) {
913 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
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 engine setting(%s), New engine setting(%s)",
920 (char*)key_old, (char*)key_new);
921 if (NULL != *setting) {
925 *setting = strdup((char*)key_new);
934 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
936 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
937 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
938 key_old = xmlNodeGetContent(cur_old);
939 if (NULL != key_old) {
940 key_new = xmlNodeGetContent(cur_new);
941 if (NULL != key_new) {
942 if (0 != xmlStrcmp(key_old, key_new)) {
943 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
944 (char*)key_old, (char*)key_new);
945 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
958 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
960 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
961 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
962 key_old = xmlNodeGetContent(cur_old);
963 if (NULL != key_old) {
964 key_new = xmlNodeGetContent(cur_new);
965 if (NULL != key_new) {
966 if (0 != xmlStrcmp(key_old, key_new)) {
967 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
968 (char*)key_old, (char*)key_new);
969 if (NULL != *language) {
973 *language = strdup((char*)key_new);
982 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
984 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
985 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
986 key_old = xmlNodeGetContent(cur_old);
987 if (NULL != key_old) {
988 key_new = xmlNodeGetContent(cur_new);
989 if (NULL != key_new) {
990 if (0 != xmlStrcmp(key_old, key_new)) {
991 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
992 (char*)key_old, (char*)key_new);
993 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
994 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
995 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
996 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
997 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
998 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1000 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
1010 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1012 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1013 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1014 key_old = xmlNodeGetContent(cur_old);
1015 if (NULL != key_old) {
1016 key_new = xmlNodeGetContent(cur_new);
1017 if (NULL != key_new) {
1018 if (0 != xmlStrcmp(key_old, key_new)) {
1019 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1020 (char*)key_old, (char*)key_new);
1021 *speech_rate = atoi((char*)key_new);
1030 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1032 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1033 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1034 key_old = xmlNodeGetContent(cur_old);
1035 if (NULL != key_old) {
1036 key_new = xmlNodeGetContent(cur_new);
1037 if (NULL != key_new) {
1038 if (0 != xmlStrcmp(key_old, key_new)) {
1039 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1040 (char*)key_old, (char*)key_new);
1041 *pitch = atoi((char*)key_new);
1050 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1056 cur_new = cur_new->next;
1057 cur_old = cur_old->next;
1060 if (NULL != g_config_doc) {
1061 xmlFreeDoc(g_config_doc);
1062 g_config_doc = NULL;