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

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: Address last round. 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 | « chrome/browser/chromeos/arc/arc_tts_service.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
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"
9 #include "content/public/browser/browser_thread.h"
7 10
8 // Chrome OS doesn't have native TTS, instead it includes a built-in 11 namespace {
9 // component extension that provides speech synthesis. This class includes
10 // an implementation of LoadBuiltInTtsExtension and dummy implementations of
11 // everything else.
12 12
13 // Helper returning an ARC tts instance.
14 arc::mojom::TtsInstance* GetArcTts() {
15 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
16 return arc::ArcBridgeService::Get()
17 ? arc::ArcBridgeService::Get()->tts()->instance()
18 : nullptr;
19 }
20
21 } // namespace
22
23 // This class includes extension-based tts through LoadBuiltInTtsExtension and
24 // native tts through ARC.
13 class TtsPlatformImplChromeOs : public TtsPlatformImpl { 25 class TtsPlatformImplChromeOs : public TtsPlatformImpl {
14 public: 26 public:
15 // TtsPlatformImpl overrides: 27 // TtsPlatformImpl overrides:
16 bool PlatformImplAvailable() override { return false; } 28 bool PlatformImplAvailable() override { return GetArcTts() != nullptr; }
17 29
18 bool LoadBuiltInTtsExtension( 30 bool LoadBuiltInTtsExtension(
19 content::BrowserContext* browser_context) override { 31 content::BrowserContext* browser_context) override {
20 TtsEngineDelegate* tts_engine_delegate = 32 TtsEngineDelegate* tts_engine_delegate =
21 TtsController::GetInstance()->GetTtsEngineDelegate(); 33 TtsController::GetInstance()->GetTtsEngineDelegate();
22 if (tts_engine_delegate) 34 if (tts_engine_delegate)
23 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context); 35 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context);
24 return false; 36 return false;
25 } 37 }
26 38
27 bool Speak(int utterance_id, 39 bool Speak(int utterance_id,
28 const std::string& utterance, 40 const std::string& utterance,
29 const std::string& lang, 41 const std::string& lang,
30 const VoiceData& voice, 42 const VoiceData& voice,
31 const UtteranceContinuousParameters& params) override { 43 const UtteranceContinuousParameters& params) override {
32 return false; 44 arc::mojom::TtsInstance* tts = GetArcTts();
45 if (!tts)
46 return false;
47
48 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New();
49 arc_utterance->utteranceId = utterance_id;
50 arc_utterance->text = utterance;
51 arc_utterance->rate = params.rate;
52 arc_utterance->pitch = params.pitch;
53 tts->Speak(std::move(arc_utterance));
54 return true;
33 } 55 }
34 56
35 bool StopSpeaking() override { return false; } 57 bool StopSpeaking() override {
58 arc::mojom::TtsInstance* tts = GetArcTts();
59 if (!tts)
60 return false;
36 61
62 tts->Stop();
63 return true;
64 }
65
66 void GetVoices(std::vector<VoiceData>* out_voices) override {
67 out_voices->push_back(VoiceData());
68 VoiceData& voice = out_voices->back();
69 voice.native = true;
70 voice.name = "Android";
71 voice.events.insert(TTS_EVENT_START);
72 voice.events.insert(TTS_EVENT_END);
73 }
74
75 // Unimplemented.
37 void Pause() override {} 76 void Pause() override {}
38
39 void Resume() override {} 77 void Resume() override {}
40
41 bool IsSpeaking() override { return false; } 78 bool IsSpeaking() override { return false; }
42 79
43 void GetVoices(std::vector<VoiceData>* out_voices) override {}
44
45 // Get the single instance of this class. 80 // Get the single instance of this class.
46 static TtsPlatformImplChromeOs* GetInstance(); 81 static TtsPlatformImplChromeOs* GetInstance();
47 82
48 private: 83 private:
49 TtsPlatformImplChromeOs() {} 84 TtsPlatformImplChromeOs() {}
50 ~TtsPlatformImplChromeOs() override {} 85 ~TtsPlatformImplChromeOs() override {}
51 86
52 friend struct base::DefaultSingletonTraits<TtsPlatformImplChromeOs>; 87 friend struct base::DefaultSingletonTraits<TtsPlatformImplChromeOs>;
53 88
54 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs); 89 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
55 }; 90 };
56 91
57 // static 92 // static
58 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { 93 TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
59 return TtsPlatformImplChromeOs::GetInstance(); 94 return TtsPlatformImplChromeOs::GetInstance();
60 } 95 }
61 96
62 // static 97 // static
63 TtsPlatformImplChromeOs* 98 TtsPlatformImplChromeOs*
64 TtsPlatformImplChromeOs::GetInstance() { 99 TtsPlatformImplChromeOs::GetInstance() {
65 return base::Singleton<TtsPlatformImplChromeOs>::get(); 100 return base::Singleton<TtsPlatformImplChromeOs>::get();
66 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_tts_service.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698