[M120 Migration][TTS] Fix some tts related issues 62/317262/3
authorfr.fang <fr.fang@samsung.com>
Fri, 6 Sep 2024 17:28:51 +0000 (01:28 +0800)
committerBot Blink <blinkbot@samsung.com>
Mon, 9 Sep 2024 03:15:30 +0000 (03:15 +0000)
1. Fix tts can't work when app's language is undefined

Launch UFC(appid: 111199000333), some utterances can't be readout.

It is because app set an undefined language. Tts can't recognize its
language, so tts fails to request add text.

When receive undefined language, set the current language to default
language.

2. Fix tts_preprae() failed when change voice guide in menu settings

Sometimes, when enable voice guide in menu settings, some apps' tts
(like hulu, Disney+) can't work.

It is because when tts_mode is TTS_MODE_SCREEN_READER, tts_preprae
can fail when voice guide is off.

When change voice guide, call tts_preprae() again. And add check
whether tts_preprae is successful when invoke Speak(), Play(), Pause(),
StopSpeaking().

Related:
https://review.tizen.org/gerrit/292659

Change-Id: I6d831a8838c0a0aaca4b927db739be5f8c06588a
Signed-off-by: fr.fang <fr.fang@samsung.com>
tizen_src/chromium_impl/content/browser/speech/tts_platform_impl_tizen.cc
tizen_src/chromium_impl/content/browser/speech/tts_platform_impl_tizen.h

index dc62ab49fb3eecedcaea1ea3a0791e87c127cc98..d6485919f1166a03cf597fdfdc4a9bb38f24bcec 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "content/browser/speech/tts_platform_impl_tizen.h"
 
+#include <vconf.h>
 #include "base/debug/leak_annotations.h"
 #include "base/functional/bind.h"
 #include "base/logging.h"
@@ -258,13 +259,26 @@ TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
   return TtsPlatformImplTizen::GetInstance();
 }
 
+static void VoiceGuidePropertyChangedCb(keynode_t* keynodeName, void* data) {
+  TtsPlatformImplTizen* obj = static_cast<TtsPlatformImplTizen*>(data);
+  if (!obj) {
+    LOG(ERROR) << "obj is NULL";
+    return;
+  }
+  obj->GetUsableTtsHandle();
+}
+
 TtsPlatformImplTizen::TtsPlatformImplTizen() {
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS,
+                           VoiceGuidePropertyChangedCb, this);
   Initialize();
 }
 
 TtsPlatformImplTizen::~TtsPlatformImplTizen() {
   LOG(INFO) << "TTS: TtsPlatformImplTizen instance [ " << (void*)this
             << " ] destruct";
+  vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS,
+                           VoiceGuidePropertyChangedCb);
   if (!tts_handle_) {
     LOG(INFO) << "TTS: TtsPlatformImplTizen instance [ " << (void*)this
               << " ] destruct, no handle, finished";
@@ -360,9 +374,23 @@ bool TtsPlatformImplTizen::Initialize() {
                << ErrorToString(static_cast<tts_error_e>(ret));
     return false;
   }
+  is_tts_prepared_ = true;
   return true;
 }
 
