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 static xmlDocPtr g_config_doc = NULL;
49 char g_engine_id[128] = {0,};
50 char g_setting[128] = {0,};
51 char g_language[128] = {0,};
53 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
55 if (NULL == path || NULL == engine_info) {
56 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
60 bool isTextsize = false;
62 xmlNodePtr cur = NULL;
66 if (0 == access(path, F_OK)) {
67 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
68 doc = xmlParseFile(path);
70 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file");
74 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", path);
78 cur = xmlDocGetRootElement(doc);
80 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
86 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
87 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-engine'. doc path(%s, %p)", path, doc);
93 cur = cur->xmlChildrenNode;
95 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
101 /* alloc engine info */
102 tts_engine_info_s* temp;
103 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
105 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory. doc path(%s, %p)", path, doc);
114 temp->setting = NULL;
115 temp->pitch_support = false;
118 while (cur != NULL) {
119 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
120 key = xmlNodeGetContent(cur);
122 if (NULL != temp->name) {
126 temp->name = strdup((char*)key);
130 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
132 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
133 key = xmlNodeGetContent(cur);
135 if (NULL != temp->uuid) {
139 temp->uuid = strdup((char*)key);
143 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
145 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
146 key = xmlNodeGetContent(cur);
148 if (NULL != temp->setting) {
150 temp->setting = NULL;
152 temp->setting = strdup((char*)key);
156 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
158 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
159 xmlNodePtr voice_node = NULL;
160 voice_node = cur->xmlChildrenNode;
162 while (NULL != voice_node) {
163 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
164 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
165 if (NULL == temp_voice) {
166 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory");
170 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
172 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
173 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
174 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
175 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
176 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
177 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
179 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
184 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
190 key = xmlNodeGetContent(voice_node);
192 if (NULL != temp_voice->language) {
193 free(temp_voice->language);
194 temp_voice->language = NULL;
196 temp_voice->language = strdup((char*)key);
199 temp->voices = g_slist_append(temp->voices, temp_voice);
201 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
202 if (NULL != temp_voice) {
208 voice_node = voice_node->next;
210 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
211 key = xmlNodeGetContent(cur);
213 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
214 temp->pitch_support = true;
219 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
221 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
223 key = xmlNodeGetContent(cur);
225 temp->text_size = atoi((char*)key);
228 SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] text size is unlimited.");
235 if (false == isTextsize) {
236 temp->text_size = TTS_MAX_TEXT_SIZE;
240 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc path(%s, %p)", path, doc);
245 if (NULL == temp->uuid) {
247 SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path);
248 tts_parser_free_engine_info(temp);
257 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
259 if (NULL == engine_info) {
260 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
264 if (NULL != engine_info->name) {
265 free(engine_info->name);
266 engine_info->name = NULL;
268 if (NULL != engine_info->uuid) {
269 free(engine_info->uuid);
270 engine_info->uuid = NULL;
272 if (NULL != engine_info->setting) {
273 free(engine_info->setting);
274 engine_info->setting = NULL;
277 tts_config_voice_s *temp_voice;
278 temp_voice = g_slist_nth_data(engine_info->voices, 0);
280 while (NULL != temp_voice) {
281 if (NULL != temp_voice) {
282 if (NULL != temp_voice->language) {
283 free(temp_voice->language);
284 temp_voice->language = NULL;
286 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
291 temp_voice = g_slist_nth_data(engine_info->voices, 0);
294 if (NULL != engine_info) {
302 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
304 if (NULL == engine_info) {
305 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
309 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "== get engine info ==");
310 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " name : %s", engine_info->name);
311 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " id : %s", engine_info->uuid);
312 if (NULL != engine_info->setting)
313 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " setting : %s", engine_info->setting);
315 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voices");
317 tts_config_voice_s *temp_voice;
319 if (g_slist_length(engine_info->voices) > 0) {
320 /* Get a first item */
321 iter = g_slist_nth(engine_info->voices, 0);
324 while (NULL != iter) {
325 /*Get handle data from list*/
326 temp_voice = iter->data;
328 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] type(%d) lang(%s)",
329 i, temp_voice->type, temp_voice->language);
332 iter = g_slist_next(iter);
336 SLOG(LOG_ERROR, TAG_TTSCONFIG, " Voice is NONE");
339 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@");
344 int tts_parser_load_config(tts_config_s** config_info)
346 if (NULL == config_info) {
347 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
351 xmlDocPtr doc = NULL;
352 xmlNodePtr cur = NULL;
354 bool is_default_open = false;
356 /* For Thread safety */
359 if (0 != access(TTS_CONFIG, F_OK)) {
360 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
362 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
366 is_default_open = true;
370 while (NULL == doc) {
371 doc = xmlParseFile(TTS_CONFIG);
378 if (TTS_RETRY_COUNT == retry_count) {
379 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
380 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
382 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
386 is_default_open = true;
392 cur = xmlDocGetRootElement(doc);
394 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
401 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
402 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
409 cur = cur->xmlChildrenNode;
411 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
418 /* alloc engine info */
420 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
422 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory(%p)", doc);
429 memset(g_engine_id, '\0', sizeof(g_engine_id));
430 memset(g_setting, '\0', sizeof(g_setting));
431 memset(g_language, '\0', sizeof(g_language));
433 temp->engine_id = g_engine_id;
434 temp->setting = g_setting;
435 temp->language = g_language;
437 while (cur != NULL) {
438 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
439 key = xmlNodeGetContent(cur);
441 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
445 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
447 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
448 key = xmlNodeGetContent(cur);
450 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
454 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL");
456 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
457 key = xmlNodeGetContent(cur);
459 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
460 temp->auto_voice = true;
461 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
462 temp->auto_voice = false;
464 SLOG(LOG_ERROR, TAG_TTSCONFIG, "Auto voice is wrong");
465 temp->auto_voice = true;
471 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
473 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
474 key = xmlNodeGetContent(cur);
476 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
477 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
478 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
479 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
480 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
481 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
483 SLOG(LOG_WARN, TAG_TTSCONFIG, "Voice type is user defined");
484 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
490 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
492 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
493 key = xmlNodeGetContent(cur);
495 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
499 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine uuid is NULL");
502 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
503 key = xmlNodeGetContent(cur);
505 temp->speech_rate = atoi((char*)key);
508 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL");
510 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
511 key = xmlNodeGetContent(cur);
513 temp->pitch = atoi((char*)key);
517 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
529 if (true == is_default_open) {
533 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
539 if (TTS_RETRY_COUNT == retry_count) {
540 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
546 if (0 > chmod(TTS_CONFIG, 0600)) {
547 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
551 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
552 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file owner : %d", ret);
554 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default config is changed : pid(%d)", getpid());
560 int tts_parser_unload_config(tts_config_s* config_info)
562 if (NULL != g_config_doc) {
563 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
564 xmlFreeDoc(g_config_doc);
567 if (NULL != config_info) {
568 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free config_info(%p)", config_info);
579 int tts_parser_copy_xml(const char* original, const char* destination)
581 if (NULL == original || NULL == destination) {
582 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
586 xmlDocPtr doc = NULL;
587 if (0 == access(original, F_OK)) {
588 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", original);
589 doc = xmlParseFile(original);
591 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", original);
595 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", original);
599 int ret = xmlSaveFile(destination, doc);
601 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
604 pFile = fopen(destination, "r");
607 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", destination);
612 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", destination);
614 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", destination);
618 if (0 > chmod(destination, 0600)) {
619 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
623 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc(%p)", doc);
628 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[SUCCESS] Copying xml");
633 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
635 if (NULL == engine_id) {
636 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
640 xmlNodePtr cur = NULL;
641 cur = xmlDocGetRootElement(g_config_doc);
643 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
647 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
648 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
652 cur = cur->xmlChildrenNode;
654 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
658 while (cur != NULL) {
659 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
660 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
663 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
664 xmlNodeSetContent(cur, (const xmlChar *)language);
667 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
668 xmlNodeSetContent(cur, (const xmlChar *)setting);
671 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
673 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
674 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
675 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
676 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
683 if (0 == access(TTS_CONFIG, F_OK)) {
684 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
686 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
689 pFile = fopen(TTS_CONFIG, "r");
692 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
697 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
699 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
702 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
708 int tts_parser_set_voice(const char* language, int type)
710 if (NULL == language) {
711 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
715 xmlNodePtr cur = NULL;
716 cur = xmlDocGetRootElement(g_config_doc);
718 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
722 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
723 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
727 cur = cur->xmlChildrenNode;
729 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
733 while (cur != NULL) {
734 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
735 xmlNodeSetContent(cur, (const xmlChar *)language);
738 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
740 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
741 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
742 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
744 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid type : %d", type);
745 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
753 if (0 == access(TTS_CONFIG, F_OK)) {
754 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
756 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
759 pFile = fopen(TTS_CONFIG, "r");
762 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
767 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
769 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
772 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
777 int tts_parser_set_auto_voice(bool value)
779 xmlNodePtr cur = NULL;
780 cur = xmlDocGetRootElement(g_config_doc);
782 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
786 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
787 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
791 cur = cur->xmlChildrenNode;
793 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
797 while (cur != NULL) {
798 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
800 xmlNodeSetContent(cur, (const xmlChar *)"on");
801 } else if (false == value) {
802 xmlNodeSetContent(cur, (const xmlChar *)"off");
804 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong value of auto voice");
812 if (0 == access(TTS_CONFIG, F_OK)) {
813 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
815 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
818 pFile = fopen(TTS_CONFIG, "r");
821 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
826 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
828 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
831 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
837 int tts_parser_set_speech_rate(int value)
839 xmlNodePtr cur = NULL;
840 cur = xmlDocGetRootElement(g_config_doc);
842 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
846 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
847 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
851 cur = cur->xmlChildrenNode;
853 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
857 while (cur != NULL) {
858 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
860 memset(temp, '\0', 10);
861 snprintf(temp, 10, "%d", value);
863 xmlNodeSetContent(cur, (const xmlChar *)temp);
865 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set speech rate : %s", temp);
872 if (0 == access(TTS_CONFIG, F_OK)) {
873 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
875 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
878 pFile = fopen(TTS_CONFIG, "r");
881 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
886 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
888 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
891 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
897 int tts_parser_set_pitch(int value)
899 xmlNodePtr cur = NULL;
900 cur = xmlDocGetRootElement(g_config_doc);
902 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
906 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
907 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
911 cur = cur->xmlChildrenNode;
913 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
917 while (cur != NULL) {
918 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
920 memset(temp, '\0', 10);
921 snprintf(temp, 10, "%d", value);
922 xmlNodeSetContent(cur, (const xmlChar *)temp);
929 if (0 == access(TTS_CONFIG, F_OK)) {
930 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
932 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
935 pFile = fopen(TTS_CONFIG, "r");
938 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
943 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
945 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
948 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
954 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
955 int* speech_rate, int* pitch)
957 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
958 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
962 xmlDocPtr doc = NULL;
963 xmlNodePtr cur_new = NULL;
964 xmlNodePtr cur_old = NULL;
970 while (NULL == doc) {
971 if (0 == access(TTS_CONFIG, F_OK)) {
972 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", TTS_CONFIG);
973 doc = xmlParseFile(TTS_CONFIG);
981 if (TTS_RETRY_COUNT == retry_count) {
982 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
987 cur_new = xmlDocGetRootElement(doc);
988 cur_old = xmlDocGetRootElement(g_config_doc);
989 if (cur_new == NULL || cur_old == NULL) {
990 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
996 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
997 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
998 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
1004 cur_new = cur_new->xmlChildrenNode;
1005 cur_old = cur_old->xmlChildrenNode;
1006 if (cur_new == NULL || cur_old == NULL) {
1007 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
1013 while (cur_new != NULL && cur_old != NULL) {
1014 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1015 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1016 key_old = xmlNodeGetContent(cur_old);
1017 if (NULL != key_old) {
1018 key_new = xmlNodeGetContent(cur_new);
1019 if (NULL != key_new) {
1020 if (0 != xmlStrcmp(key_old, key_new)) {
1021 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
1022 (char*)key_old, (char*)key_new);
1023 if (NULL != *engine) {
1027 *engine = strdup((char*)key_new);
1036 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1038 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1039 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1040 key_old = xmlNodeGetContent(cur_old);
1041 if (NULL != key_old) {
1042 key_new = xmlNodeGetContent(cur_new);
1043 if (NULL != key_new) {
1044 if (0 != xmlStrcmp(key_old, key_new)) {
1045 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)",
1046 (char*)key_old, (char*)key_new);
1047 if (NULL != *setting) {
1051 *setting = strdup((char*)key_new);
1060 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1062 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1063 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1064 key_old = xmlNodeGetContent(cur_old);
1065 if (NULL != key_old) {
1066 key_new = xmlNodeGetContent(cur_new);
1067 if (NULL != key_new) {
1068 if (0 != xmlStrcmp(key_old, key_new)) {
1069 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)",
1070 (char*)key_old, (char*)key_new);
1071 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
1074 *auto_voice = false;
1084 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1086 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1087 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1088 key_old = xmlNodeGetContent(cur_old);
1089 if (NULL != key_old) {
1090 key_new = xmlNodeGetContent(cur_new);
1091 if (NULL != key_new) {
1092 if (0 != xmlStrcmp(key_old, key_new)) {
1093 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)",
1094 (char*)key_old, (char*)key_new);
1095 if (NULL != *language) {
1099 *language = strdup((char*)key_new);
1108 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1110 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1111 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1112 key_old = xmlNodeGetContent(cur_old);
1113 if (NULL != key_old) {
1114 key_new = xmlNodeGetContent(cur_new);
1115 if (NULL != key_new) {
1116 if (0 != xmlStrcmp(key_old, key_new)) {
1117 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)",
1118 (char*)key_old, (char*)key_new);
1119 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1120 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1121 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1122 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1123 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1124 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1126 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] New voice type is not valid");
1136 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1138 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1139 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1140 key_old = xmlNodeGetContent(cur_old);
1141 if (NULL != key_old) {
1142 key_new = xmlNodeGetContent(cur_new);
1143 if (NULL != key_new) {
1144 if (0 != xmlStrcmp(key_old, key_new)) {
1145 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old speech rate(%s), New speech rate(%s)",
1146 (char*)key_old, (char*)key_new);
1147 *speech_rate = atoi((char*)key_new);
1156 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1158 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1159 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1160 key_old = xmlNodeGetContent(cur_old);
1161 if (NULL != key_old) {
1162 key_new = xmlNodeGetContent(cur_new);
1163 if (NULL != key_new) {
1164 if (0 != xmlStrcmp(key_old, key_new)) {
1165 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)",
1166 (char*)key_old, (char*)key_new);
1167 *pitch = atoi((char*)key_new);
1176 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1182 cur_new = cur_new->next;
1183 cur_old = cur_old->next;
1186 if (NULL != g_config_doc) {
1187 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1188 xmlFreeDoc(g_config_doc);
1189 g_config_doc = NULL;
1196 int tts_parser_reset()
1198 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1200 if (NULL != g_config_doc) {
1201 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1202 xmlFreeDoc(g_config_doc);
1203 g_config_doc = NULL;
1206 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1207 if (NULL == g_config_doc) {
1208 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1212 if (0 == access(TTS_CONFIG, F_OK)) {
1213 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1215 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save %s", TTS_CONFIG);
1218 pFile = fopen(TTS_CONFIG, "r");
1220 if (NULL == pFile) {
1221 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1226 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1228 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1231 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);