[A11y] Set TTSPlayer state to Ready when utterance is completed 47/286247/4 accepted/tizen/6.0/unified/20230105.030117 submit/tizen_6.0/20230104.100637
authorMaria Bialota <m.bialota@samsung.com>
Mon, 2 Jan 2023 18:48:39 +0000 (19:48 +0100)
committerMaria Bialota <m.bialota@samsung.com>
Mon, 2 Jan 2023 19:55:52 +0000 (20:55 +0100)
Change-Id: I0946f121c20eb01035c32e48f95152dba43eb3e9

dali/internal/accessibility/tizen-wayland/tts-player-impl-tizen.cpp
dali/internal/accessibility/tizen-wayland/tts-player-impl-tizen.h

index b18a74e..2e5e19c 100644 (file)
@@ -92,8 +92,13 @@ TtsPlayerTizen::~TtsPlayerTizen()
   // If it is playing, stop it
   Stop();
 
-  // Unset the callback funtion for TTS state change
-  int retVal = tts_unset_state_changed_cb(mTtsHandle);
+  // Unset the callback funtions
+  int retVal = tts_unset_utterance_completed_cb(mTtsHandle);
+  if( retVal != TTS_ERROR_NONE )
+  {
+    LogErrorCode(static_cast<tts_error_e>(retVal));
+  }
+  retVal = tts_unset_state_changed_cb(mTtsHandle);
   if( retVal != TTS_ERROR_NONE )
   {
     LogErrorCode(static_cast<tts_error_e>(retVal));
@@ -118,6 +123,13 @@ void TtsPlayerTizen::Initialize()
   }
   else
   {
+    // Set the callback funtion for utterance completed
+    retVal = tts_set_utterance_completed_cb(mTtsHandle, &UtteranceCompletedCallback, this);
+    if(retVal != TTS_ERROR_NONE)
+    {
+      LogErrorCode(static_cast<tts_error_e>(retVal));
+    }
+
     // Set the callback funtion for TTS state change
     retVal = tts_set_state_changed_cb(mTtsHandle, &StateChangedCallback, this);
     if( retVal != TTS_ERROR_NONE )
@@ -312,6 +324,13 @@ void TtsPlayerTizen::StateChangedCallback(tts_h tts, tts_state_e previous, tts_s
   }
 }
 
+void TtsPlayerTizen::UtteranceCompletedCallback(tts_h tts, int utteranceId, void *userData)
+{
+  TtsPlayerTizen* obj = static_cast<TtsPlayerTizen*>(userData);
+  // We call Stop() and as a result the "state changed" callback will be called by tts
+  obj->Stop();
+}
+
 void TtsPlayerTizen::LogErrorCode(tts_error_e reason)
 {
   std::string error_string;
index 7ae8d18..f7c5209 100644 (file)
@@ -126,6 +126,15 @@ private:
    */
   static void StateChangedCallback(tts_h tts, tts_state_e previous, tts_state_e current, void *userData);
 
+  /**
+   * Called when the utterance read by TTS has been completed.
+   *
+   * @param[in] tts The handle for TTS
+   * @param[in] ID of the completed utterance
+   * @param[in] userData The user data passed from the callback registration function.
+   */
+  static void UtteranceCompletedCallback(tts_h tts, int utteranceId, void *userData);
+
   // Undefined
   TtsPlayerTizen(const TtsPlayerTizen&);