+tts_h TtsPlatformImplTizen::GetUsableTtsHandle() {
+  if (!is_tts_prepared_) {
+    int ret = tts_prepare(tts_handle_);
+    if (ret != TTS_ERROR_NONE) {
+      LOG(ERROR) << "TTS: Fail to prepare - "
+                 << ErrorToString(static_cast<tts_error_e>(ret));
+      return NULL;
+    }
+  }
+  is_tts_prepared_ = true;
+  return tts_handle_;
+}
+
 void TtsPlatformImplTizen::StoreTtsDefaultVoice() {
   char* language = NULL;
   int voice_type;
@@ -466,6 +494,9 @@ void TtsPlatformImplTizen::Speak(
   utterance_.pitch = params.pitch;
   utterance_.on_speak_finished = std::move(on_speak_finished);
   should_speak_ = true;
+  tts_h tts_handle = GetUsableTtsHandle();
+  if (!tts_handle)
+    return;
 
   // TTS package can be litle slow at times. Always wait for READY state.
   if (!is_initialized_ || is_speaking_) {
@@ -482,7 +513,8 @@ void TtsPlatformImplTizen::SpeakStoredUtterance() {
   LOG(INFO) << "TTS: Speak utterance " << utterance_.utterance_id << " text #"
             << utterance_.utterance;
   std::string current_language = default_language_;
-  if (!utterance_.language.empty())
+  if (!utterance_.language.empty() &&
+      strcmp(utterance_.language.c_str(), "undefined"))
     current_language = ConvertLangString(utterance_.language);
 
   int voiceType = static_cast<int>(default_voice_);
@@ -507,6 +539,10 @@ void TtsPlatformImplTizen::SpeakStoredUtterance() {
 }
 
 bool TtsPlatformImplTizen::StopSpeaking() {
+  tts_h tts_handle = GetUsableTtsHandle();
+  if (!tts_handle)
+    return false;
+
   // TTS package can be litle slow at times.
   if (!is_initialized_ && utterance_pending_) {
     LOG(INFO) << "TTS: not initialized. Ignore pending utterance "
@@ -525,7 +561,7 @@ bool TtsPlatformImplTizen::StopSpeaking() {
   }
 
   LOG(INFO) << "TTS: Stop. ID: " << utterance_.utterance_id;
-  int ret = tts_stop(tts_handle_);
+  int ret = tts_stop(tts_handle);
   if (ret != TTS_ERROR_NONE) {
     LOG(ERROR) << "TTS: Fail to stop. Error - "
                << ErrorToString(static_cast<tts_error_e>(ret)) << " in "
@@ -539,6 +575,10 @@ bool TtsPlatformImplTizen::StopSpeaking() {
 }
 
 bool TtsPlatformImplTizen::Play() {
+  tts_h tts_handle = GetUsableTtsHandle();
+  if (!tts_handle)
+    return false;
+
   tts_state_e current_state = GetTtsState();
   if (current_state == TTS_STATE_PLAYING) {
     LOG(WARNING) << "TTS: Already in play state. ID: "
@@ -553,7 +593,7 @@ bool TtsPlatformImplTizen::Play() {
   }
 
   LOG(INFO) << "TTS: Play. ID: " << utterance_.utterance_id;
-  int ret = tts_play(tts_handle_);
+  int ret = tts_play(tts_handle);
   if (ret != (int)TTS_ERROR_NONE) {
     LOG(ERROR) << "TTS: Fail to play. Error - "
                << ErrorToString(static_cast<tts_error_e>(ret)) << " in "
@@ -568,6 +608,10 @@ bool TtsPlatformImplTizen::Play() {
 }
 
 void TtsPlatformImplTizen::Pause() {
+  tts_h tts_handle = GetUsableTtsHandle();
+  if (!tts_handle)
+    return;
+
   // TTS package can be litle slow at times.
   if (!is_initialized_ && utterance_pending_) {
     LOG(INFO) << "TTS: not initialized. Ignore pending utterance "
@@ -586,7 +630,7 @@ void TtsPlatformImplTizen::Pause() {
   }
 
   LOG(INFO) << "TTS: Pause. ID: " << utterance_.utterance_id;
-  int ret = tts_pause(tts_handle_);
+  int ret = tts_pause(tts_handle);
   if (ret != TTS_ERROR_NONE) {
     LOG(ERROR) << "TTS: Fail to pause - "
                << ErrorToString(static_cast<tts_error_e>(ret)) << " in "
index 26faa8a1aa9a839f7fdc041d9ba277b4e0c23a9e..1b6e85e073375c611c94ab59e43615a9fafa04e1 100644 (file)
@@ -19,6 +19,7 @@ class TtsPlatformImplTizen : public TtsPlatformImpl {
  public:
   void TtsInitialized();
   const std::string& GetUtteranceText() const { return utterance_.language; }
+  tts_h GetUsableTtsHandle();
   int GetUtteranceId() const { return utterance_.utterance_id; }
   int GetPlatformUttId() const { return utterance_.platform_utt_id; }
 
@@ -93,6 +94,7 @@ class TtsPlatformImplTizen : public TtsPlatformImpl {
   // It will be true when tts engine set the variable tts_.
   bool is_initialized_ = false;
   bool is_speaking_ = false;
+  bool is_tts_prepared_ = false;
 
   friend struct base::DefaultSingletonTraits<TtsPlatformImplTizen>;