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 // Avoid to parse non-xml file
62 char* file_ext = strrchr(path, '.');
63 if (NULL == ++file_ext || (file_ext && 0 != strncmp("xml", file_ext, strlen(file_ext)))) {
64 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] File extention is not XML type, file_ext(%s)", (file_ext) ? file_ext : "NULL");
68 bool isTextsize = false;
70 xmlNodePtr cur = NULL;
74 if (0 == access(path, F_OK)) {
75 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
76 doc = xmlParseFile(path);
78 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file");
82 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", path);
86 cur = xmlDocGetRootElement(doc);
88 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
94 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
95 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-engine'. doc path(%s, %p)", path, doc);
101 cur = cur->xmlChildrenNode;
103 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
109 /* alloc engine info */
110 tts_engine_info_s* temp;
111 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
113 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory. doc path(%s, %p)", path, doc);
122 temp->setting = NULL;
123 temp->pitch_support = false;
126 while (cur != NULL) {
127 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
128 key = xmlNodeGetContent(cur);
130 if (NULL != temp->name) {
134 temp->name = strdup((char*)key);
138 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
140 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
141 key = xmlNodeGetContent(cur);
143 if (NULL != temp->uuid) {
147 temp->uuid = strdup((char*)key);
151 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
153 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
154 key = xmlNodeGetContent(cur);
156 if (NULL != temp->setting) {
158 temp->setting = NULL;
160 temp->setting = strdup((char*)key);
164 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
166 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
167 xmlNodePtr voice_node = NULL;
168 voice_node = cur->xmlChildrenNode;
170 while (NULL != voice_node) {
171 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
172 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
173 if (NULL == temp_voice) {
174 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory");
178 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
180 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
181 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
182 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
183 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
184 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
185 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
187 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
192 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
198 key = xmlNodeGetContent(voice_node);
200 if (NULL != temp_voice->language) {
201 free(temp_voice->language);
202 temp_voice->language = NULL;
204 temp_voice->language = strdup((char*)key);
207 temp->voices = g_slist_append(temp->voices, temp_voice);
209 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
210 if (NULL != temp_voice) {
216 voice_node = voice_node->next;
218 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
219 key = xmlNodeGetContent(cur);
221 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
222 temp->pitch_support = true;
227 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
229 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
231 key = xmlNodeGetContent(cur);
233 temp->text_size = atoi((char*)key);
236 SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] text size is unlimited.");
243 if (false == isTextsize) {
244 temp->text_size = TTS_MAX_TEXT_SIZE;
248 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc path(%s, %p)", path, doc);
253 if (NULL == temp->uuid) {
255 SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path);
256 tts_parser_free_engine_info(temp);
265 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
267 if (NULL == engine_info) {
268 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
272 if (NULL != engine_info->name) {
273 free(engine_info->name);
274 engine_info->name = NULL;
276 if (NULL != engine_info->uuid) {
277 free(engine_info->uuid);
278 engine_info->uuid = NULL;
280 if (NULL != engine_info->setting) {
281 free(engine_info->setting);
282 engine_info->setting = NULL;
285 tts_config_voice_s *temp_voice;
286 temp_voice = g_slist_nth_data(engine_info->voices, 0);
288 while (NULL != temp_voice) {
289 if (NULL != temp_voice) {
290 if (NULL != temp_voice->language) {
291 free(temp_voice->language);
292 temp_voice->language = NULL;
294 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
299 temp_voice = g_slist_nth_data(engine_info->voices, 0);
302 if (NULL != engine_info) {
310 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
312 if (NULL == engine_info) {
313 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
317 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "== get engine info ==");
318 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " name : %s", engine_info->name);
319 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " id : %s", engine_info->uuid);
320 if (NULL != engine_info->setting)
321 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " setting : %s", engine_info->setting);
323 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voices");
325 tts_config_voice_s *temp_voice;
327 if (g_slist_length(engine_info->voices) > 0) {
328 /* Get a first item */
329 iter = g_slist_nth(engine_info->voices, 0);
332 while (NULL != iter) {
333 /*Get handle data from list*/
334 temp_voice = iter->data;
336 SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] type(%d) lang(%s)",
337 i, temp_voice->type, temp_voice->language);
340 iter = g_slist_next(iter);
344 SLOG(LOG_ERROR, TAG_TTSCONFIG, " Voice is NONE");
347 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@");
352 int tts_parser_load_config(tts_config_s** config_info)
354 if (NULL == config_info) {
355 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
359 xmlDocPtr doc = NULL;
360 xmlNodePtr cur = NULL;
362 bool is_default_open = false;
364 /* For Thread safety */
367 if (0 != access(TTS_CONFIG, F_OK)) {
368 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
370 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
374 is_default_open = true;
378 while (NULL == doc) {
379 doc = xmlParseFile(TTS_CONFIG);
386 if (TTS_RETRY_COUNT == retry_count) {
387 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
388 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
390 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
394 is_default_open = true;
400 cur = xmlDocGetRootElement(doc);
402 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
409 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
410 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
417 cur = cur->xmlChildrenNode;
419 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
426 /* alloc engine info */
428 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
430 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory(%p)", doc);
437 memset(g_engine_id, '\0', sizeof(g_engine_id));
438 memset(g_setting, '\0', sizeof(g_setting));
439 memset(g_language, '\0', sizeof(g_language));
441 temp->engine_id = g_engine_id;
442 temp->setting = g_setting;
443 temp->language = g_language;
445 while (cur != NULL) {
446 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
447 key = xmlNodeGetContent(cur);
449 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
453 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
455 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
456 key = xmlNodeGetContent(cur);
458 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
462 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL");
464 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
465 key = xmlNodeGetContent(cur);
467 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
468 temp->auto_voice = true;
469 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
470 temp->auto_voice = false;
472 SLOG(LOG_ERROR, TAG_TTSCONFIG, "Auto voice is wrong");
473 temp->auto_voice = true;
479 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
481 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
482 key = xmlNodeGetContent(cur);
484 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
485 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
486 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
487 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
488 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
489 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
491 SLOG(LOG_WARN, TAG_TTSCONFIG, "Voice type is user defined");
492 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
498 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
500 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
501 key = xmlNodeGetContent(cur);
503 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
507 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine uuid is NULL");
510 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
511 key = xmlNodeGetContent(cur);
513 temp->speech_rate = atoi((char*)key);
516 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL");
518 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
519 key = xmlNodeGetContent(cur);
521 temp->pitch = atoi((char*)key);
525 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
527 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
528 key = xmlNodeGetContent(cur);
530 temp->bg_volume_ratio = atof((char*)key);
534 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Background volume ratio is NULL");
546 if (true == is_default_open) {
550 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
556 if (TTS_RETRY_COUNT == retry_count) {
557 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
563 if (0 > chmod(TTS_CONFIG, 0600)) {
564 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
567 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default config is changed : pid(%d)", getpid());
573 int tts_parser_unload_config(tts_config_s* config_info)
575 if (NULL != g_config_doc) {
576 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
577 xmlFreeDoc(g_config_doc);
580 if (NULL != config_info) {
581 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free config_info(%p)", config_info);
592 int tts_parser_copy_xml(const char* original, const char* destination)
594 if (NULL == original || NULL == destination) {
595 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
599 xmlDocPtr doc = NULL;
600 if (0 == access(original, F_OK)) {
601 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", original);
602 doc = xmlParseFile(original);
604 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", original);
608 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", original);
612 int ret = xmlSaveFile(destination, doc);
614 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
617 pFile = fopen(destination, "r");
620 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", destination);
625 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", destination);
627 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", destination);
631 if (0 > chmod(destination, 0600)) {
632 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
636 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc(%p)", doc);
641 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[SUCCESS] Copying xml");
646 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
648 if (NULL == engine_id) {
649 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
653 xmlNodePtr cur = NULL;
654 cur = xmlDocGetRootElement(g_config_doc);
656 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
660 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
661 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
665 cur = cur->xmlChildrenNode;
667 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
671 while (cur != NULL) {
672 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
673 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
676 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
677 xmlNodeSetContent(cur, (const xmlChar *)language);
680 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
681 xmlNodeSetContent(cur, (const xmlChar *)setting);
684 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
686 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
687 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
688 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
689 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
696 if (0 == access(TTS_CONFIG, F_OK)) {
697 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
699 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
702 pFile = fopen(TTS_CONFIG, "r");
705 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
710 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
712 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
715 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
721 int tts_parser_set_voice(const char* language, int type)
723 if (NULL == language) {
724 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
728 xmlNodePtr cur = NULL;
729 cur = xmlDocGetRootElement(g_config_doc);
731 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
735 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
736 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
740 cur = cur->xmlChildrenNode;
742 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
746 while (cur != NULL) {
747 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
748 xmlNodeSetContent(cur, (const xmlChar *)language);
751 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
753 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
754 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
755 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
757 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid type : %d", type);
758 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
766 if (0 == access(TTS_CONFIG, F_OK)) {
767 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
769 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
772 pFile = fopen(TTS_CONFIG, "r");
775 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
780 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
782 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
785 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
790 int tts_parser_set_auto_voice(bool value)
792 xmlNodePtr cur = NULL;
793 cur = xmlDocGetRootElement(g_config_doc);
795 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
799 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
800 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
804 cur = cur->xmlChildrenNode;
806 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
810 while (cur != NULL) {
811 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
813 xmlNodeSetContent(cur, (const xmlChar *)"on");
814 } else if (false == value) {
815 xmlNodeSetContent(cur, (const xmlChar *)"off");
817 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong value of auto voice");
825 if (0 == access(TTS_CONFIG, F_OK)) {
826 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
828 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
831 pFile = fopen(TTS_CONFIG, "r");
834 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
839 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
841 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
844 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
850 int tts_parser_set_speech_rate(int value)
852 xmlNodePtr cur = NULL;
853 cur = xmlDocGetRootElement(g_config_doc);
855 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
859 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
860 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
864 cur = cur->xmlChildrenNode;
866 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
870 while (cur != NULL) {
871 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
873 memset(temp, '\0', 10);
874 snprintf(temp, 10, "%d", value);
876 xmlNodeSetContent(cur, (const xmlChar *)temp);
878 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set speech rate : %s", temp);
885 if (0 == access(TTS_CONFIG, F_OK)) {
886 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
888 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
891 pFile = fopen(TTS_CONFIG, "r");
894 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
899 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
901 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
904 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
910 int tts_parser_set_pitch(int value)
912 xmlNodePtr cur = NULL;
913 cur = xmlDocGetRootElement(g_config_doc);
915 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
919 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
920 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
924 cur = cur->xmlChildrenNode;
926 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
930 while (cur != NULL) {
931 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
933 memset(temp, '\0', 10);
934 snprintf(temp, 10, "%d", value);
935 xmlNodeSetContent(cur, (const xmlChar *)temp);
942 if (0 == access(TTS_CONFIG, F_OK)) {
943 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
945 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
948 pFile = fopen(TTS_CONFIG, "r");
951 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
956 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
958 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
961 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
967 int tts_parser_set_bg_volume_ratio(double value)
969 xmlNodePtr cur = NULL;
970 cur = xmlDocGetRootElement(g_config_doc);
972 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
976 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
977 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
981 cur = cur->xmlChildrenNode;
983 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
987 while (cur != NULL) {
988 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
990 memset(temp, '\0', 10);
991 snprintf(temp, 10, "%lf", value);
992 xmlNodeSetContent(cur, (const xmlChar *)temp);
999 if (0 == access(TTS_CONFIG, F_OK)) {
1000 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1002 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
1005 pFile = fopen(TTS_CONFIG, "r");
1007 if (NULL == pFile) {
1008 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1013 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1015 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1018 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
1024 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
1025 int* speech_rate, int* pitch, double* bg_volume_ratio)
1027 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
1028 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
1032 xmlDocPtr doc = NULL;
1033 xmlNodePtr cur_new = NULL;
1034 xmlNodePtr cur_old = NULL;
1039 int retry_count = 0;
1040 while (NULL == doc) {
1041 if (0 == access(TTS_CONFIG, F_OK)) {
1042 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", TTS_CONFIG);
1043 doc = xmlParseFile(TTS_CONFIG);
1051 if (TTS_RETRY_COUNT == retry_count) {
1052 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
1057 cur_new = xmlDocGetRootElement(doc);
1058 cur_old = xmlDocGetRootElement(g_config_doc);
1059 if (cur_new == NULL || cur_old == NULL) {
1060 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
1066 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
1067 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
1068 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc);
1074 cur_new = cur_new->xmlChildrenNode;
1075 cur_old = cur_old->xmlChildrenNode;
1076 if (cur_new == NULL || cur_old == NULL) {
1077 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
1083 while (cur_new != NULL && cur_old != NULL) {
1084 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1085 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
1086 key_old = xmlNodeGetContent(cur_old);
1087 if (NULL != key_old) {
1088 key_new = xmlNodeGetContent(cur_new);
1089 if (NULL != key_new) {
1090 if (0 != xmlStrcmp(key_old, key_new)) {
1091 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
1092 (char*)key_old, (char*)key_new);
1093 if (NULL != *engine) {
1097 *engine = strdup((char*)key_new);
1106 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1108 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1109 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
1110 key_old = xmlNodeGetContent(cur_old);
1111 if (NULL != key_old) {
1112 key_new = xmlNodeGetContent(cur_new);
1113 if (NULL != key_new) {
1114 if (0 != xmlStrcmp(key_old, key_new)) {
1115 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)",
1116 (char*)key_old, (char*)key_new);
1117 if (NULL != *setting) {
1121 *setting = strdup((char*)key_new);
1130 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1132 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1133 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
1134 key_old = xmlNodeGetContent(cur_old);
1135 if (NULL != key_old) {
1136 key_new = xmlNodeGetContent(cur_new);
1137 if (NULL != key_new) {
1138 if (0 != xmlStrcmp(key_old, key_new)) {
1139 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)",
1140 (char*)key_old, (char*)key_new);
1141 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
1144 *auto_voice = false;
1154 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1156 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1157 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1158 key_old = xmlNodeGetContent(cur_old);
1159 if (NULL != key_old) {
1160 key_new = xmlNodeGetContent(cur_new);
1161 if (NULL != key_new) {
1162 if (0 != xmlStrcmp(key_old, key_new)) {
1163 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)",
1164 (char*)key_old, (char*)key_new);
1165 if (NULL != *language) {
1169 *language = strdup((char*)key_new);
1178 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1180 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1181 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1182 key_old = xmlNodeGetContent(cur_old);
1183 if (NULL != key_old) {
1184 key_new = xmlNodeGetContent(cur_new);
1185 if (NULL != key_new) {
1186 if (0 != xmlStrcmp(key_old, key_new)) {
1187 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)",
1188 (char*)key_old, (char*)key_new);
1189 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1190 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1191 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1192 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1193 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1194 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1196 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] New voice type is not valid");
1206 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1208 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1209 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1210 key_old = xmlNodeGetContent(cur_old);
1211 if (NULL != key_old) {
1212 key_new = xmlNodeGetContent(cur_new);
1213 if (NULL != key_new) {
1214 if (0 != xmlStrcmp(key_old, key_new)) {
1215 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old speech rate(%s), New speech rate(%s)",
1216 (char*)key_old, (char*)key_new);
1217 *speech_rate = atoi((char*)key_new);
1226 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1228 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1229 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1230 key_old = xmlNodeGetContent(cur_old);
1231 if (NULL != key_old) {
1232 key_new = xmlNodeGetContent(cur_new);
1233 if (NULL != key_new) {
1234 if (0 != xmlStrcmp(key_old, key_new)) {
1235 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)",
1236 (char*)key_old, (char*)key_new);
1237 *pitch = atoi((char*)key_new);
1246 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1248 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
1249 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
1250 key_old = xmlNodeGetContent(cur_old);
1251 if (NULL != key_old) {
1252 key_new = xmlNodeGetContent(cur_new);
1253 if (NULL != key_new) {
1254 if (0 != xmlStrcmp(key_old, key_new)) {
1255 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)",
1256 (char*)key_old, (char*)key_new);
1257 *bg_volume_ratio = atof((char*)key_new);
1266 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
1272 cur_new = cur_new->next;
1273 cur_old = cur_old->next;
1276 if (NULL != g_config_doc) {
1277 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1278 xmlFreeDoc(g_config_doc);
1279 g_config_doc = NULL;
1286 int tts_parser_reset()
1288 SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1290 if (NULL != g_config_doc) {
1291 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc);
1292 xmlFreeDoc(g_config_doc);
1293 g_config_doc = NULL;
1296 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1297 if (NULL == g_config_doc) {
1298 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1302 if (0 == access(TTS_CONFIG, F_OK)) {
1303 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1305 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save %s", TTS_CONFIG);
1308 pFile = fopen(TTS_CONFIG, "r");
1310 if (NULL == pFile) {
1311 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
1316 SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
1318 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
1321 SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);