return TTS_ERROR_NONE;
}
+int tts_core_notify_synthesized_pcm(tts_client_s* client, int utt_id, tts_synthesized_pcm_event_e event, const char* pcm_data, int pcm_data_size, tts_audio_type_e audio_type, int sample_rate)
+{
+ RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+ RETVM_IF(NULL == pcm_data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] pcm_data is NULL.");
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "Synthesized pcm data : utt_id(%d), pcm_data_size(%d)", utt_id, pcm_data_size);
+
+ tts_synthesized_pcm_cb callback = tts_client_get_synthesized_pcm_cb(client);
+ void* user_data = tts_client_get_synthesized_pcm_user_data(client);
+
+ if (NULL != callback) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "Notify synthesized pcm comes");
+ tts_client_use_callback(client);
+ callback(tts_client_get_handle(client), utt_id, event, pcm_data, pcm_data_size, audio_type, sample_rate, user_data);
+ tts_client_not_use_callback(client);
+ } else {
+ SLOG(LOG_WARN, TAG_TTSC, "No registered callback(synthesized_pcm)");
+ }
+
+ return TTS_ERROR_NONE;
+}
+
bool tts_core_is_valid_text(const char* text)
{
if (NULL == text) {
#ifndef __TTS_CORE_H_
#define __TTS_CORE_H_
+#include "tts_client.h"
+#include "tts_internal.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#include "tts_client.h"
-
// common function
int tts_core_notify_state_changed(tts_client_s* client, tts_state_e current_state);
int tts_core_notify_utt_started(tts_client_s* client, int utt_id);
int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, const char* language, int voice_type, bool need_credential);
int tts_core_notify_screen_reader_changed(tts_client_s* client, bool value);
int tts_core_notify_service_state_changed(tts_client_s* client, tts_service_state_e before_state, tts_service_state_e current_state);
+int tts_core_notify_synthesized_pcm(tts_client_s* client, int utt_id, tts_synthesized_pcm_event_e event, const char* pcm_data, int pcm_data_size, tts_audio_type_e audio_type, int sample_rate);
bool tts_core_is_valid_text(const char* text);
bool tts_core_check_screen_reader(tts_client_s* client);
}
} /* TTSD_METHOD_SET_SERVICE_STATE */
+ else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_SEND_PCM)) {
+ unsigned int uid = 0;
+ int uttid = -1;
+ int event = -1;
+ char* pcm_data = NULL;
+ int pcm_data_size = -1;
+ int audio_type = -1;
+ int sample_rate = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pcm_data, &pcm_data_size,
+ DBUS_TYPE_INT32, &audio_type,
+ DBUS_TYPE_INT32, &sample_rate,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (0 == tts_core_notify_synthesized_pcm(tts_client_get_by_uid(uid), uttid, event, pcm_data, pcm_data_size, audio_type, sample_rate)) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts send pcm : uid(%u) uttid(%d) event(%d) pcm_data_size(%d) audio_type(%d) sample_rate(%d)", uid, uttid, event, pcm_data_size, audio_type, sample_rate);
+ }
+ }
+
else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_ERROR)) {
unsigned int uid;
int uttid;
if (before_state && current_state) {
tts_core_notify_service_state_changed(client, (tts_service_state_e)atoi(before_state), (tts_service_state_e)atoi(current_state));
}
+ } else if (0 == strncmp(TTSD_METHOD_SEND_PCM, method, strlen(TTSD_METHOD_SEND_PCM))) {
+ char* uttid = NULL;
+ char* event = NULL;
+ void* pcm_data = NULL;
+ size_t pcm_data_size = 0;
+ char* audio_type = NULL;
+ char* sample_rate = NULL;
+
+ bundle_get_str(msg, TTS_BUNDLE_UTTID, &uttid);
+ bundle_get_str(msg, TTS_BUNDLE_PCM_EVENT, &event);
+ bundle_get_byte(msg, TTS_BUNDLE_PCM_DATA, (void**)&pcm_data, &pcm_data_size);
+ bundle_get_str(msg, TTS_BUNDLE_PCM_AUDIO_TYPE, &audio_type);
+ bundle_get_str(msg, TTS_BUNDLE_PCM_SAMPLE_RATE, &sample_rate);
+ SLOG(LOG_DEBUG, TAG_TTSC, "uttid(%s) event(%s) pcm_data(%p) pcm_data_size(%d) audio_type(%s) sample_rate(%s)", uttid, event, pcm_data, (int)pcm_data_size, audio_type, sample_rate);
+ if (uttid && ((pcm_data && pcm_data_size > 0) || TTS_SYNTHESIZED_PCM_EVENT_FINISH == atoi(event))) {
+ tts_core_notify_synthesized_pcm(client, atoi(uttid), atoi(event), (const char*)pcm_data, (int)pcm_data_size, atoi(audio_type), atoi(sample_rate));
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get message(TTSD_METHOD_SEND_PCM). pid(%d) uid(%u)", pid, u_uid);
+ }
} else if (0 == strncmp(TTSD_METHOD_ERROR, method, strlen(TTSD_METHOD_ERROR))) {
char *uttid = NULL;
char *reason = NULL;
#define TTS_BUNDLE_CREDENTIAL_NEEDED "credential_needed"
#define TTS_BUNDLE_BEFORE_STATE "before_state"
#define TTS_BUNDLE_CURRENT_STATE "current_state"
+#define TTS_BUNDLE_PCM_EVENT "pcm_event"
+#define TTS_BUNDLE_PCM_DATA "pcm_data"
+#define TTS_BUNDLE_PCM_AUDIO_TYPE "pcm_audio_type"
+#define TTS_BUNDLE_PCM_SAMPLE_RATE "pcm_sample_rate"
#define TTS_METHOD_HELLO "tts_method_hello"
#define TTS_METHOD_HELLO_SYNC "tts_method_hello_sync"
#define TTSD_METHOD_ERROR "ttsd_method_error"
#define TTSD_METHOD_SET_STATE "ttsd_method_set_state"
#define TTSD_METHOD_SET_SERVICE_STATE "ttsd_method_set_service_state"
+#define TTSD_METHOD_SEND_PCM "ttsd_method_send_pcm"
/******************************************************************************************
/**
+ * @brief Enumration for audio type.
+ * @since_tizen 8.0
+ */
+typedef enum {
+ TTS_AUDIO_TYPE_RAW_S16 = 0, /**< Signed 16-bit audio type */
+ TTS_AUDIO_TYPE_RAW_U8 /**< Unsigned 8-bit audio type */
+} tts_audio_type_e;
+
+
+/**
* @brief Enumeration for synthesized pcm event.
* @since_tizen 8.0
*/
typedef enum {
- TTS_SYNTHESIZED_PCM_EVENT_FAIL = -1, /**< 'Error' event */
- TTS_SYNTHESIZED_PCM_EVENT_START, /**< 'Started' event */
- TTS_SYNTHESIZED_PCM_EVENT_CONTINUE, /**< 'Finished' event */
- TTS_SYNTHESIZED_PCM_EVENT_FINISH, /**< 'Finished' event */
+ TTS_SYNTHESIZED_PCM_EVENT_FAIL = -1, /**< Event when the synthesized PCM is failed */
+ TTS_SYNTHESIZED_PCM_EVENT_START = 1, /**< Event when the synthesized PCM is received at first */
+ TTS_SYNTHESIZED_PCM_EVENT_CONTINUE = 2, /**< Event when the synthesized PCM is received, not first and not last */
+ TTS_SYNTHESIZED_PCM_EVENT_FINISH = 3 /**< Event when the synthesized PCM is received finally */
} tts_synthesized_pcm_event_e;
* @since_tizen 8.0
* @remarks The @a tts handle should not be destroyed in the callback.
* @param[in] tts The TTS handle, the same handle for which the callback was set.
+ * @param[in] utt_id The utterance ID
* @param[in] event The event type
- * @param[in] buffer The synthesized pcm data
- * @param[in] buffer_size The size of the buffer
+ * @param[in] pcm_data The synthesized pcm data
+ * @param[in] pcm_data_size The size of the pcm data
+ * @param[in] audio_type The audio type of pcm data
+ * @param[in] sample_rate The sampling rate of pcm data
* @param[in] user_data The user data passed from the callback registration function
* @pre An application registers this callback using tts_set_synthesized_pcm_cb() to get pcm data.
* @see tts_set_synthesized_pcm_cb()
* @see tts_unset_synthesized_pcm_cb()
*/
-typedef void (*tts_synthesized_pcm_cb)(tts_h tts, tts_synthesized_pcm_event_e event, char* buffer, int buffer_size, void *user_data);
+typedef void (*tts_synthesized_pcm_cb)(tts_h tts, int utt_id, tts_synthesized_pcm_event_e event, const char* pcm_data, int pcm_data_size, tts_audio_type_e audio_type, int sample_rate, void *user_data);
/**
return app_data->mode;
}
+ttsd_playing_mode_e ttsd_data_get_playing_mode(unsigned int uid)
+{
+ lock_guard<mutex> lock(g_app_data_mutex);
+ app_data_s* app_data = get_client_app_data(uid);
+ if (nullptr == app_data) {
+ SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
+ return TTSD_PLAYING_MODE_BY_SERVICE;
+ }
+
+ return app_data->playing_mode;
+}
+
int ttsd_data_set_credential(unsigned int uid, const char* credential)
{
lock_guard<mutex> lock(g_app_data_mutex);
ttsd_mode_e ttsd_data_get_mode(unsigned int uid);
+ttsd_playing_mode_e ttsd_data_get_playing_mode(unsigned int uid);
+
int ttsd_data_set_credential(unsigned int uid, const char* credential);
char* ttsd_data_get_credential(unsigned int uid);
return TTSD_ERROR_NONE;
}
+int ttsdc_dbus_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate)
+{
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
+ return -1;
+ }
+
+ DBusMessage* msg = NULL;
+
+ char target_if_name[64];
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
+
+ /* create a message */
+ msg = dbus_message_new_signal(
+ TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ TTSD_METHOD_SEND_PCM); /* name of the signal */
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create error message : uid(%u)", uid);
+ return -1;
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pcm_data, pcm_data_size,
+ DBUS_TYPE_INT32, &audio_type,
+ DBUS_TYPE_INT32, &sample_rate,
+ DBUS_TYPE_INVALID);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
+ return TTSD_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
int ttsdc_dbus_send_error_message(int pid, unsigned int uid, int uttid, int reason, char* err_msg)
{
if (NULL == g_conn_sender) {
#ifndef __TTSD_DBUS_h__
#define __TTSD_DBUS_h__
+#include "ttsd_main.h"
+
#ifdef __cplusplus
extern "C" {
#endif
int ttsdc_dbus_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+int ttsdc_dbus_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate);
+
#ifdef __cplusplus
}
static int(*ttsd_dbus_vtable[])() = {&ttsd_dbus_open_connection, &ttsd_dbus_close_connection, &ttsdc_dbus_send_utt_start_message,
&ttsdc_dbus_send_utt_finish_message, &ttsdc_dbus_send_set_state_message, &ttsdc_dbus_send_error_message,
- &ttsdc_dbus_send_set_service_state_message};
+ &ttsdc_dbus_send_set_service_state_message, &ttsdc_dbus_send_pcm};
static int(*ttsd_tidl_vtable[])() = {&ttsd_tidl_open_connection, &ttsd_tidl_close_connection, &ttsdc_tidl_send_utt_start_message,
&ttsdc_tidl_send_utt_finish_message, &ttsdc_tidl_send_set_state_message, &ttsdc_tidl_send_error_message,
- &ttsdc_tidl_send_set_service_state_message};
+ &ttsdc_tidl_send_set_service_state_message, &ttsdc_tidl_send_pcm};
int ttsd_ipc_open_connection()
{
return TTSD_ERROR_OPERATION_FAILED;
}
+
+int ttsdc_ipc_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate)
+{
+ SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_pcm");
+
+ if (0 > ttsd_data_is_client(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%u)", uid);
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (ttsd_data_get_ipc_method(uid))
+ {
+ case TTS_IPC_METHOD_DBUS:
+ SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus");
+ return ttsd_dbus_vtable[SEND_PCM](pid, uid, uttid, event, pcm_data, pcm_data_size, audio_type, sample_rate);
+
+ case TTS_IPC_METHOD_TIDL:
+ SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl");
+ return ttsd_tidl_vtable[SEND_PCM](pid, uid, uttid, event, pcm_data, pcm_data_size, audio_type, sample_rate);
+
+ default:
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid");
+ }
+
+ return TTSD_ERROR_OPERATION_FAILED;
+}
\ No newline at end of file
SEND_UTTERANCE_FINISH,
SEND_SET_STATE,
SEND_ERROR,
- SEND_SET_SERVICE_STATE
+ SEND_SET_SERVICE_STATE,
+ SEND_PCM
} ttsd_ipc_vtable_e;
int ttsd_ipc_open_connection();
int ttsdc_ipc_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+int ttsdc_ipc_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate);
#ifdef __cplusplus
}
g_total_data_size += data_size;
}
- /* add wav data */
- sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
- if (NULL == sound_data) {
- SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
- return TTSD_ERROR_OUT_OF_MEMORY;
- }
+ ttsd_playing_mode_e playing_mode = ttsd_data_get_playing_mode(uid);
+ SLOG(LOG_DEBUG, tts_tag(), "[SERVER] uid(%d), playing mode(%d)", uid, playing_mode);
+ if (TTSD_PLAYING_MODE_BY_SERVICE == playing_mode) {
+ /* add wav data */
+ sound_data_s* sound_data = ttsd_data_create_sound_data(uttid, data, data_size, event, audio_type, rate, 0);
+ if (NULL == sound_data) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
- if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
- SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
- ttsd_data_destroy_sound_data(sound_data);
+ if (0 != ttsd_data_add_sound_data(uid, sound_data)) {
+ SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%u)", uid);
+ ttsd_data_destroy_sound_data(sound_data);
- return TTSD_ERROR_OPERATION_FAILED;
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+ } else { /* TTSD_PLAYING_MODE_BY_CLIENT */
+ /* send pcm data to client */
+ int tmp_pid = ttsd_data_get_pid(uid);
+ if (0 != ttsdc_ipc_send_pcm(tmp_pid, uid, uttid, event, data, data_size, audio_type, rate)) {
+ SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to send pcm data to client");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
}
if (event == TTSE_RESULT_EVENT_FINISH) {
bundle_free(msg);
return TTSD_ERROR_NONE;
}
+
+int ttsdc_tidl_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "[TIDL] ttsdc_tidl_send_pcm");
+
+ char tmp_uttid[10] = {0, };
+ char tmp_event[10] = {0, };
+ char tmp_audio_type[10] = {0, };
+ char tmp_sample_rate[10] = {0, };
+
+ bundle* msg = bundle_create();
+ snprintf(tmp_uttid, 10, "%d", uttid);
+ snprintf(tmp_event, 10, "%d", event);
+ snprintf(tmp_audio_type, 10, "%d", audio_type);
+ snprintf(tmp_sample_rate, 10, "%d", sample_rate);
+ bundle_add_str(msg, TTS_BUNDLE_METHOD, TTSD_METHOD_SEND_PCM);
+ bundle_add_str(msg, TTS_BUNDLE_UTTID, tmp_uttid);
+ bundle_add_str(msg, TTS_BUNDLE_PCM_EVENT, tmp_event);
+ bundle_add_byte(msg, TTS_BUNDLE_PCM_DATA, pcm_data, (const size_t)pcm_data_size);
+ bundle_add_str(msg, TTS_BUNDLE_PCM_AUDIO_TYPE, tmp_audio_type);
+ bundle_add_str(msg, TTS_BUNDLE_PCM_SAMPLE_RATE, tmp_sample_rate);
+
+ SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTSD SEND PCM MSG");
+ __send_msg(pid, uid, msg);
+
+ bundle_free(msg);
+ return TTSD_ERROR_NONE;
+}
int ttsdc_tidl_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+int ttsdc_tidl_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate);
+
#ifdef __cplusplus
}
#endif