Commit 055bbadc authored by Ryan Daum's avatar Ryan Daum Committed by Commit Bot

[chromecast] Cleans ups in cast TTS

Cleans up some more remnants from our fork of TtsController/Platform
from Chrome.

  - Remove VoicesChangedDelegate support, as we don't use this or need
    it.
  - Remove 'copied from chrome' comment as we are pretty thoroughly
    forked now.
  - Remove more code related to the tts_extension pieces we don't
    support
  - Remove a chromeos only test that was never compiled anyways.

Bug: none
Test: unit test and manual
Change-Id: I410603b58dac41772442af31597be7dda78be898
Reviewed-on: https://chromium-review.googlesource.com/1181174Reviewed-by: default avatarAlex Sakhartchouk <alexst@chromium.org>
Commit-Queue: Ryan Daum <rdaum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584491}
parent e247d795
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
#ifndef CHROMECAST_BROWSER_TTS_TTS_CONTROLLER_H_
#define CHROMECAST_BROWSER_TTS_TTS_CONTROLLER_H_
......@@ -24,11 +20,11 @@ class TtsPlatformImpl;
namespace base {
class Value;
}
} // namespace base
namespace content {
class BrowserContext;
}
} // namespace content
// Events sent back from the TTS engine indicating the progress.
enum TtsEventType {
......@@ -68,7 +64,7 @@ struct VoiceData {
std::string name;
std::string lang;
TtsGenderType gender;
std::string extension_id;
std::string extension_id; // Not used in cast.
std::set<TtsEventType> events;
// If true, the synthesis engine is a remote network resource.
......@@ -91,14 +87,6 @@ class UtteranceEventDelegate {
const std::string& error_message) = 0;
};
// Class that wants to be notified when the set of
// voices has changed.
class VoicesChangedDelegate {
public:
virtual ~VoicesChangedDelegate() {}
virtual void OnVoicesChanged() = 0;
};
// One speech utterance.
class Utterance {
public:
......@@ -234,9 +222,9 @@ class Utterance {
bool finished_;
};
// Singleton class that manages text-to-speech for the TTS and TTS engine
// extension APIs, maintaining a queue of pending utterances and keeping
// track of all state.
// Singleton class that manages text-to-speech for the TTS extension APIs,
// potentially maintaining a queue of pending utterances and keeping track of
// all state.
class TtsController {
public:
virtual ~TtsController() = default;
......@@ -279,22 +267,6 @@ class TtsController {
virtual void GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) = 0;
// Called by the extension system or platform implementation when the
// list of voices may have changed and should be re-queried.
virtual void VoicesChanged() = 0;
// Add a delegate that wants to be notified when the set of voices changes.
virtual void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0;
// Remove delegate that wants to be notified when the set of voices changes.
virtual void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0;
// Remove delegate that wants to be notified when an utterance fires an event.
// Note: this cancels speech from any utterance with this delegate, and
// removes any utterances with this delegate from the queue.
virtual void RemoveUtteranceEventDelegate(
UtteranceEventDelegate* delegate) = 0;
// For unit testing.
virtual int QueueSize() = 0;
};
......
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
#include "chromecast/browser/tts/tts_controller_impl.h"
#include <stddef.h>
......@@ -171,11 +167,6 @@ void TtsControllerImpl::SpeakOrEnqueue(Utterance* utterance) {
}
void TtsControllerImpl::SpeakNow(Utterance* utterance) {
// Ensure we have all built-in voices loaded. This is a no-op if already
// loaded.
bool loaded_built_in =
GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->browser_context());
// Get all available voices and try to find a matching voice.
std::vector<VoiceData> voices;
GetVoices(utterance->browser_context(), &voices);
......@@ -234,17 +225,8 @@ void TtsControllerImpl::SpeakNow(Utterance* utterance) {
bool success = GetPlatformImpl()->Speak(utterance->id(), utterance->text(),
utterance->lang(), voice,
utterance->continuous_parameters());
if (!success)
current_utterance_ = nullptr;
// If the native voice wasn't able to process this speech, see if
// the browser has built-in TTS that isn't loaded yet.
if (!success && loaded_built_in) {
utterance_queue_.push(utterance);
return;
}
if (!success) {
current_utterance_ = nullptr;
utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex,
GetPlatformImpl()->error());
delete utterance;
......@@ -353,7 +335,6 @@ void TtsControllerImpl::GetVoices(content::BrowserContext* browser_context,
if (platform_impl) {
// Ensure we have all built-in voices loaded. This is a no-op if already
// loaded.
platform_impl->LoadBuiltInTtsExtension(browser_context);
if (platform_impl->PlatformImplAvailable())
platform_impl->GetVoices(out_voices);
}
......@@ -525,51 +506,3 @@ void TtsControllerImpl::UpdateUtteranceDefaults(Utterance* utterance) {
volume = blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume;
utterance->set_continuous_parameters(rate, pitch, volume);
}
void TtsControllerImpl::VoicesChanged() {
// Existence of platform tts indicates explicit requests to tts. Since
// |VoicesChanged| can occur implicitly, only send if needed.
if (!GetPlatformImpl())
return;
for (std::set<VoicesChangedDelegate*>::iterator iter =
voices_changed_delegates_.begin();
iter != voices_changed_delegates_.end(); ++iter) {
(*iter)->OnVoicesChanged();
}
}
void TtsControllerImpl::AddVoicesChangedDelegate(
VoicesChangedDelegate* delegate) {
voices_changed_delegates_.insert(delegate);
}
void TtsControllerImpl::RemoveVoicesChangedDelegate(
VoicesChangedDelegate* delegate) {
voices_changed_delegates_.erase(delegate);
}
void TtsControllerImpl::RemoveUtteranceEventDelegate(
UtteranceEventDelegate* delegate) {
// First clear any pending utterances with this delegate.
base::queue<Utterance*> old_queue = utterance_queue_;
utterance_queue_ = base::queue<Utterance*>();
while (!old_queue.empty()) {
Utterance* utterance = old_queue.front();
old_queue.pop();
if (utterance->event_delegate() != delegate)
utterance_queue_.push(utterance);
else
delete utterance;
}
if (current_utterance_ && current_utterance_->event_delegate() == delegate) {
current_utterance_->set_event_delegate(nullptr);
GetPlatformImpl()->clear_error();
GetPlatformImpl()->StopSpeaking();
FinishCurrentUtterance();
if (!paused_)
SpeakNextUtterance();
}
}
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
#ifndef CHROMECAST_BROWSER_TTS_TTS_CONTROLLER_IMPL_H_
#define CHROMECAST_BROWSER_TTS_TTS_CONTROLLER_IMPL_H_
......@@ -23,7 +19,7 @@
namespace content {
class BrowserContext;
}
} // namespace content
// Singleton class that manages text-to-speech for the TTS and TTS engine
// extension APIs, maintaining a queue of pending utterances and keeping
......@@ -45,10 +41,6 @@ class TtsControllerImpl : public TtsController {
const std::string& error_message) override;
void GetVoices(content::BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) override;
void VoicesChanged() override;
void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) override;
void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) override;
void RemoveUtteranceEventDelegate(UtteranceEventDelegate* delegate) override;
void SetPlatformImpl(std::unique_ptr<TtsPlatformImpl> platform_impl) override;
int QueueSize() override;
......@@ -86,8 +78,6 @@ class TtsControllerImpl : public TtsController {
// pulled from user prefs, and may not be the same as other platforms.
void UpdateUtteranceDefaults(Utterance* utterance);
friend struct base::DefaultSingletonTraits<TtsControllerImpl>;
// The current utterance being spoken.
Utterance* current_utterance_;
......@@ -97,9 +87,6 @@ class TtsControllerImpl : public TtsController {
// A queue of utterances to speak after the current one finishes.
base::queue<Utterance*> utterance_queue_;
// A set of delegates that want to be notified when the voices change.
std::set<VoicesChangedDelegate*> voices_changed_delegates_;
// A pointer to the platform implementation of text-to-speech.
std::unique_ptr<TtsPlatformImpl> platform_impl_;
......
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
// Unit tests for the TTS Controller.
#include "base/values.h"
......@@ -16,6 +12,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
namespace chromecast {
class TtsControllerTest : public testing::Test {};
// Platform Tts implementation that does nothing.
......@@ -155,41 +153,4 @@ TEST_F(TtsControllerTest, TestGetMatchingVoice) {
}
}
#if defined(OS_CHROMEOS)
TEST_F(TtsControllerTest, TestTtsControllerUtteranceDefaults) {
std::unique_ptr<TestableTtsController> controller =
std::make_unique<TestableTtsController>();
std::unique_ptr<Utterance> utterance1 = std::make_unique<Utterance>(nullptr);
// Initialized to default (unset constant) values.
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().rate);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().pitch);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().volume);
controller->UpdateUtteranceDefaults(utterance1.get());
// Updated to global defaults.
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechRate,
utterance1->continuous_parameters().rate);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechPitch,
utterance1->continuous_parameters().pitch);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume,
utterance1->continuous_parameters().volume);
// Now we will set prefs and expect those to be used as defaults.
TestingPrefServiceSimple pref_service_;
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechRate, 1.5);
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechPitch, 2.0);
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechVolume, 0.5);
controller->pref_service_for_testing_ = &pref_service_;
std::unique_ptr<Utterance> utterance2 = std::make_unique<Utterance>(nullptr);
controller->UpdateUtteranceDefaults(utterance2.get());
// Updated to pref values.
EXPECT_EQ(1.5f, utterance2->continuous_parameters().rate);
EXPECT_EQ(2.0f, utterance2->continuous_parameters().pitch);
EXPECT_EQ(0.5f, utterance2->continuous_parameters().volume);
}
#endif // defined(OS_CHROMEOS)
} // namespace chromecast
......@@ -2,19 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
#include "chromecast/browser/tts/tts_platform.h"
#include <string>
bool TtsPlatformImpl::LoadBuiltInTtsExtension(
content::BrowserContext* browser_context) {
return false;
}
std::string TtsPlatformImpl::error() {
return error_;
}
......
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// PLEASE NOTE: this is a copy with modifications from chrome/browser/speech.
// It is temporary until a refactoring to move the chrome TTS implementation up
// into components and extensions/components can be completed.
#ifndef CHROMECAST_BROWSER_TTS_TTS_PLATFORM_H_
#define CHROMECAST_BROWSER_TTS_TTS_PLATFORM_H_
......@@ -30,14 +26,6 @@ class TtsPlatformImpl {
// Returns true if this platform implementation is supported and available.
virtual bool PlatformImplAvailable() = 0;
// Some platforms may provide a built-in TTS extension. Returns true
// if the extension was not previously loaded and is now loading, and
// false if it's already loaded or if there's no extension to load.
// Will call TtsController::RetrySpeakingQueuedUtterances when
// the extension finishes loading.
virtual bool LoadBuiltInTtsExtension(
content::BrowserContext* browser_context);
// Speak the given utterance with the given parameters if possible,
// and return true on success. Utterance will always be nonempty.
// If rate, pitch, or volume are -1.0, they will be ignored.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment