| Index: chrome/browser/speech/tts_chromeos.cc
|
| diff --git a/chrome/browser/speech/tts_chromeos.cc b/chrome/browser/speech/tts_chromeos.cc
|
| index 7d218e826bf9c086d65e241e5536dd997b740218..a1552f8007d25b5729bc3154111fdbf130ab16eb 100644
|
| --- a/chrome/browser/speech/tts_chromeos.cc
|
| +++ b/chrome/browser/speech/tts_chromeos.cc
|
| @@ -4,16 +4,28 @@
|
|
|
| #include "base/macros.h"
|
| #include "chrome/browser/speech/tts_platform.h"
|
| +#include "components/arc/arc_bridge_service.h"
|
| +#include "components/arc/common/tts.mojom.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +namespace {
|
| +
|
| +// Helper returning an ARC tts instance.
|
| +arc::mojom::TtsInstance* GetArcTts() {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + return arc::ArcBridgeService::Get()
|
| + ? arc::ArcBridgeService::Get()->tts()->instance()
|
| + : nullptr;
|
| +}
|
|
|
| -// Chrome OS doesn't have native TTS, instead it includes a built-in
|
| -// component extension that provides speech synthesis. This class includes
|
| -// an implementation of LoadBuiltInTtsExtension and dummy implementations of
|
| -// everything else.
|
| +} // namespace
|
|
|
| +// This class includes extension-based tts through LoadBuiltInTtsExtension and
|
| +// native tts through ARC.
|
| class TtsPlatformImplChromeOs : public TtsPlatformImpl {
|
| public:
|
| // TtsPlatformImpl overrides:
|
| - bool PlatformImplAvailable() override { return false; }
|
| + bool PlatformImplAvailable() override { return GetArcTts() != nullptr; }
|
|
|
| bool LoadBuiltInTtsExtension(
|
| content::BrowserContext* browser_context) override {
|
| @@ -29,19 +41,42 @@ class TtsPlatformImplChromeOs : public TtsPlatformImpl {
|
| const std::string& lang,
|
| const VoiceData& voice,
|
| const UtteranceContinuousParameters& params) override {
|
| - return false;
|
| + arc::mojom::TtsInstance* tts = GetArcTts();
|
| + if (!tts)
|
| + return false;
|
| +
|
| + arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New();
|
| + arc_utterance->utteranceId = utterance_id;
|
| + arc_utterance->text = utterance;
|
| + arc_utterance->rate = params.rate;
|
| + arc_utterance->pitch = params.pitch;
|
| + tts->Speak(std::move(arc_utterance));
|
| + return true;
|
| }
|
|
|
| - bool StopSpeaking() override { return false; }
|
| + bool StopSpeaking() override {
|
| + arc::mojom::TtsInstance* tts = GetArcTts();
|
| + if (!tts)
|
| + return false;
|
|
|
| - void Pause() override {}
|
| + tts->Stop();
|
| + return true;
|
| + }
|
|
|
| - void Resume() override {}
|
| + void GetVoices(std::vector<VoiceData>* out_voices) override {
|
| + out_voices->push_back(VoiceData());
|
| + VoiceData& voice = out_voices->back();
|
| + voice.native = true;
|
| + voice.name = "Android";
|
| + voice.events.insert(TTS_EVENT_START);
|
| + voice.events.insert(TTS_EVENT_END);
|
| + }
|
|
|
| + // Unimplemented.
|
| + void Pause() override {}
|
| + void Resume() override {}
|
| bool IsSpeaking() override { return false; }
|
|
|
| - void GetVoices(std::vector<VoiceData>* out_voices) override {}
|
| -
|
| // Get the single instance of this class.
|
| static TtsPlatformImplChromeOs* GetInstance();
|
|
|
|
|