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

Side by Side 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: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/arc/BUILD.gn » ('j') | components/arc/BUILD.gn » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/speech/tts_platform.h" 6 #include "chrome/browser/speech/tts_platform.h"
7 #include "components/arc/arc_bridge_service.h"
8 #include "components/arc/common/tts.mojom.h"
7 9
8 // Chrome OS doesn't have native TTS, instead it includes a built-in 10 namespace {
9 // component extension that provides speech synthesis. This class includes
10 // an implementation of LoadBuiltInTtsExtension and dummy implementations of
11 // everything else.
12 11
12 // Helper returning an Arc tts instance.
13 arc::mojom::TtsInstance* GetArcTts() {
14 return arc::ArcBridgeService::Get()
15 ? arc::ArcBridgeService::Get()->tts()->instance()
16 : nullptr;
17 }
18
19 } // namespace
20
21 // This class includes extension-based tts through LoadBuiltInTtsExtension and
22 // native tts through ARC.
13 class TtsPlatformImplChromeOs : public TtsPlatformImpl { 23 class TtsPlatformImplChromeOs : public TtsPlatformImpl {
14 public: 24 public:
15 // TtsPlatformImpl overrides: 25 // TtsPlatformImpl overrides:
16 bool PlatformImplAvailable() override { return false; } 26 bool PlatformImplAvailable() override { return GetArcTts() != nullptr; }
17 27
18 bool LoadBuiltInTtsExtension( 28 bool LoadBuiltInTtsExtension(
19 content::BrowserContext* browser_context) override { 29 content::BrowserContext* browser_context) override {
20 TtsEngineDelegate* tts_engine_delegate = 30 TtsEngineDelegate* tts_engine_delegate =
21 TtsController::GetInstance()->GetTtsEngineDelegate(); 31 TtsController::GetInstance()->GetTtsEngineDelegate();
22 if (tts_engine_delegate) 32 if (tts_engine_delegate)
23 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context); 33 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context);
24 return false; 34 return false;
25 } 35 }
26 36
27 bool Speak(int utterance_id, 37 bool Speak(int utterance_id,
28 const std::string& utterance, 38 const std::string& utterance,
29 const std::string& lang, 39 const std::string& lang,
30 const VoiceData& voice, 40 const VoiceData& voice,
31 const UtteranceContinuousParameters& params) override { 41 const UtteranceContinuousParameters& params) override {
32 return false; 42 arc::mojom::TtsInstance* tts = GetArcTts();
Luis Héctor Chávez 2016/07/26 22:48:11 DCHECK_CURRENTLY_ON(BrowserThread::UI);
hidehiko 2016/07/29 09:25:53 ping?
David Tseng 2016/08/01 20:21:41 Done.
43 if (!tts)
44 return false;
45
46 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New();
47 arc_utterance->utteranceId = utterance_id;
48 arc_utterance->text = utterance;
49 arc_utterance->rate = params.rate;
50 arc_utterance->pitch = params.pitch;
51 tts->Speak(std::move(arc_utterance));
52 return true;
33 } 53 }
34 54
35 bool StopSpeaking() override { return false; } 55 bool StopSpeaking() override {
56 arc::mojom::TtsInstance* tts = GetArcTts();
Luis Héctor Chávez 2016/07/26 22:48:11 DCHECK_CURRENTLY_ON(BrowserThread::UI);
hidehiko 2016/07/29 09:25:53 ping?
David Tseng 2016/08/01 20:21:41 Done.
57 if (!tts)
58 return false;
36 59
60 tts->Stop();
61 return true;
62 }
63
64 void GetVoices(std::vector<VoiceData>* out_voices) override {
65 out_voices->push_back(VoiceData());
66 VoiceData& voice = out_voices->back();
67 voice.native = true;
68 voice.name = "Android";
69 voice.events.insert(TTS_EVENT_START);
70 voice.events.insert(TTS_EVENT_END);
71 }
72
73 // Unimplemented.
37 void Pause() override {} 74 void Pause() override {}
38
39 void Resume() override {} 75 void Resume() override {}
40
41 bool IsSpeaking() override { return false; } 76 bool IsSpeaking() override { return false; }
42 77
43 void GetVoices(std::vector<VoiceData>* out_voices) override {}
44
45 // Get the single instance of this class. 78 // Get the single instance of this class.
46 static TtsPlatformImplChromeOs* GetInstance(); 79 static TtsPlatformImplChromeOs* GetInstance();
47 80
48 private: 81 private:
49 TtsPlatformImplChromeOs() {} 82 TtsPlatformImplChromeOs() {}
50 ~TtsPlatformImplChromeOs() override {} 83 ~TtsPlatformImplChromeOs() override {}
51 84
52 friend struct base::DefaultSingletonTraits<TtsPlatformImplChromeOs>; 85 friend struct base::DefaultSingletonTraits<TtsPlatformImplChromeOs>;
53 86
54 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs); 87 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
55 }; 88 };
56 89
57 // static 90 // static
58 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { 91 TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
59 return TtsPlatformImplChromeOs::GetInstance(); 92 return TtsPlatformImplChromeOs::GetInstance();
60 } 93 }
61 94
62 // static 95 // static
63 TtsPlatformImplChromeOs* 96 TtsPlatformImplChromeOs*
64 TtsPlatformImplChromeOs::GetInstance() { 97 TtsPlatformImplChromeOs::GetInstance() {
65 return base::Singleton<TtsPlatformImplChromeOs>::get(); 98 return base::Singleton<TtsPlatformImplChromeOs>::get();
66 } 99 }
OLDNEW
« no previous file with comments | « no previous file | components/arc/BUILD.gn » ('j') | components/arc/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698