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

Unified Diff: chrome/browser/ui/app_list/speech_recognizer.h

Issue 676593003: Implement native speech recognition for the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor and address review comments. Created 6 years, 2 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/ui/app_list/speech_recognizer.h
diff --git a/chrome/browser/ui/app_list/speech_recognizer.h b/chrome/browser/ui/app_list/speech_recognizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..9b01e115de0dc1c19d6be049b219320e8ad7889d
--- /dev/null
+++ b/chrome/browser/ui/app_list/speech_recognizer.h
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_
+#define CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "base/timer/timer.h"
+#include "content/public/browser/speech_recognition_event_listener.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "ui/app_list/speech_ui_model_observer.h"
+
+namespace app_list {
+
+class SpeechRecognizerDelegate;
+class StartPageService;
+
+// SpeechRecognizer is a wrapper around the speech recognition engine that
+// simplifies its use from the UI thread. This class handles all setup/shutdown,
+// collection of results, error cases, and threading.
+class SpeechRecognizer : public base::RefCountedThreadSafe<SpeechRecognizer>,
+ public content::SpeechRecognitionEventListener {
+ public:
+ SpeechRecognizer(SpeechRecognizerDelegate* delegate,
+ net::URLRequestContextGetter* url_request_context_getter,
+ const std::string& locale);
+
+ // Start/stop the speech recognizer. Must be called on the UI thread.
+ void Start();
+ void Stop();
+
+ protected:
+ // Overidden from content::SpeechRecognitionEventListener:
+ // These are always called on the IO thread.
+ void OnRecognitionStart(int session_id) override;
+ void OnRecognitionEnd(int session_id) override;
+ void OnRecognitionResults(
+ int session_id,
+ const content::SpeechRecognitionResults& results) override;
+ void OnRecognitionError(
+ int session_id, const content::SpeechRecognitionError& error) override;
+ void OnSoundStart(int session_id) override;
+ void OnSoundEnd(int session_id) override;
+ void OnAudioLevelsChange(
+ int session_id, float volume, float noise_volume) override;
+ // Overridden, but with trivial implementations.
Matt Giuca 2014/11/03 02:35:52 I don't think this line is necessary.
Anand Mistry (off Chromium) 2014/11/03 06:51:56 Removed.
+ void OnEnvironmentEstimationComplete(int session_id) override;
+ void OnAudioStart(int session_id) override;
+ void OnAudioEnd(int session_id) override;
+
+ private:
+ friend class base::RefCountedThreadSafe<SpeechRecognizer>;
+ ~SpeechRecognizer();
+
+ void StartOnIOThread(
+ int render_process_id,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
+ void StopOnIOThread();
+
+ void NotifyRecognitionStateChanged(SpeechRecognitionState new_state);
+
+ void StartSpeechTimeout();
+ void StopSpeechTimeout();
+ void SpeechTimeout();
+
+ SpeechRecognizerDelegate* delegate_; // Not owned.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+ std::string locale_;
+ base::Timer speech_timeout_;
+ int session_;
+
+ base::WeakPtrFactory<SpeechRecognizer> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer);
+};
+
+} // namespace app_list
+
+#endif // CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_
« no previous file with comments | « no previous file | chrome/browser/ui/app_list/speech_recognizer.cc » ('j') | chrome/browser/ui/app_list/speech_recognizer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698