[ACR-1216][tts][Add tts_repeat()] 15/177615/10 accepted/tizen/unified/20180515.063821 submit/tizen/20180515.010831
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 2 May 2018 07:09:54 +0000 (16:09 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Fri, 11 May 2018 05:36:35 +0000 (14:36 +0900)
Change-Id: I3aa4413aa7d047521b888a027b78fcf99699b970
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/tts.c
client/tts_client.c
client/tts_client.h
include/tts.h
include/tts_internal.h
server/ttsd_dbus_server.c

index 64c073e..23cfdb2 100644 (file)
@@ -37,6 +37,14 @@ static bool g_err_callback_status = false;
 
 static int g_max_text_size = -1;
 
+/* for repetition */
+static char* g_language = NULL;
+
+static int g_voice_type = -1;
+
+static int g_speed = -1;
+
+
 /* Function definition */
 static Eina_Bool __tts_notify_state_changed(void *data);
 static Eina_Bool __tts_notify_error(void *data);
@@ -132,6 +140,14 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
                                        language, voice_type, data->default_voice_changed_user_data);
                        }
 
+                       /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
+                       if (0 != strncmp(before_lang, language, strlen(before_lang))) {
+                               if (NULL != data->text_repeat) {
+                                       free(data->text_repeat);
+                                       data->text_repeat = NULL;
+                               }
+                       }
+
                        /* Next item */
                        iter = g_list_next(iter);
                }
@@ -355,6 +371,11 @@ int tts_destroy(tts_h tts)
                }
        }
 
+       if (NULL != g_language) {
+               free(g_language);
+               g_language = NULL;
+       }
+
        tts = NULL;
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
@@ -1135,6 +1156,28 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        }
        SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
 
+       /* save texts for repetition */
+       if (NULL != client->text_repeat) {
+               free(client->text_repeat);
+               client->text_repeat = NULL;
+       }
+
+       client->text_repeat = strdup(text);
+
+       if (NULL != g_language) {
+               free(g_language);
+               g_language = NULL;
+       }
+       if (NULL == language)
+               g_language = NULL;
+       else
+               g_language = strdup(language);
+
+       g_voice_type = voice_type;
+       g_speed = speed;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] repeat: text(%s), language(%s), voice type(%d), speed(%d)", client->text_repeat, g_language, g_voice_type, g_speed);
+
        /* change default language value */
        char* temp = NULL;
 
@@ -2658,3 +2701,96 @@ int tts_stop_pcm(tts_h tts)
 
        return TTS_ERROR_NONE;
 }
+
+int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == text_repeat || NULL == utt_id) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       *text_repeat = NULL;
+       *utt_id = -1;
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", client->current_state);
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       /* Clear the legacy and Add texts to be played repeatedly */
+       int ret = -1;
+       ret = tts_stop(tts);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to clear the legacy");
+               return ret;
+       }
+
+       if (NULL != client->text_repeat) {
+               char* tmp_text = strdup(client->text_repeat);
+               char* tmp_lang = NULL;
+               if (NULL != g_language) {
+                       tmp_lang = strdup(g_language);
+               }
+               ret = tts_add_text(tts, tmp_text, tmp_lang, g_voice_type, g_speed, utt_id);
+               if (TTS_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add texts for repetition.");
+                       if (NULL != tmp_text) {
+                               free(tmp_text);
+                               tmp_text = NULL;
+                       }
+                       if (NULL != tmp_lang) {
+                               free(tmp_lang);
+                               tmp_lang = NULL;
+                       }
+                       return ret;
+               }
+               *text_repeat = strdup(client->text_repeat);
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] text to repeat(%s), utt_id(%d)", *text_repeat, *utt_id);
+               if (NULL != tmp_text) {
+                       free(tmp_text);
+                       tmp_text = NULL;
+               }
+               if (NULL != tmp_lang) {
+                       free(tmp_lang);
+                       tmp_lang = NULL;
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] There is no previous added texts. Please add texts");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       /* Play added texts */
+       ret = tts_play(tts);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play texts for repetition.");
+               if (NULL != *text_repeat) {
+                       free(*text_repeat);
+                       *text_repeat = NULL;
+               }
+               *utt_id = -1;
+               return ret;
+       }
+
+       return TTS_ERROR_NONE;
+}
index 0d9b493..4ce1855 100644 (file)
@@ -87,6 +87,8 @@ int tts_client_new(tts_h* tts)
        client->credential_needed = false;
        client->internal = false;
 
+       client->text_repeat = NULL;
+
        g_client_list = g_list_append(g_client_list, client);
 
        *tts = temp;
@@ -130,6 +132,11 @@ int tts_client_destroy(tts_h tts)
                                        data->credential = NULL;
                                }
 
+                               if (NULL != data->text_repeat) {
+                                       free(data->text_repeat);
+                                       data->text_repeat = NULL;
+                               }
+
                                free(data);
                                free(tts);
 
@@ -282,4 +289,4 @@ int tts_client_get_mode_client_count(tts_mode_e mode)
 GList* tts_client_get_client_list()
 {
        return g_client_list;
-}
\ No newline at end of file
+}
index aac943a..fa5eaae 100644 (file)
@@ -68,6 +68,9 @@ typedef struct {
        char*           credential;
        bool            credential_needed;
        bool            internal;
+
+       /* repeatition */
+       char*           text_repeat;
 } tts_client_s;
 
 int tts_client_new(tts_h* tts);
index 878ef1b..6de4882 100644 (file)
@@ -609,6 +609,30 @@ int tts_stop(tts_h tts);
 */
 int tts_pause(tts_h tts);
 
+/**
+ * @brief Repeats the last played text.
+ * @since_tizen 5.0
+ * @remarks This function repeats the last played text once. If there is no previous text, this function will not work.
+ *          If the language is changed, the last played text is removed.
+ *          Before calling this function, please call 'tts_stop()' in order to stop playing the previous one.
+ *          If this function succeeds, @a text_repeat must be released with free().
+ * @param[in] tts The TTS handle
+ * @param[out] text_repeat Texts to be played repeatedly
+ * @param[out] utt_id The utterance ID passed to the callback function
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
+ * @pre The state should be #TTS_STATE_READY.
+ * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
+ * @see tts_add_text()
+ * @see tts_stop()
+ */
+int tts_repeat(tts_h tts, char** text_repeat, int* utt_id);
 
 /**
  * @brief Registers a callback function to be called when the TTS state changes.
index 12f0a04..88babea 100644 (file)
@@ -144,7 +144,7 @@ int tts_prepare_sync(tts_h tts);
 #endif
 
 /**
  * @}
   */
+ * @}
+ */
 
 #endif /* __TTS_INTERNAL_H__ */
index 4f464f9..e750048 100644 (file)
@@ -309,7 +309,6 @@ int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg)
                dbus_error_free(&err);
                ret = TTSD_ERROR_OPERATION_FAILED;
        } else {
-               
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)", 
                        uid, (NULL == text) ? "NULL" : text, (NULL == lang) ? "NULL" : lang, voicetype, speed, uttid, (NULL == credential) ? "NULL" : credential);
                ret =  ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid, credential);