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

Side by Side Diff: chrome/browser/speech/tts_chromeos.cc

Issue 102263005: Automatically trigger installation of high-quality speech synthesis extension. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change extension manifest to match Chrome OS Created 7 years 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
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 "chrome/browser/speech/tts_extension_loader_chromeos.h" 5 #include "base/bind_helpers.h"
6 #include "base/logging.h"
7 #include "base/prefs/scoped_user_pref_update.h"
8 #include "chrome/browser/profiles/profile.h"
6 #include "chrome/browser/speech/tts_platform.h" 9 #include "chrome/browser/speech/tts_platform.h"
10 #include "chrome/common/extensions/extension_constants.h"
11 #include "chrome/common/pref_names.h"
12
13 namespace {
14
15 // Trigger installing high-quality speech after this many utterances
16 // have been spoken in one session.
17 const int kHighQualitySpeechUtteranceThreshold = 100;
18
19 } // anonymous namespace
7 20
8 // Chrome OS doesn't have native TTS, instead it includes a built-in 21 // Chrome OS doesn't have native TTS, instead it includes a built-in
9 // component extension that provides speech synthesis. This class includes 22 // component extension that provides speech synthesis. This class monitors
10 // an implementation of LoadBuiltInTtsExtension and dummy implementations of 23 // use of this component extension and triggers installing a higher-quality
11 // everything else. 24 // speech synthesis extension if a certain number of utterances are spoken
25 // in a single session.
12 class TtsPlatformImplChromeOs 26 class TtsPlatformImplChromeOs
13 : public TtsPlatformImpl { 27 : public TtsPlatformImpl {
14 public: 28 public:
15 // TtsPlatformImpl overrides: 29 // TtsPlatformImpl overrides:
16 virtual bool PlatformImplAvailable() OVERRIDE { 30 virtual bool PlatformImplAvailable() OVERRIDE {
17 return false; 31 return false;
18 } 32 }
19 33
20 virtual bool LoadBuiltInTtsExtension(Profile* profile) OVERRIDE {
21 return TtsExtensionLoaderChromeOs::GetInstance(profile)->LoadTtsExtension();
22 }
23
24 virtual bool Speak( 34 virtual bool Speak(
25 int utterance_id, 35 int utterance_id,
26 const std::string& utterance, 36 const std::string& utterance,
27 const std::string& lang, 37 const std::string& lang,
28 const VoiceData& voice, 38 const VoiceData& voice,
29 const UtteranceContinuousParameters& params) OVERRIDE { 39 const UtteranceContinuousParameters& params) OVERRIDE {
30 return false; 40 return false;
31 } 41 }
32 42
33 virtual bool StopSpeaking() OVERRIDE { 43 virtual bool StopSpeaking() OVERRIDE { return false; }
34 return false; 44 virtual void Pause() OVERRIDE {}
35 } 45 virtual void Resume() OVERRIDE {}
46 virtual bool IsSpeaking() OVERRIDE { return false; }
47 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE {}
36 48
37 virtual void Pause() OVERRIDE {} 49 virtual void WillSpeakUtteranceWithVoice(
38 50 const Utterance* utterance,
39 virtual void Resume() OVERRIDE {} 51 const VoiceData& voice_data) OVERRIDE;
40
41 virtual bool IsSpeaking() OVERRIDE {
42 return false;
43 }
44
45 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE {
46 }
47 52
48 // Get the single instance of this class. 53 // Get the single instance of this class.
49 static TtsPlatformImplChromeOs* GetInstance(); 54 static TtsPlatformImplChromeOs* GetInstance();
50 55
51 private: 56 private:
52 TtsPlatformImplChromeOs() {} 57 TtsPlatformImplChromeOs();
53 virtual ~TtsPlatformImplChromeOs() {} 58 virtual ~TtsPlatformImplChromeOs() {}
54 59
55 friend struct DefaultSingletonTraits<TtsPlatformImplChromeOs>; 60 friend struct DefaultSingletonTraits<TtsPlatformImplChromeOs>;
56 61
62 // A count of the number of utterances spoken for each language
63 // using the built-in speech synthesis. When enough utterances have
64 // been spoken in a single session, automatically enable install
65 // the high-quality speech synthesis extension for that language.
66 base::hash_map<std::string, int> lang_utterance_count_;
67
57 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs); 68 DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
58 }; 69 };
59 70
71 TtsPlatformImplChromeOs::TtsPlatformImplChromeOs() {
72 }
73
74 void TtsPlatformImplChromeOs::WillSpeakUtteranceWithVoice(
75 const Utterance* utterance,
76 const VoiceData& voice_data) {
77 CHECK(utterance);
78 CHECK(utterance->profile());
79
80 if (utterance->profile()->IsOffTheRecord())
81 return;
82
83 if (voice_data.extension_id != extension_misc::kSpeechSynthesisExtensionId)
84 return;
85
86 lang_utterance_count_[voice_data.lang]++;
87 if (lang_utterance_count_[voice_data.lang] !=
88 kHighQualitySpeechUtteranceThreshold) {
89 return;
90 }
91
92 // Add this language to the list that are allowed to install a
93 // component extension for high-quality speech synthesis, overriding
94 // the lower-quality one.
95 ListPrefUpdate updater(utterance->profile()->GetPrefs(),
96 prefs::kHighQualitySpeechSynthesisLanguages);
97 updater->AppendIfNotPresent(new base::StringValue(voice_data.lang));
98 }
99
60 // static 100 // static
61 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { 101 TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
62 return TtsPlatformImplChromeOs::GetInstance(); 102 return TtsPlatformImplChromeOs::GetInstance();
63 } 103 }
64 104
65 // static 105 // static
66 TtsPlatformImplChromeOs* 106 TtsPlatformImplChromeOs*
67 TtsPlatformImplChromeOs::GetInstance() { 107 TtsPlatformImplChromeOs::GetInstance() {
68 return Singleton<TtsPlatformImplChromeOs>::get(); 108 return Singleton<TtsPlatformImplChromeOs>::get();
69 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698