return TTS_ERROR_NONE;
}
+int tts_add_silent_utterance(tts_h tts, unsigned int duration_in_msec, int* utt_id)
+{
+ RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+ tts_client_s* client = tts_client_get(tts);
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
+ RETVM_IF(NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null.");
+
+ tts_state_e current_state = tts_client_get_current_state(client);
+ RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
+
+ RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
+ RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
+
+ if (duration_in_msec < 0) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add silent. The duration of silent should be above than zero.");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (duration_in_msec > MAX_SILENT_DURATION) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add silent. The max duration for silent is 5000 msec");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = tts_core_add_silent_utterance(client, duration_in_msec, utt_id);
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add silent. ret(%s)", tts_core_covert_error_code(ret));
+ return ret;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_NONE;
+}
+
int tts_synthesis_parameter_create(tts_synthesis_parameter_h *parameter)
{
SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS synthesis parameter handle");
RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
- free(parameter->langauge);
- parameter->langauge = NULL;
+ free(parameter->language);
+ parameter->language = NULL;
free(parameter->ptts_id);
parameter->ptts_id = NULL;
RETVM_IF(NULL == parameter || NULL == language, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
- char *new_langauge = strdup(language);
- RETVM_IF(NULL == new_langauge, TTS_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for language");
+ char *new_language = strdup(language);
+ RETVM_IF(NULL == new_language, TTS_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for language");
- free(parameter->langauge);
- parameter->langauge = new_langauge;
+ free(parameter->language);
+ parameter->language = new_language;
SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set language(%s) to a synthesis parameter", language);
return TTS_ERROR_NONE;
return TTS_ERROR_NONE;
}
-int tts_add_silent_utterance(tts_h tts, unsigned int duration_in_msec, int* utt_id)
+int tts_get_pitch_range(tts_h tts, int* min, int* normal, int* max)
{
RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get pitch range");
+
+ RETVM_IF(NULL == min || NULL == normal || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
+
+ tts_client_s* client = tts_client_get(tts);
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
+
+ *min = 0;
+ *normal = 0;
+ *max = 0;
+
+ return TTS_ERROR_NONE;
+}
+
+int tts_get_volume_range(tts_h tts, int* min, int* max)
+{
+ RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get volume range");
+
+ RETVM_IF(NULL == min || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
+
+ tts_client_s* client = tts_client_get(tts);
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
+
+ *min = 0;
+ *max = 0;
+
+ return TTS_ERROR_NONE;
+}
+
+int tts_add_text_with_synthesis_parameter(tts_h tts, const char* text, tts_synthesis_parameter_h parameter, int* utt_id)
+{
+ RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+ SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Add text with synthesis parameter: text(%s), language(%s), ptts_id(%s), type(%d), speed(%d), pitch(%d), volume(%lf), background_volume(%lf)",
+ (NULL == text) ? "NULL" : text, (NULL == parameter->language) ? "NULL" : parameter->language, (NULL == parameter->ptts_id) ? "NULL" : parameter->ptts_id, parameter->voice_type, parameter->speed, parameter->pitch, parameter->volume, parameter->background_volume_ratio);
+
+ RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
+ RETVM_IF(NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
+ RETVM_IF(false == tts_core_is_valid_text(text), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input text is invalid");
+
tts_client_s* client = tts_client_get(tts);
RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
- RETVM_IF(NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null.");
tts_state_e current_state = tts_client_get_current_state(client);
RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
- if (duration_in_msec < 0) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add silent. The duration of silent should be above than zero.");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- if (duration_in_msec > MAX_SILENT_DURATION) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add silent. The max duration for silent is 5000 msec");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- int ret = tts_core_add_silent_utterance(client, duration_in_msec, utt_id);
+ int ret = tts_core_add_text_with_synthesis_parameter(client, text, parameter, utt_id);
if (TTS_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add silent. ret(%s)", tts_core_covert_error_code(ret));
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add text. ret(%s)", tts_core_covert_error_code(ret));
return ret;
}
return TTS_ERROR_NONE;
}
+static inline int __request_add_text_with_synthesis_parameter(tts_client_s* client, const char* text, tts_synthesis_parameter_h parameter, int* utt_id)
+{
+ int new_utt_id = tts_client_new_utterance_id(client);
+ if (0 > new_utt_id) {
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ // TODO: If use cpp, remove dupliceated code using command class pattern
+ unsigned int uid = tts_client_get_uid(client);
+ int ret = -1;
+ tts_client_set_reprepared(client, false);
+ for (int count = 0; count < TTS_RETRY_COUNT; count++) {
+ ret = tts_ipc_request_add_text_with_synthesis_parameter(uid, text, parameter, new_utt_id, client->credential);
+ if (false == __is_ipc_retry_needed(client, ret)) {
+ break;
+ }
+ }
+
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+ return ret;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success __request_add_text_with_synthesis_parameter");
+ *utt_id = new_utt_id;
+ return TTS_ERROR_NONE;
+}
+
static inline int __request_play(tts_client_s* client)
{
unsigned int uid = tts_client_get_uid(client);
return __request_add_text(client, text, language, voice_type, speed, utt_id);
}
+int tts_core_add_text_with_synthesis_parameter(tts_client_s* client, const char* text, tts_synthesis_parameter_h parameter, int* utt_id)
+{
+ RETVM_IF(NULL == text || NULL == parameter || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid.");
+ RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ reprepare_on_demand(client);
+
+ SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] text(%s), language(%s)", text, (parameter->language) ? parameter->language : "NULL");
+ return __request_add_text_with_synthesis_parameter(client, text, parameter, utt_id);
+}
+
int tts_core_play(tts_client_s* client)
{
RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
// called by tts_ipc
int tts_core_add_text(tts_client_s* client, const char* text, const char* language, int voice_type, int speed, int* utt_id);
int tts_core_add_silent_utterance(tts_client_s* client, unsigned int duration_in_msec, int* utt_id);
+int tts_core_add_text_with_synthesis_parameter(tts_client_s* client, const char* text, tts_synthesis_parameter_h parameter, int* utt_id);
int tts_core_play(tts_client_s* client);
int tts_core_stop(tts_client_s* client);
int tts_core_pause(tts_client_s* client);
return result;
}
+int tts_dbus_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential)
+{
+ if (NULL == text || NULL == parameter) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ DBusMessage* msg = __tts_dbus_make_message(uid, TTS_METHOD_ADD_TEXT_WITH_SYNTHESIS_PARAMETER);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text with systhesis parameter : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : uid(%u), text(%s), lang(%s), id(%d), credential(%s)",
+ uid, text, parameter->language, uttid, (NULL == credential) ? "NULL" : credential);
+ }
+
+ char *temp = NULL;
+ if (NULL == credential) {
+ temp = strdup("NULL");
+ } else {
+ temp = strdup(credential);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_STRUCT, ¶meter,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_STRING, &temp,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ int result = __send_message_and_get_result(msg, TTS_METHOD_ADD_TEXT_WITH_SYNTHESIS_PARAMETER);
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
+ return result;
+}
int tts_dbus_request_set_private_data(unsigned int uid, const char* key, const char* data)
{
int tts_dbus_request_add_silent_utterance(unsigned int uid, unsigned int duration_in_msec, int uttid, const char* credential);
+int tts_dbus_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential);
+
int tts_dbus_request_play(unsigned int uid, const char* credential);
int tts_dbus_request_stop(unsigned int uid);
REQUEST_FINALIZE,
REQUEST_ADD_TEXT,
REQUEST_ADD_SILENT_UTTERANCE,
+ REQUEST_ADD_TEXT_WITH_SYNTHESIS_PARAMETER,
REQUEST_PLAY,
REQUEST_STOP,
REQUEST_PAUSE,
static int(*ttsc_dbus_vtable[])() = { &tts_dbus_open_connection, &tts_dbus_close_connection, &tts_dbus_stop_listening,
&tts_dbus_request_hello, &tts_dbus_request_hello_sync, &tts_dbus_request_initialize,
- &tts_dbus_request_finalize, &tts_dbus_request_add_text, &tts_dbus_request_add_silent_utterance, &tts_dbus_request_play, &tts_dbus_request_stop,
+ &tts_dbus_request_finalize, &tts_dbus_request_add_text, &tts_dbus_request_add_silent_utterance, &tts_dbus_request_add_text_with_synthesis_parameter, &tts_dbus_request_play, &tts_dbus_request_stop,
&tts_dbus_request_pause, &tts_dbus_request_set_private_data, &tts_dbus_request_get_private_data,
&tts_dbus_request_play_pcm, &tts_dbus_request_stop_pcm, &tts_dbus_request_add_pcm,
&tts_dbus_request_get_service_state };
static int(*ttsc_tidl_vtable[])() = { &tts_tidl_open_connection, &tts_tidl_close_connection, &tts_tidl_stop_listening,
&tts_tidl_request_hello, &tts_tidl_request_hello_sync, &tts_tidl_request_initialize,
- &tts_tidl_request_finalize, &tts_tidl_request_add_text, &tts_tidl_request_add_silent_utterance, &tts_tidl_request_play, &tts_tidl_request_stop,
+ &tts_tidl_request_finalize, &tts_tidl_request_add_text, &tts_tidl_request_add_silent_utterance, &tts_tidl_request_add_text_with_synthesis_parameter, &tts_tidl_request_play, &tts_tidl_request_stop,
&tts_tidl_request_pause, &tts_tidl_request_set_private_data, &tts_tidl_request_get_private_data,
&tts_tidl_request_play_pcm, &tts_tidl_request_stop_pcm, &tts_tidl_request_add_pcm,
&tts_tidl_request_get_service_state };
return g_vtable[REQUEST_ADD_SILENT_UTTERANCE](uid, duration_in_msec, uttid, credential);
}
+int tts_ipc_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential)
+{
+ SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_add_text_with_synthesis_parameter");
+
+ RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
+ RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
+
+ return g_vtable[REQUEST_ADD_TEXT_WITH_SYNTHESIS_PARAMETER](uid, text, parameter, uttid, credential);
+}
+
int tts_ipc_request_set_private_data(unsigned int uid, const char* key, const char* data)
{
SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_set_private_data");
int tts_ipc_request_add_silent_utterance(unsigned int uid, unsigned int duration_in_msec, int uttid, const char* credential);
+int tts_ipc_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential);
+
int tts_ipc_request_play(unsigned int uid, const char* credential);
int tts_ipc_request_stop(unsigned int uid);
* @brief A structure of handle for synthesis paramter
*/
struct tts_synthesis_parameter_s {
- char *langauge;
+ char *language;
char *ptts_id;
int voice_type;
int speed;
return TTS_ERROR_NONE;
}
+int tts_tidl_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential)
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_add_text_with_synthesis_parameter");
+
+ tts_client_s* client = tts_client_get_by_uid(uid);
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
+
+ tts_tidl_info_s* info = __get_tidl_info_s(uid);
+ RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
+
+ RETVM_IF(NULL == text || NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
+
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
+
+ const char *not_null_credential = NULL == credential ? "NULL" : credential;
+ int ret = rpc_port_proxy_tts_invoke_add_text_with_synthesis_parameter(info->rpc_h, uid, text, parameter->language, parameter->ptts_id, parameter->voice_type, parameter->speed, parameter->pitch, parameter->volume, parameter->background_volume_ratio, uttid, not_null_credential);
+ int exception = get_last_result();
+ if (RPC_PORT_ERROR_NONE != exception) {
+ ret = __convert_and_handle_tidl_error(exception, info);
+ }
+
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request add text with synthesis parameter : Fail to invoke message");
+ return ret;
+ }
+
+ return TTS_ERROR_NONE;
+}
+
int tts_tidl_request_set_private_data(unsigned int uid, const char* key, const char* data)
{
SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_set_private_data");
int tts_tidl_request_add_silent_utterance(unsigned int uid, unsigned int duration_in_msec, int uttid, const char* credential);
+int tts_tidl_request_add_text_with_synthesis_parameter(unsigned int uid, const char* text, tts_synthesis_parameter_h parameter, int uttid, const char* credential);
+
int tts_tidl_request_play(unsigned int uid, const char* credential);
int tts_tidl_request_stop(unsigned int uid);
#define TTS_METHOD_GET_CURRENT_VOICE "tts_method_get_current_voice"
#define TTS_METHOD_ADD_TEXT "tts_method_add_text"
#define TTS_METHOD_ADD_SILENT_UTTERANCE "tts_method_add_silent_utterance"
+#define TTS_METHOD_ADD_TEXT_WITH_SYNTHESIS_PARAMETER "tts_method_add_text_with_systhesis_parameter"
#define TTS_METHOD_PLAY "tts_method_play"
#define TTS_METHOD_STOP "tts_method_stop"
#define TTS_METHOD_PAUSE "tts_method_pause"
+struct tts_synthesis_parameter_s {
+ string langauge;
+ string ptts_id;
+ int voice_type;
+ int speed;
+ int pitch;
+ double volume;
+ double background_volume;
+}
+
interface tts {
void notify_cb(int pid, int uid, bundle msg) delegate;
void register_cb(int pid, int uid, int mode, int playing_mode, int registered_event_mask, notify_cb callback) async;
int finalize(in int uid);
int add_text(int uid, string text, string lang, int vctype, int speed, int uttid, string credential);
int add_silent_utterance(int uid, int duration_in_msec, int uttid, string credential);
+ int add_text_with_synthesis_parameter(int uid, string text, in string langauge, in string ptts_id, in int voice_type, in int speed, in int pitch, in double volume, in double background_volume, int uttid, string credential);
int stop(in int uid);
int pause(in int uid);
int play_pcm(in int uid);