return __tts_convert_config_error_code(ret);
}
- ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
+ ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
tts_client_destroy(*tts);
static tts_setting_pitch_changed_cb g_pitch_changed_cb;
static void* g_pitch_changed_user_data;
+static tts_setting_background_volume_ratio_changed_cb g_bg_volume_ratio_changed_cb;
+static void* g_bg_volume_ratio_changed_user_data;
const char* tts_tag()
g_pitch_changed_cb(value, g_pitch_changed_user_data);
}
+void __setting_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "Rratio : %lf", value);
+
+ if (NULL != g_bg_volume_ratio_changed_cb)
+ g_bg_volume_ratio_changed_cb(value, g_bg_volume_ratio_changed_user_data);
+}
+
int tts_setting_initialize()
{
SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Initialize TTS Setting");
return __setting_convert_config_error_code(ret);
}
- ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb,
- __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, NULL);
+ ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb,
+ __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, __setting_config_bg_volume_ratio_changed_cb, NULL);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
return __setting_convert_config_error_code(ret);
return __setting_convert_config_error_code(ret);
}
+int tts_setting_get_background_volume_ratio(double *ratio)
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get background ratio");
+
+ if (TTS_SETTING_STATE_NONE == g_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+ return TTS_SETTING_ERROR_INVALID_STATE;
+ }
+
+ if (NULL == ratio) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Param is NULL");
+ return TTS_SETTING_ERROR_INVALID_PARAMETER;
+ }
+
+ double temp;
+ temp = 0;
+
+ int ret = tts_config_mgr_get_bg_volume_ratio(&temp);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+ } else {
+ /* Copy value */
+ *ratio = temp;
+ SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get bg volume duration : %lf", *ratio);
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return __setting_convert_config_error_code(ret);
+}
+
+int tts_setting_set_background_volume_ratio(double ratio)
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set bg volume duration");
+
+ if (TTS_SETTING_STATE_NONE == g_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+ return TTS_SETTING_ERROR_INVALID_STATE;
+ }
+
+ if (0.0 > ratio || ratio > 1.0) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid bg volume ratio(%lf)", ratio);
+ return TTS_SETTING_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = tts_config_mgr_set_bg_volume_ratio(ratio);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+ } else {
+ SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set bg volume ratio : %lf", ratio);
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return __setting_convert_config_error_code(ret);
+}
+
int tts_setting_get_pitch(int* pitch)
{
SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default pitch");
return TTS_SETTING_ERROR_NONE;
}
+
+
+int tts_setting_set_background_volume_ratio_changed_cb(tts_setting_background_volume_ratio_changed_cb callback, void* user_data)
+{
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input param is NULL");
+ return TTS_SETTING_ERROR_INVALID_PARAMETER;
+ }
+
+ g_bg_volume_ratio_changed_cb = callback;
+ g_bg_volume_ratio_changed_user_data = user_data;
+
+ return TTS_SETTING_ERROR_NONE;
+}
+
+int tts_setting_unset_background_volume_ratio_changed_cb()
+{
+ g_bg_volume_ratio_changed_cb = NULL;
+ g_bg_volume_ratio_changed_user_data = NULL;
+
+ return TTS_SETTING_ERROR_NONE;
+}
tts_config_speech_rate_changed_cb speech_cb;
tts_config_screen_reader_changed_cb screen_cb;
tts_config_pitch_changed_cb pitch_cb;
+ tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb;
void* user_data;
} tts_config_client_s;
int voice_type = -1;
int speech_rate = -1;
int pitch = -1;
+ double bg_volume_ratio = -1;
GSList *iter = NULL;
tts_config_client_s* temp_client = NULL;
- if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch))
+ if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch, &bg_volume_ratio))
return ECORE_CALLBACK_PASS_ON;
/* engine changed */
}
}
+ if (-1 != bg_volume_ratio) {
+ g_config_info->bg_volume_ratio = bg_volume_ratio;
+
+ SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio change(%lf)", g_config_info->bg_volume_ratio);
+
+ /* Call all callbacks of client*/
+ iter = g_slist_nth(g_config_client_list, 0);
+
+ while (NULL != iter) {
+ temp_client = iter->data;
+
+ if (NULL != temp_client) {
+ if (NULL != temp_client->bg_volume_ratio_cb) {
+ SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio changed callback : uid(%d)", temp_client->uid);
+ temp_client->bg_volume_ratio_cb(g_config_info->bg_volume_ratio, temp_client->user_data);
+ }
+ }
+
+ iter = g_slist_next(iter);
+ }
+ }
+
if (NULL != engine) {
free(engine);
engine = NULL;
temp_client->speech_cb = NULL;
temp_client->pitch_cb = NULL;
temp_client->screen_cb = NULL;
+ temp_client->bg_volume_ratio_cb = NULL;
temp_client->user_data = NULL;
g_config_client_list = g_slist_append(g_config_client_list, temp_client);
temp_client->speech_cb = NULL;
temp_client->pitch_cb = NULL;
temp_client->screen_cb = NULL;
+ temp_client->bg_volume_ratio_cb = NULL;
temp_client->user_data = NULL;
g_config_client_list = g_slist_append(g_config_client_list, temp_client);
SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voice type : %d", g_config_info->type);
SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " speech rate : %d", g_config_info->speech_rate);
SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " pitch : %d", g_config_info->pitch);
+ SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " bg volume ratio : %lf", g_config_info->bg_volume_ratio);
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@@@");
if (0 != __tts_config_mgr_register_config_event()) {
tts_config_voice_changed_cb voice_cb,
tts_config_speech_rate_changed_cb speech_cb,
tts_config_pitch_changed_cb pitch_cb,
+ tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb,
void* user_data)
{
GSList *iter = NULL;
temp_client->voice_cb = voice_cb;
temp_client->speech_cb = speech_cb;
temp_client->pitch_cb = pitch_cb;
+ temp_client->bg_volume_ratio_cb = bg_volume_ratio_cb;
temp_client->user_data = user_data;
}
}
temp_client->voice_cb = NULL;
temp_client->speech_cb = NULL;
temp_client->pitch_cb = NULL;
+ temp_client->bg_volume_ratio_cb = NULL;
temp_client->user_data = NULL;
}
}
return 0;
}
+int tts_config_mgr_get_bg_volume_ratio(double *value)
+{
+ if (0 >= g_slist_length(g_config_client_list)) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+ return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == value)
+ return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+ else
+ *value = g_config_info->bg_volume_ratio;
+
+ return 0;
+}
+
+int tts_config_mgr_set_bg_volume_ratio(double value)
+{
+ if (0 >= g_slist_length(g_config_client_list)) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+ return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
+ if (0 != tts_parser_set_bg_volume_ratio(value))
+ {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
+
+ g_config_info->bg_volume_ratio = value;
+
+ return 0;
+}
+
bool tts_config_check_default_engine_is_valid(const char* engine)
{
if (0 >= g_slist_length(g_config_client_list)) {
typedef void (*tts_config_pitch_changed_cb)(int value, void* user_data);
+typedef void (*tts_config_bg_volume_ratio_changed_cb)(double value, void* user_data);
+
typedef void (*tts_config_screen_reader_changed_cb)(bool value);
tts_config_voice_changed_cb voice_cb,
tts_config_speech_rate_changed_cb speech_cb,
tts_config_pitch_changed_cb pitch_cb,
+ tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb,
void* user_data);
int tts_config_mgr_unset_callback(int uid);
int tts_config_mgr_set_pitch(int value);
+int tts_config_mgr_get_bg_volume_ratio(double *value);
+int tts_config_mgr_set_bg_volume_ratio(double value);
+
bool tts_config_check_default_engine_is_valid(const char* engine);
bool tts_config_check_default_voice_is_valid(const char* language, int type);
#define TTS_TAG_CONFIG_LANGUAGE "language"
#define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
#define TTS_TAG_CONFIG_PITCH "pitch"
+#define TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO "background-volume-ratio"
#define TTS_TAG_VOICE_TYPE_FEMALE "female"
#define TTS_TAG_VOICE_TYPE_MALE "male"
#define TTS_TAG_VOICE_TYPE_CHILD "child"
} else {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
}
+ } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+ key = xmlNodeGetContent(cur);
+ if (NULL != key) {
+ temp->bg_volume_ratio = atof((char*)key);
+ xmlFree(key);
+ key = NULL;
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Background volume ratio is NULL");
+ }
} else {
}
return 0;
}
+int tts_parser_set_bg_volume_ratio(double value)
+{
+ xmlNodePtr cur = NULL;
+ cur = xmlDocGetRootElement(g_config_doc);
+ if (cur == NULL) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+ return -1;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
+ return -1;
+ }
+
+ cur = cur->xmlChildrenNode;
+ if (cur == NULL) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+ return -1;
+ }
+
+ while (cur != NULL) {
+ if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+ char temp[10];
+ memset(temp, '\0', 10);
+ snprintf(temp, 10, "%lf", value);
+ xmlNodeSetContent(cur, (const xmlChar *)temp);
+ break;
+ }
+
+ cur = cur->next;
+ }
+
+ if (0 == access(TTS_CONFIG, F_OK)) {
+ int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
+ if (0 > ret) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
+ } else {
+ static FILE* pFile;
+ pFile = fopen(TTS_CONFIG, "r");
+ int fd = -1;
+ if (NULL == pFile) {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
+ } else {
+ fd = fileno(pFile);
+ fsync(fd);
+ fclose(pFile);
+ SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
+ }
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
+ }
+
+ return 0;
+}
+
int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
- int* speech_rate, int* pitch)
+ int* speech_rate, int* pitch, double* bg_volume_ratio)
{
if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
} else {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
}
+ } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+ if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+ key_old = xmlNodeGetContent(cur_old);
+ if (NULL != key_old) {
+ key_new = xmlNodeGetContent(cur_new);
+ if (NULL != key_new) {
+ if (0 != xmlStrcmp(key_old, key_new)) {
+ SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)",
+ (char*)key_old, (char*)key_new);
+ *bg_volume_ratio = atof((char*)key_new);
+ }
+ xmlFree(key_new);
+ key_new = NULL;
+ }
+ xmlFree(key_old);
+ key_old = NULL;
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
+ }
} else {
}
int speech_rate;
int pitch;
bool credential;
+ double bg_volume_ratio;
} tts_config_s;
int tts_parser_set_pitch(int value);
+int tts_parser_set_bg_volume_ratio(double value);
+
int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
- int* speech_rate, int* pitch);
+ int* speech_rate, int* pitch, double* bg_volume_ratio);
int tts_parser_copy_xml(const char* original, const char* destination);
*/
typedef void (*tts_setting_pitch_changed_cb)(int pitch, void *user_data);
+/**
+* @brief Called when the current background volume ratio is changed.
+*
+* @param[in] ratio Current background volume ratio
+* @param[in] user_data The user data passed from the callback registration function
+*
+* @pre An application registers this callback using registration function.
+*
+* @see tts_setting_set_background_volume_ratio_changed_cb()
+* @see tts_setting_unset_background_volume_ratio_changed_cb()
+*/
+typedef void (*tts_setting_background_volume_ratio_changed_cb)(double ratio, void *user_data);
/**
* @brief Initialize TTS setting.
int tts_setting_set_pitch(int pitch);
/**
+* @brief Gets a current background volume ratio.
+*
+* @param[out] ratio Current background volume ratio
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #TTS_SETTING_ERROR_NONE Success.
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #TTS_SETTING_ERROR_INVALID_STATE Not initialized.
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Operation failure.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED_FEATURE Not supported feature.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_set_background_volume_ratio()
+*/
+int tts_setting_get_background_volume_ratio(double *ratio);
+
+/**
+* @brief Sets a current background volume ratio.
+*
+* @param[in] ratio Current background volume ratio (Range 0.0 ~ 1.0)
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #TTS_SETTING_ERROR_NONE Success.
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #TTS_SETTING_ERROR_INVALID_STATE Not initialized.
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Operation failure.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED_FEATURE Not supported feature.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_get_background_volume_ratio()
+*/
+int tts_setting_set_background_volume_ratio(double ratio);
+
+/**
* @brief Registers a callback function to be called when engine information is changed
*
* @param[in] callback The callback function to register
int tts_setting_unset_pitch_changed_cb();
+/**
+* @brief Sets a callback function to be called when current background volume is changed
+*
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #TTS_SETTING_ERROR_NONE Successful
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Invalid state
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_background_volume_ratio_changed_cb()
+* @see tts_setting_unset_background_volume_ratio_changed_cb()
+*/
+int tts_setting_set_background_volume_ratio_changed_cb(tts_setting_background_volume_ratio_changed_cb callback, void* user_data);
+
+/**
+* @brief Unsets the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #TTS_SETTING_ERROR_NONE Successful
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Invalid state
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_set_background_volume_ratio_changed_cb()
+*/
+int tts_setting_unset_background_volume_ratio_changed_cb();
+
#ifdef __cplusplus
}
#endif
if (NULL != g_callback) {
SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the engine reload callback : engine id(%s)", engine_id);
- g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0);
+ g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0, 0);
SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the voice changed callback : lang(%s), type(%d)", language, voice_type);
- g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type);
+ g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type, 0);
} else {
SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
}
if (NULL != g_callback) {
- g_callback(TTS_CONFIG_TYPE_VOICE, language, type);
+ g_callback(TTS_CONFIG_TYPE_VOICE, language, type, 0);
} else {
SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
void __ttsd_config_speech_rate_changed_cb(int value, void* user_data)
{
if (NULL != g_callback) {
- g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value);
+ g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value, 0);
} else {
SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
void __ttsd_config_pitch_changed_cb(int value, void* user_data)
{
if (NULL != g_callback) {
- g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value);
+ g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value, 0);
} else {
SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
}
}
+void __ttsd_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+ if (NULL != g_callback)
+ g_callback(TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO, NULL, 0, value);
+ else
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
+}
+
int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
{
if (NULL == config_cb) {
}
ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb,
- __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, NULL);
+ __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, __ttsd_config_bg_volume_ratio_changed_cb, NULL);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set config changed : %d", ret);
return -1;
return 0;
}
+int ttsd_config_get_bg_volume_ratio(double* ratio)
+{
+ if (NULL == ratio)
+ return -1;
+
+ if (0 != tts_config_mgr_get_bg_volume_ratio(ratio)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default bg volume ratio");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
+ return 0;
+}
+
int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
const char* func, int line, const char* message)
{
TTS_CONFIG_TYPE_ENGINE,
TTS_CONFIG_TYPE_VOICE,
TTS_CONFIG_TYPE_SPEED,
- TTS_CONFIG_TYPE_PITCH
+ TTS_CONFIG_TYPE_PITCH,
+ TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO
} tts_config_type_e;
-typedef void (*ttsd_config_changed_cb)(tts_config_type_e type, const char* str_param, int int_param);
+typedef void (*ttsd_config_changed_cb)(tts_config_type_e type, const char* str_param, int int_param, double double_param);
typedef void (*ttsd_config_screen_reader_changed_cb)(bool value);
int ttsd_config_get_default_pitch(int* pitch);
+int ttsd_config_get_bg_volume_ratio(double* ratio);
+
int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
const char* func, int line, const char* message);
static sound_stream_info_h g_stream_info_h;
+static sound_stream_ducking_h g_stream_ducking;
+
+static bool ducking_flag;
+
+#define SND_MGR_DUCKING_DURATION 500
+
static int g_focus_watch_id;
+static double g_bg_volume_ratio;
/*
* Internal Interfaces
return;
}
+void __sound_stream_ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ ducking state changed cb");
+
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] is ducked : %d", is_ducked);
+
+ ducking_flag = true;
+ return;
+}
+
+static void __change_background_volume()
+{
+ int ret = SOUND_MANAGER_ERROR_NONE;
+ bool is_ducked = false;
+ ret = sound_manager_is_ducked(g_stream_ducking, &is_ducked);
+ if (is_ducked) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] The background volume is already ducked");
+ return;
+ }
+
+ ducking_flag = false;
+ ret = sound_manager_activate_ducking(g_stream_ducking, SND_MGR_DUCKING_DURATION, g_bg_volume_ratio);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to activate ducking");
+ return;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] Activate ducking");
+ }
+
+ while (ducking_flag == false) {
+ usleep(10000);
+ SLOG(LOG_DEBUG, tts_tag(), "ducking waiting");
+ }
+}
+
+static void __recover_background_volume()
+{
+ int ret = SOUND_MANAGER_ERROR_NONE;
+ bool is_ducked = false;
+ ret = sound_manager_is_ducked(g_stream_ducking, &is_ducked);
+ if (!is_ducked) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] The background volume is already recovered");
+ return;
+ }
+
+ ret = sound_manager_deactivate_ducking(g_stream_ducking);
+ if (SOUND_MANAGER_ERROR_NONE != ret)
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to deactivate ducking");
+ else
+ SLOG(LOG_WARN, tts_tag(), "[Player] Deactivate ducking");
+}
+
static int __create_audio_out(ttse_audio_type_e type, int rate)
{
int ret = -1;
SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
}
+ __change_background_volume();
+
SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
return;
}
}
+ __recover_background_volume();
+
SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
return;
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Add sound focus watch callback");
}
+ ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_MEDIA, __sound_stream_ducking_state_changed_cb, NULL, &g_stream_ducking);
+ if (SOUND_MANAGER_ERROR_NONE != ret)
+ SLOG(LOG_ERROR, tts_tag(), "[Player WARNING] Fail to create stream ducking");
+ else
+ SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream ducking");
+
ecore_thread_max_set(1);
ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Remove the focus state watch cb");
}
+ ret = sound_manager_destroy_stream_ducking(g_stream_ducking);
+ if (SOUND_MANAGER_ERROR_NONE != ret)
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream ducking");
+ else
+ SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream ducking");
+
/* clear g_player_list */
g_playing_info = NULL;
g_player_init = false;
return 0;
}
+int ttsd_player_get_background_volume_ratio(double* ratio)
+{
+ if (NULL == ratio)
+ return -1;
+ else
+ *ratio = g_bg_volume_ratio;
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_player_set_background_volume_ratio(double ratio)
+{
+ SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] ttsd_player_set_background_volume_ratio : %lf", ratio);
+
+ g_bg_volume_ratio = ratio;
+ return TTSD_ERROR_NONE;
+}
int ttsd_player_check_current_playback_focus(bool *is_current_interrupt);
+int ttsd_player_set_background_volume_ratio(double ratio);
+
#ifdef __cplusplus
}
#endif
return true;
}
-void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param)
+void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
{
switch (type) {
case TTS_CONFIG_TYPE_ENGINE:
}
break;
}
+
+ case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
+ {
+ if (0.0 <= double_param && double_param <= 1.0) {
+ /* set default bg volume ratio */
+ int ret = 0;
+ ret = ttsd_player_set_background_volume_ratio(double_param);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
+ }
+ }
+ break;
+ }
}
return;
SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
}
+ double ratio;
+ if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
+ {
+ SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
+ int ret = ttsd_player_set_background_volume_ratio(ratio);
+ if (0 != ret)
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
+ }
+ else
+ SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
+
/* player init */
if (ttsd_player_init()) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
<voice-type>female</voice-type>
<speech-rate>8</speech-rate>
<pitch>8</pitch>
+ <background-volume-ratio>1.0</background-volume-ratio>
</tts-config>