2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
20 #include "tts_config_parser.h"
24 #define TTS_TAG_ENGINE_BASE_TAG "tts-engine"
25 #define TTS_TAG_ENGINE_NAME "name"
26 #define TTS_TAG_ENGINE_ID "id"
27 #define TTS_TAG_ENGINE_SETTING "setting"
28 #define TTS_TAG_ENGINE_VOICE_SET "voices"
29 #define TTS_TAG_ENGINE_VOICE "voice"
30 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
31 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
32 #define TTS_TAG_ENGINE_TEXT_SIZE "text-size"
34 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
35 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
36 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
37 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
38 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
39 #define TTS_TAG_CONFIG_LANGUAGE "language"
40 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
41 #define TTS_TAG_CONFIG_PITCH "pitch"
42 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
43 #define TTS_TAG_VOICE_TYPE_MALE "male"
44 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 #define TTS_MAX_TEXT_SIZE 2000
48 extern char* tts_tag();
50 static xmlDocPtr g_config_doc = NULL;
51 char g_engine_id[128] = {0,};
52 char g_setting[128] = {0,};
53 char g_language[128] = {0,};
55 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
57 if (NULL == path || NULL == engine_info) {
58 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
62 bool isTextsize = false;
64 xmlNodePtr cur = NULL;
68 doc = xmlParseFile(path);
70 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
74 cur = xmlDocGetRootElement(doc);
76 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
82 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
83 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
89 cur = cur->xmlChildrenNode;
91 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
97 /* alloc engine info */
98 tts_engine_info_s* temp;
99 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
101 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
110 temp->setting = NULL;
111 temp->pitch_support = false;
114 while (cur != NULL) {
115 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
116 key = xmlNodeGetContent(cur);
118 if (NULL != temp->name) {
122 temp->name = strdup((char*)key);
126 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
128 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
129 key = xmlNodeGetContent(cur);
131 if (NULL != temp->uuid) {
135 temp->uuid = strdup((char*)key);
139 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
141 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
142 key = xmlNodeGetContent(cur);
144 if (NULL != temp->setting) {
146 temp->setting = NULL;
148 temp->setting = strdup((char*)key);
152 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
154 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
155 xmlNodePtr voice_node = NULL;
156 voice_node = cur->xmlChildrenNode;
158 while (NULL != voice_node) {
159 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
160 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
161 if (NULL == temp_voice) {
162 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
166 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
168 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
169 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
170 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
171 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
172 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
173 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
175 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
180 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
186 key = xmlNodeGetContent(voice_node);
188 if (NULL != temp_voice->language) {
189 free(temp_voice->language);
190 temp_voice->language = NULL;
192 temp_voice->language = strdup((char*)key);
195 temp->voices = g_slist_append(temp->voices, temp_voice);
197 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
198 if (NULL != temp_voice) {
204 voice_node = voice_node->next;
206 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
207 key = xmlNodeGetContent(cur);
209 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
210 temp->pitch_support = true;
215 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
217 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
219 key = xmlNodeGetContent(cur);
221 temp->text_size = atoi((char*)key);
224 SLOG(LOG_INFO, tts_tag(), "[INFO] text size is unlimited.");
231 if (false == isTextsize) {
232 temp->text_size = TTS_MAX_TEXT_SIZE;
238 if (NULL == temp->uuid) {
240 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
241 tts_parser_free_engine_info(temp);
250 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
252 if (NULL == engine_info) {
253 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
257 if (NULL != engine_info->name) {
258 free(engine_info->name);
259 engine_info->name = NULL;
261 if (NULL != engine_info->uuid) {
262 free(engine_info->uuid);
263 engine_info->uuid = NULL;
265 if (NULL != engine_info->setting) {
266 free(engine_info->setting);
267 engine_info->setting = NULL;
270 tts_config_voice_s *temp_voice;
271 temp_voice = g_slist_nth_data(engine_info->voices, 0);
273 while (NULL != temp_voice) {
274 if (NULL != temp_voice) {
275 if (NULL != temp_voice->language) {
276 free(temp_voice->language);
277 temp_voice->language = NULL;
279 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
284 temp_voice = g_slist_nth_data(engine_info->voices, 0);
287 if (NULL != engine_info) {
295 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
297 if (NULL == engine_info) {
298 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
302 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
303 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
304 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
305 if (NULL != engine_info->setting)
306 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
308 SLOG(LOG_DEBUG, tts_tag(), " voices");
310 tts_config_voice_s *temp_voice;
312 if (g_slist_length(engine_info->voices) > 0) {
313 /* Get a first item */
314 iter = g_slist_nth(engine_info->voices, 0);
317 while (NULL != iter) {
318 /*Get handle data from list*/
319 temp_voice = iter->data;
321 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
322 i, temp_voice->type, temp_voice->language);
325 iter = g_slist_next(iter);
329 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
332 SLOG(LOG_DEBUG, tts_tag(), "@@@");
337 int tts_parser_load_config(tts_config_s** config_info)
339 if (NULL == config_info) {
340 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
344 xmlDocPtr doc = NULL;
345 xmlNodePtr cur = NULL;
347 bool is_default_open = false;
349 /* For Thread safety */
352 if (0 != access(TTS_CONFIG, F_OK)) {
353 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
355 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
359 is_default_open = true;
363 while (NULL == doc) {
364 doc = xmlParseFile(TTS_CONFIG);
371 if (TTS_RETRY_COUNT == retry_count) {
372 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
373 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
375 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
379 is_default_open = true;
385 cur = xmlDocGetRootElement(doc);
387 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
394 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
395 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
402 cur = cur->xmlChildrenNode;
404 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
411 /* alloc engine info */
413 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
415 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
422 memset(g_engine_id, '\0', sizeof(g_engine_id));
423 memset(g_setting, '\0', sizeof(g_setting));
424 memset(g_language, '\0', sizeof(g_language));
426 temp->engine_id = g_engine_id;
427 temp->setting = g_setting;
428 temp->language = g_language;
430 while (cur != NULL) {
431 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
432 key = xmlNodeGetContent(cur);
434 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
438 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
440 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
441 key = xmlNodeGetContent(cur);
443 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
447 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
449 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
450 key = xmlNodeGetContent(cur);
452 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
453 temp->auto_voice = true;
454 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
455 temp->auto_voice = false;
457 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
458 temp->auto_voice = true;
464 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
466 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
467 key = xmlNodeGetContent(cur);
469 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
470 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
471 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
472 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
473 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
474 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
476 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
477 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
483 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
485 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
486 key = xmlNodeGetContent(cur);
488 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
492 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
495 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
496 key = xmlNodeGetContent(cur);
498 temp->speech_rate = atoi((char*)key);
501 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
503 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
504 key = xmlNodeGetContent(cur);
506 temp->pitch = atoi((char*)key);
510 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
522 if (true == is_default_open) {
526 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
532 if (TTS_RETRY_COUNT == retry_count) {
533 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
539 if (0 > chmod(TTS_CONFIG, 0600)) {
540 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
544 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
545 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
547 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
553 int tts_parser_unload_config(tts_config_s* config_info)
555 if (NULL != g_config_doc) {
556 xmlFreeDoc(g_config_doc);
559 if (NULL != config_info) {
570 int tts_parser_copy_xml(const char* original, const char* destination)
572 if (NULL == original || NULL == destination) {
573 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
577 xmlDocPtr doc = NULL;
578 doc = xmlParseFile(original);
580 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
584 int ret = xmlSaveFile(destination, doc);
586 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
590 if (0 > chmod(destination, 0600)) {
591 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
596 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
601 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
603 if (NULL == engine_id) {
604 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
608 xmlNodePtr cur = NULL;
609 cur = xmlDocGetRootElement(g_config_doc);
611 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
615 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
616 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
620 cur = cur->xmlChildrenNode;
622 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
626 while (cur != NULL) {
627 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
628 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
631 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
632 xmlNodeSetContent(cur, (const xmlChar *)language);
635 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
636 xmlNodeSetContent(cur, (const xmlChar *)setting);
639 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
641 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
642 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
643 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
644 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
651 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
653 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
659 int tts_parser_set_voice(const char* language, int type)
661 if (NULL == language) {
662 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
666 xmlNodePtr cur = NULL;
667 cur = xmlDocGetRootElement(g_config_doc);
669 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
673 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
674 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
678 cur = cur->xmlChildrenNode;
680 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
684 while (cur != NULL) {
685 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
686 xmlNodeSetContent(cur, (const xmlChar *)language);
689 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
691 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
692 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
693 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
695 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
696 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
704 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
706 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
712 int tts_parser_set_auto_voice(bool value)
714 xmlNodePtr cur = NULL;
715 cur = xmlDocGetRootElement(g_config_doc);
717 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
721 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
722 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
726 cur = cur->xmlChildrenNode;
728 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
732 while (cur != NULL) {
733 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
735 xmlNodeSetContent(cur, (const xmlChar *)"on");
736 } else if (false == value) {
737 xmlNodeSetContent(cur, (const xmlChar *)"off");
739 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
747 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
749 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
755 int tts_parser_set_speech_rate(int value)
757 xmlNodePtr cur = NULL;
758 cur = xmlDocGetRootElement(g_config_doc);
760 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
764 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
765 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
769 cur = cur->xmlChildrenNode;
771 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
775 while (cur != NULL) {
776 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
778 memset(temp, '\0', 10);
779 snprintf(temp, 10, "%d", value);
781 xmlNodeSetContent(cur, (const xmlChar *)temp);
783 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
790 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
792 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
798 int tts_parser_set_pitch(int value)
800 xmlNodePtr cur = NULL;
801 cur = xmlDocGetRootElement(g_config_doc);
803 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
807 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
808 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
812 cur = cur->xmlChildrenNode;
814 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
818 while (cur != NULL) {
819 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
821 memset(temp, '\0', 10);
822 snprintf(temp, 10, "%d", value);
823 xmlNodeSetContent(cur, (const xmlChar *)temp);
830 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
832 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
838 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
839 int* speech_rate, int* pitch)
841 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
842 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
846 xmlDocPtr doc = NULL;
847 xmlNodePtr cur_new = NULL;
848 xmlNodePtr cur_old = NULL;
854 while (NULL == doc) {
855 doc = xmlParseFile(TTS_CONFIG);
862 if (TTS_RETRY_COUNT == retry_count) {
863 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
868 cur_new = xmlDocGetRootElement(doc);
869 cur_old = xmlDocGetRootElement(g_config_doc);
870 if (cur_new == NULL || cur_old == NULL) {
871 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
877 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
878 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
879 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
885 cur_new = cur_new->xmlChildrenNode;
886 cur_old = cur_old->xmlChildrenNode;
887 if (cur_new == NULL || cur_old == NULL) {
888 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
894 while (cur_new != NULL && cur_old != NULL) {
895 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
896 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
897 key_old = xmlNodeGetContent(cur_old);
898 if (NULL != key_old) {
899 key_new = xmlNodeGetContent(cur_new);
900 if (NULL != key_new) {
901 if (0 != xmlStrcmp(key_old, key_new)) {
902 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
903 (char*)key_old, (char*)key_new);
904 if (NULL != *engine) {
908 *engine = strdup((char*)key_new);
917 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
919 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
920 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
921 key_old = xmlNodeGetContent(cur_old);
922 if (NULL != key_old) {
923 key_new = xmlNodeGetContent(cur_new);
924 if (NULL != key_new) {
925 if (0 != xmlStrcmp(key_old, key_new)) {
926 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
927 (char*)key_old, (char*)key_new);
928 if (NULL != *setting) {
932 *setting = strdup((char*)key_new);
941 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
943 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
944 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
945 key_old = xmlNodeGetContent(cur_old);
946 if (NULL != key_old) {
947 key_new = xmlNodeGetContent(cur_new);
948 if (NULL != key_new) {
949 if (0 != xmlStrcmp(key_old, key_new)) {
950 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
951 (char*)key_old, (char*)key_new);
952 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
965 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
967 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
968 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
969 key_old = xmlNodeGetContent(cur_old);
970 if (NULL != key_old) {
971 key_new = xmlNodeGetContent(cur_new);
972 if (NULL != key_new) {
973 if (0 != xmlStrcmp(key_old, key_new)) {
974 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
975 (char*)key_old, (char*)key_new);
976 if (NULL != *language) {
980 *language = strdup((char*)key_new);
989 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
991 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
992 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
993 key_old = xmlNodeGetContent(cur_old);
994 if (NULL != key_old) {
995 key_new = xmlNodeGetContent(cur_new);
996 if (NULL != key_new) {
997 if (0 != xmlStrcmp(key_old, key_new)) {
998 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
999 (char*)key_old, (char*)key_new);
1000 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1001 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1002 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1003 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1004 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1005 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1007 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
1017 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1019 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1020 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1021 key_old = xmlNodeGetContent(cur_old);
1022 if (NULL != key_old) {
1023 key_new = xmlNodeGetContent(cur_new);
1024 if (NULL != key_new) {
1025 if (0 != xmlStrcmp(key_old, key_new)) {
1026 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1027 (char*)key_old, (char*)key_new);
1028 *speech_rate = atoi((char*)key_new);
1037 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1039 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1040 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1041 key_old = xmlNodeGetContent(cur_old);
1042 if (NULL != key_old) {
1043 key_new = xmlNodeGetContent(cur_new);
1044 if (NULL != key_new) {
1045 if (0 != xmlStrcmp(key_old, key_new)) {
1046 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1047 (char*)key_old, (char*)key_new);
1048 *pitch = atoi((char*)key_new);
1057 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1063 cur_new = cur_new->next;
1064 cur_old = cur_old->next;
1067 if (NULL != g_config_doc) {
1068 xmlFreeDoc(g_config_doc);
1069 g_config_doc = NULL;