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_CONFIG_BACKGROUND_VOLUME_RATIO "background-volume-ratio"
43 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
44 #define TTS_TAG_VOICE_TYPE_MALE "male"
45 #define TTS_TAG_VOICE_TYPE_CHILD "child"
47 #define TTS_MAX_TEXT_SIZE 2000
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, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
61 bool isTextsize = false;
63 xmlNodePtr cur = NULL;
67 if (0 == access(path, F_OK)) {
68 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
69 doc = xmlParseFile(path);
71 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file");
75 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", path);
79 cur = xmlDocGetRootElement(doc);
81 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
87 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
88 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-engine'. doc path(%s, %p)", path, doc);
94 cur = cur->xmlChildrenNode;
96 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
102 /* alloc engine info */
103 tts_engine_info_s* temp;
104 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
106 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory. doc path(%s, %p)", path, doc);
115 temp->setting = NULL;
116 temp->pitch_support = false;
119 while (cur != NULL) {
120 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
121 key = xmlNodeGetContent(cur);
123 if (NULL != temp->name) {
127 temp->name = strdup((char*)key);
131 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
133 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
134 key = xmlNodeGetContent(cur);
136 if (NULL != temp->uuid) {
140 temp->uuid = strdup((char*)key);
144 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
146 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
147 key = xmlNodeGetContent(cur);
149 if (NULL != temp->setting) {
151 temp->setting = NULL;
153 temp->setting = strdup((char*)key);
157 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
159 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
160 xmlNodePtr voice_node = NULL;
161 voice_node = cur->xmlChildrenNode;
163 while (NULL != voice_node) {
164 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
165 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
166 if (NULL == temp_voice) {
167 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory");
171 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
173 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
174 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
175 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
176 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
177 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
178 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
180 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
185 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
191 key = xmlNodeGetContent(voice_node);
193 if (NULL != temp_voice->language) {
194 free(temp_voice->language);
195 temp_voice->language = NULL;
197 temp_voice->language = strdup((char*)key);
200 temp->voices = g_slist_append(temp->voices, temp_voice);
202 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
203 if (NULL != temp_voice) {
209 voice_node = voice_node->next;
211 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
212 key = xmlNodeGetContent(cur);
214 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
215 temp->pitch_support = true;
220 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
222 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
224 key = xmlNodeGetContent(cur);
226 temp->text_size = atoi((char*)key);
229 SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] text size is unlimited.");
236 if (false == isTextsize) {
237 temp->text_size = TTS_MAX_TEXT_SIZE;
241 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc path(%s, %p)", path, doc);
246 if (NULL == temp->uuid) {
248 SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path);
249 tts_parser_free_engine_info(temp);
258 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
260 if (NULL == engine_info) {
261 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
265 if (NULL != engine_info->name) {
266 free(engine_info->name);
267 engine_info->name = NULL;
269 if (NULL != engine_info->uuid) {
270 free(engine_info->uuid);
271 engine_info->uuid = NULL;
273 if (NULL != engine_info->setting) {
274 free(engine_info->setting);
275 engine_info->setting = NULL;
278 tts_config_voice_s *temp_voice;
279 temp_voice = g_slist_nth_data(engine_info->voices, 0);
281 while (NULL != temp_voice) {
282 if (NULL != temp_voice) {
283 if (NULL != temp_voice->language) {
284 free(temp_voice->language);
285 temp_voice->language = NULL;
287 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
292 temp_voice = g_slist_nth_data(engine_info->voices, 0);
295 if (NULL != engine_info) {
303 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
305 if (NULL == engine_info) {
306 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
310 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "== get engine info ==");
311 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " name : %s", engine_info->name);
312 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " id : %s", engine_info->uuid);
313 if (NULL != engine_info->setting)
314 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " setting : %s", engine_info->setting);
316 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voices");
318 tts_config_voice_s *temp_voice;
320 if (g_slist_length(engine_info->voices) > 0) {
321 /* Get a first item */
322 iter = g_slist_nth(engine_info->voices, 0);
325 while (NULL != iter) {
326 /*Get handle data from list*/
327 temp_voice = iter->data;
329 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] type(%d) lang(%s)",
330 i, temp_voice->type, temp_voice->language);
333 iter = g_slist_next(iter);
337 SLOG(LOG_ERROR, TAG_TTSCONFIG, " Voice is NONE");
340 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@");
345 int tts_parser_load_config(tts_config_s** config_info)
347 if (NULL == config_info) {
348 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
352 xmlDocPtr doc = NULL;
353 xmlNodePtr cur = NULL;
355 bool is_default_open = false;
357 /* For Thread safety */
360 if (0 != access(TTS_CONFIG, F_OK)) {
361 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
363 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
367 is_default_open = true;
371 while (NULL == doc) {
372 doc = xmlParseFile(TTS_CONFIG);
379 if (TTS_RETRY_COUNT == retry_count) {
380 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
381 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
383 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
387 is_default_open = true;
393 cur = xmlDocGetRootElement(doc);
395 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
402 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
403 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
410 cur = cur->xmlChildrenNode;
412 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
419 /* alloc engine info */
421 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
423 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory(%p)", doc);
430 memset(g_engine_id, '\0', sizeof(g_engine_id));
431 memset(g_setting, '\0', sizeof(g_setting));
432 memset(g_language, '\0', sizeof(g_language));
434 temp->engine_id = g_engine_id;
435 temp->setting = g_setting;
436 temp->language = g_language;
438 while (cur != NULL) {
439 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
440 key = xmlNodeGetContent(cur);
442 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
446 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
448 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
449 key = xmlNodeGetContent(cur);
451 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
455 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL");
457 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
458 key = xmlNodeGetContent(cur);
460 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
461 temp->auto_voice = true;
462 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
463 temp->auto_voice = false;
465 SLOG(LOG_ERROR, TAG_TTSCONFIG, "Auto voice is wrong");
466 temp->auto_voice = true;
472 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
474 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
475 key = xmlNodeGetContent(cur);
477 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
478 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
479 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
480 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
481 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
482 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
484 SLOG(LOG_WARN, TAG_TTSCONFIG, "Voice type is user defined");
485 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
491 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
493 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
494 key = xmlNodeGetContent(cur);
496 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
500 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine uuid is NULL");
503 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
504 key = xmlNodeGetContent(cur);
506 temp->speech_rate = atoi((char*)key);
509 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL");
511 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
512 key = xmlNodeGetContent(cur);
514 temp->pitch = atoi((char*)key);
518 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
520 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
521 key = xmlNodeGetContent(cur);
523 temp->bg_volume_ratio = atof((char*)key);
527 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Background volume ratio is NULL");
539 if (true == is_default_open) {
543 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
549 if (TTS_RETRY_COUNT == retry_count) {
550 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
556 if (0 > chmod(TTS_CONFIG, 0600)) {
557 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
561 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
562 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file owner : %d", ret);
564 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default config is changed : pid(%d)", getpid());
570 int tts_parser_unload_config(tts_config_s* config_info)
572 if (NULL != g_config_doc) {
573 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
574 xmlFreeDoc(g_config_doc);
577 if (NULL != config_info) {
578 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free config_info(%p)", config_info);
589 int tts_parser_copy_xml(const char* original, const char* destination)
591 if (NULL == original || NULL == destination) {
592 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
596 xmlDocPtr doc = NULL;
597 if (0 == access(original, F_OK)) {
598 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", original);
599 doc = xmlParseFile(original);
601 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", original);
605 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", original);
609 int ret = xmlSaveFile(destination, doc);
611 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
614 pFile = fopen(destination, "r");
617 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", destination);
622 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", destination);
624 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", destination);
628 if (0 > chmod(destination, 0600)) {
629 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
633 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc(%p)", doc);
638 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[SUCCESS] Copying xml");
643 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
645 if (NULL == engine_id) {
646 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
650 xmlNodePtr cur = NULL;
651 cur = xmlDocGetRootElement(g_config_doc);
653 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
657 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
658 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
662 cur = cur->xmlChildrenNode;
664 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
668 while (cur != NULL) {
669 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
670 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
673 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
674 xmlNodeSetContent(cur, (const xmlChar *)language);
677 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
678 xmlNodeSetContent(cur, (const xmlChar *)setting);
681 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
683 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
684 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
685 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
686 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
693 if (0 == access(TTS_CONFIG, F_OK)) {
694 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
696 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
699 pFile = fopen(TTS_CONFIG, "r");
702 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
707 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
709 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
712 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
718 int tts_parser_set_voice(const char* language, int type)
720 if (NULL == language) {
721 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
725 xmlNodePtr cur = NULL;
726 cur = xmlDocGetRootElement(g_config_doc);
728 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
732 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
733 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
737 cur = cur->xmlChildrenNode;
739 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
743 while (cur != NULL) {
744 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
745 xmlNodeSetContent(cur, (const xmlChar *)language);
748 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
750 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
751 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
752 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
754 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid type : %d", type);
755 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
763 if (0 == access(TTS_CONFIG, F_OK)) {
764 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
766 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
769 pFile = fopen(TTS_CONFIG, "r");
772 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
777 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
779 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
782 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
787 int tts_parser_set_auto_voice(bool value)
789 xmlNodePtr cur = NULL;
790 cur = xmlDocGetRootElement(g_config_doc);
792 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
796 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
797 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
801 cur = cur->xmlChildrenNode;
803 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
807 while (cur != NULL) {
808 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
810 xmlNodeSetContent(cur, (const xmlChar *)"on");
811 } else if (false == value) {
812 xmlNodeSetContent(cur, (const xmlChar *)"off");
814 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong value of auto voice");
822 if (0 == access(TTS_CONFIG, F_OK)) {
823 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
825 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
828 pFile = fopen(TTS_CONFIG, "r");
831 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
836 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
838 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
841 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
847 int tts_parser_set_speech_rate(int value)
849 xmlNodePtr cur = NULL;
850 cur = xmlDocGetRootElement(g_config_doc);
852 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
856 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
857 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
861 cur = cur->xmlChildrenNode;
863 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
867 while (cur != NULL) {
868 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
870 memset(temp, '\0', 10);
871 snprintf(temp, 10, "%d", value);
873 xmlNodeSetContent(cur, (const xmlChar *)temp);
875 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set speech rate : %s", temp);
882 if (0 == access(TTS_CONFIG, F_OK)) {
883 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
885 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
888 pFile = fopen(TTS_CONFIG, "r");
891 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
896 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
898 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
901 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
907 int tts_parser_set_pitch(int value)
909 xmlNodePtr cur = NULL;
910 cur = xmlDocGetRootElement(g_config_doc);
912 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
916 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
917 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
921 cur = cur->xmlChildrenNode;
923 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
927 while (cur != NULL) {
928 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
930 memset(temp, '\0', 10);
931 snprintf(temp, 10, "%d", value);
932 xmlNodeSetContent(cur, (const xmlChar *)temp);
939 if (0 == access(TTS_CONFIG, F_OK)) {
940 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
942 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
945 pFile = fopen(TTS_CONFIG, "r");
948 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
953 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
955 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
958 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
964 int tts_parser_set_bg_volume_ratio(double value)
966 xmlNodePtr cur = NULL;
967 cur = xmlDocGetRootElement(g_config_doc);
969 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
973 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
974 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
978 cur = cur->xmlChildrenNode;
980 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
984 while (cur != NULL) {
985 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
987 memset(temp, '\0', 10);
988 snprintf(temp, 10, "%lf", value);
989 xmlNodeSetContent(cur, (const xmlChar *)temp);
996 if (0 == access(TTS_CONFIG, F_OK)) {
997 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
999 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
1002 pFile = fopen(TTS_CONFIG, "r");
1004 if (NULL == pFile) {
1005 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1010 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1012 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1015 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
1021 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
1022 int* speech_rate, int* pitch, double* bg_volume_ratio)
1024 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
1025 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
1029 xmlDocPtr doc = NULL;
1030 xmlNodePtr cur_new = NULL;
1031 xmlNodePtr cur_old = NULL;
1036 int retry_count = 0;
1037 while (NULL == doc) {
1038 if (0 == access(TTS_CONFIG, F_OK)) {
1039 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", TTS_CONFIG);
1040 doc = xmlParseFile(TTS_CONFIG);
1048 if (TTS_RETRY_COUNT == retry_count) {
1049 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
1054 cur_new = xmlDocGetRootElement(doc);
1055 cur_old = xmlDocGetRootElement(g_config_doc);
1056 if (cur_new == NULL || cur_old == NULL) {
1057 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
1063 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
1064 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
1065 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
1071 cur_new = cur_new->xmlChildrenNode;
1072 cur_old = cur_old->xmlChildrenNode;
1073 if (cur_new == NULL || cur_old == NULL) {
1074 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
1080 while (cur_new != NULL && cur_old != NULL) {
1081 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1082 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1083 key_old = xmlNodeGetContent(cur_old);
1084 if (NULL != key_old) {
1085 key_new = xmlNodeGetContent(cur_new);
1086 if (NULL != key_new) {
1087 if (0 != xmlStrcmp(key_old, key_new)) {
1088 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
1089 (char*)key_old, (char*)key_new);
1090 if (NULL != *engine) {
1094 *engine = strdup((char*)key_new);
1103 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1105 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1106 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1107 key_old = xmlNodeGetContent(cur_old);
1108 if (NULL != key_old) {
1109 key_new = xmlNodeGetContent(cur_new);
1110 if (NULL != key_new) {
1111 if (0 != xmlStrcmp(key_old, key_new)) {
1112 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)",
1113 (char*)key_old, (char*)key_new);
1114 if (NULL != *setting) {
1118 *setting = strdup((char*)key_new);
1127 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1129 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1130 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1131 key_old = xmlNodeGetContent(cur_old);
1132 if (NULL != key_old) {
1133 key_new = xmlNodeGetContent(cur_new);
1134 if (NULL != key_new) {
1135 if (0 != xmlStrcmp(key_old, key_new)) {
1136 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)",
1137 (char*)key_old, (char*)key_new);
1138 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
1141 *auto_voice = false;
1151 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1153 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1154 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1155 key_old = xmlNodeGetContent(cur_old);
1156 if (NULL != key_old) {
1157 key_new = xmlNodeGetContent(cur_new);
1158 if (NULL != key_new) {
1159 if (0 != xmlStrcmp(key_old, key_new)) {
1160 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)",
1161 (char*)key_old, (char*)key_new);
1162 if (NULL != *language) {
1166 *language = strdup((char*)key_new);
1175 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1177 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1178 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1179 key_old = xmlNodeGetContent(cur_old);
1180 if (NULL != key_old) {
1181 key_new = xmlNodeGetContent(cur_new);
1182 if (NULL != key_new) {
1183 if (0 != xmlStrcmp(key_old, key_new)) {
1184 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)",
1185 (char*)key_old, (char*)key_new);
1186 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1187 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1188 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1189 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1190 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1191 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1193 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] New voice type is not valid");
1203 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1205 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1206 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1207 key_old = xmlNodeGetContent(cur_old);
1208 if (NULL != key_old) {
1209 key_new = xmlNodeGetContent(cur_new);
1210 if (NULL != key_new) {
1211 if (0 != xmlStrcmp(key_old, key_new)) {
1212 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old speech rate(%s), New speech rate(%s)",
1213 (char*)key_old, (char*)key_new);
1214 *speech_rate = atoi((char*)key_new);
1223 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1225 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1226 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1227 key_old = xmlNodeGetContent(cur_old);
1228 if (NULL != key_old) {
1229 key_new = xmlNodeGetContent(cur_new);
1230 if (NULL != key_new) {
1231 if (0 != xmlStrcmp(key_old, key_new)) {
1232 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)",
1233 (char*)key_old, (char*)key_new);
1234 *pitch = atoi((char*)key_new);
1243 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1245 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
1246 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
1247 key_old = xmlNodeGetContent(cur_old);
1248 if (NULL != key_old) {
1249 key_new = xmlNodeGetContent(cur_new);
1250 if (NULL != key_new) {
1251 if (0 != xmlStrcmp(key_old, key_new)) {
1252 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)",
1253 (char*)key_old, (char*)key_new);
1254 *bg_volume_ratio = atof((char*)key_new);
1263 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1269 cur_new = cur_new->next;
1270 cur_old = cur_old->next;
1273 if (NULL != g_config_doc) {
1274 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1275 xmlFreeDoc(g_config_doc);
1276 g_config_doc = NULL;
1283 int tts_parser_reset()
1285 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1287 if (NULL != g_config_doc) {
1288 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1289 xmlFreeDoc(g_config_doc);
1290 g_config_doc = NULL;
1293 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1294 if (NULL == g_config_doc) {
1295 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1299 if (0 == access(TTS_CONFIG, F_OK)) {
1300 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1302 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save %s", TTS_CONFIG);
1305 pFile = fopen(TTS_CONFIG, "r");
1307 if (NULL == pFile) {
1308 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1313 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1315 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1318 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);