2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
20 #include "tts_config_parser.h"
24 #define TTS_TAG_ENGINE_BASE_TAG "tts-engine"
25 #define TTS_TAG_ENGINE_NAME "name"
26 #define TTS_TAG_ENGINE_ID "id"
27 #define TTS_TAG_ENGINE_SETTING "setting"
28 #define TTS_TAG_ENGINE_VOICE_SET "voices"
29 #define TTS_TAG_ENGINE_VOICE "voice"
30 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
31 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
32 #define TTS_TAG_ENGINE_TEXT_SIZE "text-size"
34 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
35 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
36 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
37 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
38 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
39 #define TTS_TAG_CONFIG_LANGUAGE "language"
40 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
41 #define TTS_TAG_CONFIG_PITCH "pitch"
42 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
43 #define TTS_TAG_VOICE_TYPE_MALE "male"
44 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 #define TTS_MAX_TEXT_SIZE 2000
48 extern char* tts_tag();
50 static xmlDocPtr g_config_doc = NULL;
51 char g_engine_id[128] = {0,};
52 char g_setting[128] = {0,};
53 char g_language[128] = {0,};
55 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
57 if (NULL == path || NULL == engine_info) {
58 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
62 bool isTextsize = false;
64 xmlNodePtr cur = NULL;
68 if (0 == access(path, F_OK)) {
69 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to access to %s", path);
70 doc = xmlParseFile(path);
72 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
76 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", path);
80 cur = xmlDocGetRootElement(doc);
82 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
88 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
89 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
95 cur = cur->xmlChildrenNode;
97 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
103 /* alloc engine info */
104 tts_engine_info_s* temp;
105 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
107 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
116 temp->setting = NULL;
117 temp->pitch_support = false;
120 while (cur != NULL) {
121 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
122 key = xmlNodeGetContent(cur);
124 if (NULL != temp->name) {
128 temp->name = strdup((char*)key);
132 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
134 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
135 key = xmlNodeGetContent(cur);
137 if (NULL != temp->uuid) {
141 temp->uuid = strdup((char*)key);
145 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
147 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
148 key = xmlNodeGetContent(cur);
150 if (NULL != temp->setting) {
152 temp->setting = NULL;
154 temp->setting = strdup((char*)key);
158 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
160 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
161 xmlNodePtr voice_node = NULL;
162 voice_node = cur->xmlChildrenNode;
164 while (NULL != voice_node) {
165 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
166 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
167 if (NULL == temp_voice) {
168 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
172 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
174 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
175 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
176 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
177 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
178 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
179 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
181 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
186 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
192 key = xmlNodeGetContent(voice_node);
194 if (NULL != temp_voice->language) {
195 free(temp_voice->language);
196 temp_voice->language = NULL;
198 temp_voice->language = strdup((char*)key);
201 temp->voices = g_slist_append(temp->voices, temp_voice);
203 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
204 if (NULL != temp_voice) {
210 voice_node = voice_node->next;
212 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
213 key = xmlNodeGetContent(cur);
215 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
216 temp->pitch_support = true;
221 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
223 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
225 key = xmlNodeGetContent(cur);
227 temp->text_size = atoi((char*)key);
230 SLOG(LOG_INFO, tts_tag(), "[INFO] text size is unlimited.");
237 if (false == isTextsize) {
238 temp->text_size = TTS_MAX_TEXT_SIZE;
244 if (NULL == temp->uuid) {
246 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
247 tts_parser_free_engine_info(temp);
256 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
258 if (NULL == engine_info) {
259 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
263 if (NULL != engine_info->name) {
264 free(engine_info->name);
265 engine_info->name = NULL;
267 if (NULL != engine_info->uuid) {
268 free(engine_info->uuid);
269 engine_info->uuid = NULL;
271 if (NULL != engine_info->setting) {
272 free(engine_info->setting);
273 engine_info->setting = NULL;
276 tts_config_voice_s *temp_voice;
277 temp_voice = g_slist_nth_data(engine_info->voices, 0);
279 while (NULL != temp_voice) {
280 if (NULL != temp_voice) {
281 if (NULL != temp_voice->language) {
282 free(temp_voice->language);
283 temp_voice->language = NULL;
285 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
290 temp_voice = g_slist_nth_data(engine_info->voices, 0);
293 if (NULL != engine_info) {
301 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
303 if (NULL == engine_info) {
304 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
308 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
309 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
310 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
311 if (NULL != engine_info->setting)
312 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
314 SLOG(LOG_DEBUG, tts_tag(), " voices");
316 tts_config_voice_s *temp_voice;
318 if (g_slist_length(engine_info->voices) > 0) {
319 /* Get a first item */
320 iter = g_slist_nth(engine_info->voices, 0);
323 while (NULL != iter) {
324 /*Get handle data from list*/
325 temp_voice = iter->data;
327 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
328 i, temp_voice->type, temp_voice->language);
331 iter = g_slist_next(iter);
335 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
338 SLOG(LOG_DEBUG, tts_tag(), "@@@");
343 int tts_parser_load_config(tts_config_s** config_info)
345 if (NULL == config_info) {
346 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
350 xmlDocPtr doc = NULL;
351 xmlNodePtr cur = NULL;
353 bool is_default_open = false;
355 /* For Thread safety */
358 if (0 != access(TTS_CONFIG, F_OK)) {
359 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
361 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
365 is_default_open = true;
369 while (NULL == doc) {
370 doc = xmlParseFile(TTS_CONFIG);
377 if (TTS_RETRY_COUNT == retry_count) {
378 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
379 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
381 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
385 is_default_open = true;
391 cur = xmlDocGetRootElement(doc);
393 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
400 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
401 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
408 cur = cur->xmlChildrenNode;
410 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
417 /* alloc engine info */
419 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
421 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
428 memset(g_engine_id, '\0', sizeof(g_engine_id));
429 memset(g_setting, '\0', sizeof(g_setting));
430 memset(g_language, '\0', sizeof(g_language));
432 temp->engine_id = g_engine_id;
433 temp->setting = g_setting;
434 temp->language = g_language;
436 while (cur != NULL) {
437 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
438 key = xmlNodeGetContent(cur);
440 strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
444 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
446 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
447 key = xmlNodeGetContent(cur);
449 strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
453 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
455 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
456 key = xmlNodeGetContent(cur);
458 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
459 temp->auto_voice = true;
460 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
461 temp->auto_voice = false;
463 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
464 temp->auto_voice = true;
470 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
472 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
473 key = xmlNodeGetContent(cur);
475 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
476 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
477 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
478 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
479 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
480 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
482 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
483 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
489 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
491 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
492 key = xmlNodeGetContent(cur);
494 strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
498 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
501 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
502 key = xmlNodeGetContent(cur);
504 temp->speech_rate = atoi((char*)key);
507 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
509 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
510 key = xmlNodeGetContent(cur);
512 temp->pitch = atoi((char*)key);
516 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
528 if (true == is_default_open) {
532 ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
538 if (TTS_RETRY_COUNT == retry_count) {
539 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
545 if (0 > chmod(TTS_CONFIG, 0600)) {
546 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
550 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
551 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
553 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
559 int tts_parser_unload_config(tts_config_s* config_info)
561 if (NULL != g_config_doc) {
562 xmlFreeDoc(g_config_doc);
565 if (NULL != config_info) {
576 int tts_parser_copy_xml(const char* original, const char* destination)
578 if (NULL == original || NULL == destination) {
579 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
583 xmlDocPtr doc = NULL;
584 if (0 == access(original, F_OK)) {
585 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to access to %s", original);
586 doc = xmlParseFile(original);
588 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
592 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", original);
596 int ret = xmlSaveFile(destination, doc);
598 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
600 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", destination);
604 if (0 > chmod(destination, 0600)) {
605 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
610 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
615 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
617 if (NULL == engine_id) {
618 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
622 xmlNodePtr cur = NULL;
623 cur = xmlDocGetRootElement(g_config_doc);
625 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
629 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
630 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
634 cur = cur->xmlChildrenNode;
636 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
640 while (cur != NULL) {
641 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
642 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
645 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
646 xmlNodeSetContent(cur, (const xmlChar *)language);
649 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
650 xmlNodeSetContent(cur, (const xmlChar *)setting);
653 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
655 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
656 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
657 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
658 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
665 if (0 == access(TTS_CONFIG, F_OK)) {
666 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
668 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
670 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
673 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);
679 int tts_parser_set_voice(const char* language, int type)
681 if (NULL == language) {
682 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
686 xmlNodePtr cur = NULL;
687 cur = xmlDocGetRootElement(g_config_doc);
689 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
693 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
694 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
698 cur = cur->xmlChildrenNode;
700 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
704 while (cur != NULL) {
705 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
706 xmlNodeSetContent(cur, (const xmlChar *)language);
709 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
711 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
712 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
713 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
715 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
716 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
724 if (0 == access(TTS_CONFIG, F_OK)) {
725 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
727 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
729 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
732 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);
737 int tts_parser_set_auto_voice(bool value)
739 xmlNodePtr cur = NULL;
740 cur = xmlDocGetRootElement(g_config_doc);
742 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
746 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
747 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
751 cur = cur->xmlChildrenNode;
753 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
757 while (cur != NULL) {
758 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
760 xmlNodeSetContent(cur, (const xmlChar *)"on");
761 } else if (false == value) {
762 xmlNodeSetContent(cur, (const xmlChar *)"off");
764 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
772 if (0 == access(TTS_CONFIG, F_OK)) {
773 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
775 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
777 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
780 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);
786 int tts_parser_set_speech_rate(int value)
788 xmlNodePtr cur = NULL;
789 cur = xmlDocGetRootElement(g_config_doc);
791 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
795 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
796 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
800 cur = cur->xmlChildrenNode;
802 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
806 while (cur != NULL) {
807 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
809 memset(temp, '\0', 10);
810 snprintf(temp, 10, "%d", value);
812 xmlNodeSetContent(cur, (const xmlChar *)temp);
814 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
821 if (0 == access(TTS_CONFIG, F_OK)) {
822 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
824 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
826 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
829 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);
835 int tts_parser_set_pitch(int value)
837 xmlNodePtr cur = NULL;
838 cur = xmlDocGetRootElement(g_config_doc);
840 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
844 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
845 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
849 cur = cur->xmlChildrenNode;
851 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
855 while (cur != NULL) {
856 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
858 memset(temp, '\0', 10);
859 snprintf(temp, 10, "%d", value);
860 xmlNodeSetContent(cur, (const xmlChar *)temp);
867 if (0 == access(TTS_CONFIG, F_OK)) {
868 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
870 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
872 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
875 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);
881 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
882 int* speech_rate, int* pitch)
884 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
885 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
889 xmlDocPtr doc = NULL;
890 xmlNodePtr cur_new = NULL;
891 xmlNodePtr cur_old = NULL;
897 while (NULL == doc) {
898 if (0 == access(TTS_CONFIG, F_OK)) {
899 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to access to %s", TTS_CONFIG);
900 doc = xmlParseFile(TTS_CONFIG);
908 if (TTS_RETRY_COUNT == retry_count) {
909 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
914 cur_new = xmlDocGetRootElement(doc);
915 cur_old = xmlDocGetRootElement(g_config_doc);
916 if (cur_new == NULL || cur_old == NULL) {
917 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
923 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
924 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
925 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
931 cur_new = cur_new->xmlChildrenNode;
932 cur_old = cur_old->xmlChildrenNode;
933 if (cur_new == NULL || cur_old == NULL) {
934 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
940 while (cur_new != NULL && cur_old != NULL) {
941 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
942 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
943 key_old = xmlNodeGetContent(cur_old);
944 if (NULL != key_old) {
945 key_new = xmlNodeGetContent(cur_new);
946 if (NULL != key_new) {
947 if (0 != xmlStrcmp(key_old, key_new)) {
948 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
949 (char*)key_old, (char*)key_new);
950 if (NULL != *engine) {
954 *engine = strdup((char*)key_new);
963 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
965 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
966 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
967 key_old = xmlNodeGetContent(cur_old);
968 if (NULL != key_old) {
969 key_new = xmlNodeGetContent(cur_new);
970 if (NULL != key_new) {
971 if (0 != xmlStrcmp(key_old, key_new)) {
972 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
973 (char*)key_old, (char*)key_new);
974 if (NULL != *setting) {
978 *setting = strdup((char*)key_new);
987 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
989 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
990 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
991 key_old = xmlNodeGetContent(cur_old);
992 if (NULL != key_old) {
993 key_new = xmlNodeGetContent(cur_new);
994 if (NULL != key_new) {
995 if (0 != xmlStrcmp(key_old, key_new)) {
996 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
997 (char*)key_old, (char*)key_new);
998 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
1001 *auto_voice = false;
1011 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1013 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1014 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
1015 key_old = xmlNodeGetContent(cur_old);
1016 if (NULL != key_old) {
1017 key_new = xmlNodeGetContent(cur_new);
1018 if (NULL != key_new) {
1019 if (0 != xmlStrcmp(key_old, key_new)) {
1020 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
1021 (char*)key_old, (char*)key_new);
1022 if (NULL != *language) {
1026 *language = strdup((char*)key_new);
1035 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1037 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1038 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
1039 key_old = xmlNodeGetContent(cur_old);
1040 if (NULL != key_old) {
1041 key_new = xmlNodeGetContent(cur_new);
1042 if (NULL != key_new) {
1043 if (0 != xmlStrcmp(key_old, key_new)) {
1044 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
1045 (char*)key_old, (char*)key_new);
1046 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
1047 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
1048 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
1049 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
1050 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
1051 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
1053 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
1063 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1065 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1066 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1067 key_old = xmlNodeGetContent(cur_old);
1068 if (NULL != key_old) {
1069 key_new = xmlNodeGetContent(cur_new);
1070 if (NULL != key_new) {
1071 if (0 != xmlStrcmp(key_old, key_new)) {
1072 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1073 (char*)key_old, (char*)key_new);
1074 *speech_rate = atoi((char*)key_new);
1083 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1085 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1086 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1087 key_old = xmlNodeGetContent(cur_old);
1088 if (NULL != key_old) {
1089 key_new = xmlNodeGetContent(cur_new);
1090 if (NULL != key_new) {
1091 if (0 != xmlStrcmp(key_old, key_new)) {
1092 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1093 (char*)key_old, (char*)key_new);
1094 *pitch = atoi((char*)key_new);
1103 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1109 cur_new = cur_new->next;
1110 cur_old = cur_old->next;
1113 if (NULL != g_config_doc) {
1114 xmlFreeDoc(g_config_doc);
1115 g_config_doc = NULL;
1122 int tts_parser_reset()
1124 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG);
1126 if (NULL != g_config_doc) {
1127 xmlFreeDoc(g_config_doc);
1128 g_config_doc = NULL;
1131 g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG);
1132 if (NULL == g_config_doc) {
1133 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG);
1137 if (0 == access(TTS_CONFIG, F_OK)) {
1138 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
1140 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save %s", TTS_CONFIG);
1142 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG);
1145 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to access to %s", TTS_CONFIG);