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

Unified 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: Fix debug assertion 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 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 e42cb0c546b4642050ddd73fc9df48d3ef7dd4fd..1c86c5642cc2d308bc89a19b5f0acff80638921b 100644
--- a/chrome/browser/speech/tts_chromeos.cc
+++ b/chrome/browser/speech/tts_chromeos.cc
@@ -2,13 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/speech/tts_extension_loader_chromeos.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/tts_platform.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/pref_names.h"
+
+namespace {
+
+// Trigger installing high-quality speech after this many utterances
+// have been spoken in one session.
+const int kHighQualitySpeechUtteranceThreshold = 100;
+
+} // anonymous namespace
// 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.
+// component extension that provides speech synthesis. This class monitors
+// use of this component extension and triggers installing a higher-quality
+// speech synthesis extension if a certain number of utterances are spoken
+// in a single session.
class TtsPlatformImplChromeOs
: public TtsPlatformImpl {
public:
@@ -17,10 +31,6 @@ class TtsPlatformImplChromeOs
return false;
}
- virtual bool LoadBuiltInTtsExtension(Profile* profile) OVERRIDE {
- return TtsExtensionLoaderChromeOs::GetInstance(profile)->LoadTtsExtension();
- }
-
virtual bool Speak(
int utterance_id,
const std::string& utterance,
@@ -30,33 +40,63 @@ class TtsPlatformImplChromeOs
return false;
}
- virtual bool StopSpeaking() OVERRIDE {
- return false;
- }
-
+ virtual bool StopSpeaking() OVERRIDE { return false; }
virtual void Pause() OVERRIDE {}
-
virtual void Resume() OVERRIDE {}
+ virtual bool IsSpeaking() OVERRIDE { return false; }
+ virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE {}
- virtual bool IsSpeaking() OVERRIDE {
- return false;
- }
-
- virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE {
- }
+ virtual void WillSpeakUtteranceWithVoice(
+ const Utterance* utterance,
+ const VoiceData& voice_data) OVERRIDE;
// Get the single instance of this class.
static TtsPlatformImplChromeOs* GetInstance();
private:
- TtsPlatformImplChromeOs() {}
+ TtsPlatformImplChromeOs();
virtual ~TtsPlatformImplChromeOs() {}
friend struct DefaultSingletonTraits<TtsPlatformImplChromeOs>;
+ // A count of the number of utterances spoken for each language
+ // using the built-in speech synthesis. When enough utterances have
+ // been spoken in a single session, automatically enable install
+ // the high-quality speech synthesis extension for that language.
+ base::hash_map<std::string, int> lang_utterance_count_;
+
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
};
+TtsPlatformImplChromeOs::TtsPlatformImplChromeOs() {
+}
+
+void TtsPlatformImplChromeOs::WillSpeakUtteranceWithVoice(
+ const Utterance* utterance,
+ const VoiceData& voice_data) {
+ CHECK(utterance);
+ CHECK(utterance->profile());
+
+ if (utterance->profile()->IsOffTheRecord())
+ return;
+
+ if (voice_data.extension_id != extension_misc::kSpeechSynthesisExtensionId)
+ return;
+
+ lang_utterance_count_[voice_data.lang]++;
+ if (lang_utterance_count_[voice_data.lang] !=
+ kHighQualitySpeechUtteranceThreshold) {
+ return;
+ }
+
+ // Add this language to the list that are allowed to install a
+ // component extension for high-quality speech synthesis, overriding
+ // the lower-quality one.
+ ListPrefUpdate updater(utterance->profile()->GetPrefs(),
+ prefs::kHighQualitySpeechSynthesisLanguages);
+ updater->AppendIfNotPresent(new base::StringValue(voice_data.lang));
+}
+
// static
TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
return TtsPlatformImplChromeOs::GetInstance();
« no previous file with comments | « chrome/browser/resources/chromeos/speech_synthesis/manifest.json ('k') | chrome/browser/speech/tts_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698