Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3224)

Unified Diff: chrome/browser/speech/tts_chromeos.cc

Issue 2180263002: Host side implementation of ARC tts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixup namespace. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e9790df8cefceadcd4dff9f2617025f8f3306b83 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.
hidehiko 2016/08/02 03:56:20 nit: s/Arc/ARC/ in comment for consistency.
David Tseng 2016/08/02 16:32:18 Done.
+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();

Powered by Google App Engine
This is Rietveld 408576698