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");
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'");
93 cur = cur->xmlChildrenNode;
95 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
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");
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;
242 if (NULL == temp->uuid) {
244 SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path);
245 tts_parser_free_engine_info(temp);
254 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
256 if (NULL == engine_info) {
257 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
261 if (NULL != engine_info->name) {
262 free(engine_info->name);
263 engine_info->name = NULL;
265 if (NULL != engine_info->uuid) {
266 free(engine_info->uuid);
267 engine_info->uuid = NULL;
269 if (NULL != engine_info->setting) {
270 free(engine_info->setting);
271 engine_info->setting = NULL;
274 tts_config_voice_s *temp_voice;
275 temp_voice = g_slist_nth_data(engine_info->voices, 0);
277 while (NULL != temp_voice) {
278 if (NULL != temp_voice) {
279 if (NULL != temp_voice->language) {
280 free(temp_voice->language);
281 temp_voice->language = NULL;
283 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
288 temp_voice = g_slist_nth_data(engine_info->voices, 0);
291 if (NULL != engine_info) {
299 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
301 if (NULL == engine_info) {
302 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
306 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "== get engine info ==");
307 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " name : %s", engine_info->name);
308 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " id : %s", engine_info->uuid);
309 if (NULL != engine_info->setting)
310 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " setting : %s", engine_info->setting);
312 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voices");
314 tts_config_voice_s *temp_voice;
316 if (g_slist_length(engine_info->voices) > 0) {
317 /* Get a first item */
318 iter = g_slist_nth(engine_info->voices, 0);
321 while (NULL != iter) {
322 /*Get handle data from list*/
323 temp_voice = iter->data;
325 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] type(%d) lang(%s)",
326 i, temp_voice->type, temp_voice->language);
329 iter = g_slist_next(iter);
333 SLOG(LOG_ERROR, TAG_TTSCONFIG, " Voice is NONE");
336 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@");
341 int tts_parser_load_config(tts_config_s** config_info)
343 if (NULL == config_info) {
344 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
348 xmlDocPtr doc = NULL;
349 xmlNodePtr cur = NULL;
351 bool is_default_open = false;
353 /* For Thread safety */
356 if (0 != access(TTS_CONFIG, F_OK)) {
357 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
359 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
363 is_default_open = true;
367 while (NULL == doc) {
368 doc = xmlParseFile(TTS_CONFIG);
375 if (TTS_RETRY_COUNT == retry_count) {
376 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
377 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
379 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
383 is_default_open = true;
389 cur = xmlDocGetRootElement(doc);
391 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
398 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
399 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
406 cur = cur->xmlChildrenNode;
408 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
415 /* alloc engine info */
417 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
419 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory");
426 memset(g_engine_id, '\0', sizeof(g_engine_id));
427 memset(g_setting, '\0', sizeof(g_setting));
428 memset(g_language, '\0', sizeof(g_language));
430 temp->engine_id = g_engine_id;
431 temp->setting = g_setting;
432 temp->language = g_language;
434 while (cur != NULL) {
435 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
436 key = xmlNodeGetContent(cur);
438 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
442 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
444 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
445 key = xmlNodeGetContent(cur);
447 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
451 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL");
453 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
454 key = xmlNodeGetContent(cur);
456 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
457 temp->auto_voice = true;
458 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
459 temp->auto_voice = false;
461 SLOG(LOG_ERROR, TAG_TTSCONFIG, "Auto voice is wrong");
462 temp->auto_voice = true;
468 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
470 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
471 key = xmlNodeGetContent(cur);
473 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
474 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
475 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
476 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
477 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
478 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
480 SLOG(LOG_WARN, TAG_TTSCONFIG, "Voice type is user defined");
481 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
487 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
489 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
490 key = xmlNodeGetContent(cur);
492 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
496 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine uuid is NULL");
499 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
500 key = xmlNodeGetContent(cur);
502 temp->speech_rate = atoi((char*)key);
505 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL");
507 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
508 key = xmlNodeGetContent(cur);
510 temp->pitch = atoi((char*)key);
514 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
526 if (true == is_default_open) {
530 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
536 if (TTS_RETRY_COUNT == retry_count) {
537 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
543 if (0 > chmod(TTS_CONFIG, 0600)) {
544 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
548 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
549 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file owner : %d", ret);
551 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default config is changed : pid(%d)", getpid());
557 int tts_parser_unload_config(tts_config_s* config_info)
559 if (NULL != g_config_doc) {
560 xmlFreeDoc(g_config_doc);
563 if (NULL != config_info) {
574 int tts_parser_copy_xml(const char* original, const char* destination)
576 if (NULL == original || NULL == destination) {
577 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
581 xmlDocPtr doc = NULL;
582 if (0 == access(original, F_OK)) {
583 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", original);
584 doc = xmlParseFile(original);
586 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", original);
590 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", original);
594 int ret = xmlSaveFile(destination, doc);
596 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
599 pFile = fopen(destination, "r");
602 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", destination);
607 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", destination);
609 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", destination);
613 if (0 > chmod(destination, 0600)) {
614 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
619 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[SUCCESS] Copying xml");
624 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
626 if (NULL == engine_id) {
627 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
631 xmlNodePtr cur = NULL;
632 cur = xmlDocGetRootElement(g_config_doc);
634 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
638 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
639 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
643 cur = cur->xmlChildrenNode;
645 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
649 while (cur != NULL) {
650 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
651 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
654 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
655 xmlNodeSetContent(cur, (const xmlChar *)language);
658 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
659 xmlNodeSetContent(cur, (const xmlChar *)setting);
662 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
664 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
665 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
666 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
667 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
674 if (0 == access(TTS_CONFIG, F_OK)) {
675 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
677 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
680 pFile = fopen(TTS_CONFIG, "r");
683 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
688 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
690 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
693 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
699 int tts_parser_set_voice(const char* language, int type)
701 if (NULL == language) {
702 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
706 xmlNodePtr cur = NULL;
707 cur = xmlDocGetRootElement(g_config_doc);
709 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
713 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
714 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
718 cur = cur->xmlChildrenNode;
720 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
724 while (cur != NULL) {
725 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
726 xmlNodeSetContent(cur, (const xmlChar *)language);
729 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
731 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
732 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
733 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
735 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid type : %d", type);
736 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
744 if (0 == access(TTS_CONFIG, F_OK)) {
745 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
747 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
750 pFile = fopen(TTS_CONFIG, "r");
753 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
758 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
760 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
763 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
768 int tts_parser_set_auto_voice(bool value)
770 xmlNodePtr cur = NULL;
771 cur = xmlDocGetRootElement(g_config_doc);
773 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
777 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
778 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
782 cur = cur->xmlChildrenNode;
784 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
788 while (cur != NULL) {
789 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
791 xmlNodeSetContent(cur, (const xmlChar *)"on");
792 } else if (false == value) {
793 xmlNodeSetContent(cur, (const xmlChar *)"off");
795 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong value of auto voice");
803 if (0 == access(TTS_CONFIG, F_OK)) {
804 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
806 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
809 pFile = fopen(TTS_CONFIG, "r");
812 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
817 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
819 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
822 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
828 int tts_parser_set_speech_rate(int value)
830 xmlNodePtr cur = NULL;
831 cur = xmlDocGetRootElement(g_config_doc);
833 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
837 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
838 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
842 cur = cur->xmlChildrenNode;
844 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
848 while (cur != NULL) {
849 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
851 memset(temp, '\0', 10);
852 snprintf(temp, 10, "%d", value);
854 xmlNodeSetContent(cur, (const xmlChar *)temp);
856 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set speech rate : %s", temp);
863 if (0 == access(TTS_CONFIG, F_OK)) {
864 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
866 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
869 pFile = fopen(TTS_CONFIG, "r");
872 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
877 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
879 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
882 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
888 int tts_parser_set_pitch(int value)
890 xmlNodePtr cur = NULL;
891 cur = xmlDocGetRootElement(g_config_doc);
893 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
897 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
898 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
902 cur = cur->xmlChildrenNode;
904 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
908 while (cur != NULL) {
909 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
911 memset(temp, '\0', 10);
912 snprintf(temp, 10, "%d", value);
913 xmlNodeSetContent(cur, (const xmlChar *)temp);
920 if (0 == access(TTS_CONFIG, F_OK)) {
921 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
923 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
926 pFile = fopen(TTS_CONFIG, "r");
929 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
934 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
936 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
939 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
945 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
946 int* speech_rate, int* pitch)
948 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
949 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
953 xmlDocPtr doc = NULL;
954 xmlNodePtr cur_new = NULL;
955 xmlNodePtr cur_old = NULL;
961 while (NULL == doc) {
962 if (0 == access(TTS_CONFIG, F_OK)) {
963 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", TTS_CONFIG);
964 doc = xmlParseFile(TTS_CONFIG);
972 if (TTS_RETRY_COUNT == retry_count) {
973 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
978 cur_new = xmlDocGetRootElement(doc);
979 cur_old = xmlDocGetRootElement(g_config_doc);
980 if (cur_new == NULL || cur_old == NULL) {
981 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
987 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
988 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
989 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
995 cur_new = cur_new->xmlChildrenNode;
996 cur_old = cur_old->xmlChildrenNode;
997 if (cur_new == NULL || cur_old == NULL) {
998 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
1004 while (cur_new != NULL && cur_old != NULL) {
1005 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1006 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1007 key_old = xmlNodeGetContent(cur_old);
1008 if (NULL != key_old) {
1009 key_new = xmlNodeGetContent(cur_new);
1010 if (NULL != key_new) {
1011 if (0 != xmlStrcmp(key_old, key_new)) {
1012 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
1013 (char*)key_old, (char*)key_new);
1014 if (NULL != *engine) {
1018 *engine = strdup((char*)key_new);
1027 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1029 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1030 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1031 key_old = xmlNodeGetContent(cur_old);
1032 if (NULL != key_old) {
1033 key_new = xmlNodeGetContent(cur_new);
1034 if (NULL != key_new) {
1035 if (0 != xmlStrcmp(key_old, key_new)) {
1036 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)",
1037 (char*)key_old, (char*)key_new);
1038 if (NULL != *setting) {
1042 *setting = strdup((char*)key_new);
1051 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1053 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1054 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1055 key_old = xmlNodeGetContent(cur_old);
1056 if (NULL != key_old) {
1057 key_new = xmlNodeGetContent(cur_new);
1058 if (NULL != key_new) {
1059 if (0 != xmlStrcmp(key_old, key_new)) {
1060 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)",
1061 (char*)key_old, (char*)key_new);
1062 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
1065 *auto_voice = false;
1075 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1077 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1078 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1079 key_old = xmlNodeGetContent(cur_old);
1080 if (NULL != key_old) {
1081 key_new = xmlNodeGetContent(cur_new);
1082 if (NULL != key_new) {
1083 if (0 != xmlStrcmp(key_old, key_new)) {
1084 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)",
1085 (char*)key_old, (char*)key_new);
1086 if (NULL != *language) {
1090 *language = strdup((char*)key_new);
1099 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1101 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1102 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1103 key_old = xmlNodeGetContent(cur_old);
1104 if (NULL != key_old) {
1105 key_new = xmlNodeGetContent(cur_new);
1106 if (NULL != key_new) {
1107 if (0 != xmlStrcmp(key_old, key_new)) {
1108 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)",
1109 (char*)key_old, (char*)key_new);
1110 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1111 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1112 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1113 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1114 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1115 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1117 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] New voice type is not valid");
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_SPEECH_RATE)) {
1130 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
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 speech rate(%s), New speech rate(%s)",
1137 (char*)key_old, (char*)key_new);
1138 *speech_rate = atoi((char*)key_new);
1147 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1149 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1150 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1151 key_old = xmlNodeGetContent(cur_old);
1152 if (NULL != key_old) {
1153 key_new = xmlNodeGetContent(cur_new);
1154 if (NULL != key_new) {
1155 if (0 != xmlStrcmp(key_old, key_new)) {
1156 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)",
1157 (char*)key_old, (char*)key_new);
1158 *pitch = atoi((char*)key_new);
1167 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1173 cur_new = cur_new->next;
1174 cur_old = cur_old->next;
1177 if (NULL != g_config_doc) {
1178 xmlFreeDoc(g_config_doc);
1179 g_config_doc = NULL;
1186 int tts_parser_reset()
1188 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1190 if (NULL != g_config_doc) {
1191 xmlFreeDoc(g_config_doc);
1192 g_config_doc = NULL;
1195 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1196 if (NULL == g_config_doc) {
1197 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1201 if (0 == access(TTS_CONFIG, F_OK)) {
1202 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1204 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save %s", TTS_CONFIG);
1207 pFile = fopen(TTS_CONFIG, "r");
1209 if (NULL == pFile) {
1210 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1215 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1217 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1220 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);