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

Side by Side Diff: content/public/browser/speech_recognition_manager.h

Issue 9972011: Speech refactoring: Reimplemented SpeechRecognitionManagerImpl as a FSM. (CL1.7) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased from master. Created 8 years, 8 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 | Annotate | Revision Log
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 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ 6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
7 7
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/callback.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
11 #include "content/public/common/speech_recognition_result.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 // This is the gatekeeper for speech recognition in the browser process. It 15 class SpeechRecognitionEventListener;
14 // handles requests received from various render views and makes sure only one 16 struct SpeechRecognitionSessionConfig;
15 // of them can use speech recognition at a time. It also sends recognition 17 struct SpeechRecognitionSessionContext;
16 // results and status events to the render views when required. 18
17 class SpeechRecognitionManager { 19 // The SpeechRecognitionManager (SRM) is a singleton class that handles SR
Satish 2012/04/19 13:03:19 I like this comment block :) but feels verbose. Ca
Primiano Tucci (use gerrit) 2012/04/20 16:06:43 Done.
20 // functionalities within Chrome. Everyone that needs to perform SR should
21 // interface exclusively with the SRM. Usually SR requires the operation and
22 // coordination of several objects (an audio controller, a SR engine...). The
23 // aim of the SRM is to make all this activities transparent to end users,
24 // which will perceive only the SRM methods and the callback interface
25 // SpeechRecognitionEventListener.
26 // Since many different sources can use SR in different times (some overlapping
27 // is allowed while waiting for results), the SRM has the further responsibility
28 // of handling separately and reliably these different sessions, distinguishing
29 // them by means of a session_id.
30 // The rationale behind the word "reliably" is that while most of the classes,
31 // that are (should be) NOT directly accessible to the end-user are designed to
32 // work in an ideal flow (the SpeechRecognizer will get extremely offended if
33 // asked to start recognition while it is already in progress), the SRM is
34 // designed to interface with an evil world (the user interface / JS APIs) in
35 // which very bad people that will try any possible sequence of commands, often
36 // without a particular logic.
37 // In this sense a session, within the SRM, models the ongoing evolution of a
38 // SR request from the viewpoint of the end-user (abstracting all the concrete
39 // operations that must be carried out, that will be handled by inner classes).
40 // SR session requires for most of the time (i.e. audio capture) exclusive
41 // interaction with the user (popup/notifications/consensus). For this reason,
42 // while many SR sessions can be alive during the lifetime of the browser,
43 // only one, the interactive session, is allowed to capture audio and interact
44 // with the user. After the audio capture is terminated the session may
45 // eventually be detached (will continue processing recorded audio and gathering
46 // the results without interacting with the user). A SR session finally dies
47 // either when it retrieves a valid result or when, after reporting a visible
48 class CONTENT_EXPORT SpeechRecognitionManager {
18 public: 49 public:
50 static const int kSessionIDInvalid;
51
19 // Returns the singleton instance. 52 // Returns the singleton instance.
20 CONTENT_EXPORT static SpeechRecognitionManager* GetInstance(); 53 static SpeechRecognitionManager* GetInstance();
21 54
22 // Starts/restarts recognition for an existing request. 55 // Creates a new recognition session.
23 virtual void StartRecognitionForRequest(int session_id) = 0; 56 virtual int CreateSession(SpeechRecognitionSessionConfig& config,
57 SpeechRecognitionEventListener* listener) = 0;
24 58
25 // Cancels recognition for an existing request. 59 // Starts/restarts recognition for an existing session.
26 virtual void CancelRecognitionForRequest(int session_id) = 0; 60 virtual void StartSession(int session_id) = 0;
27 61
28 // Called when the user clicks outside the speech input UI causing it to close 62 // Aborts recognition for an existing session, without providing any result.
29 // and possibly have speech input go to another element. 63 virtual void AbortSession(int session_id) = 0;
30 virtual void FocusLostForRequest(int session_id) = 0; 64
65 // Aborts all sessions for a given listener, without providing any result.
66 virtual void AbortAllSessionsForListener(
67 SpeechRecognitionEventListener* listener) = 0;
68
69 // Stops audio capture for an existing session. The audio captured before the
70 // call will be processed, possibly ending up with a result.
71 virtual void StopAudioCaptureForSession(int session_id) = 0;
72
73 // Detaches the session preventing it from interacting further with the
74 // browser (typically invoked when the user clicks outside the speech UI).
75 // The session will be silently continued in background if possible (in the
76 // case it already finished capturing audio and was just waiting for the
77 // result) or will be aborted if user interaction (e.g., audio recording) was
78 // involved at the time DetachSession was called.
79 virtual void DetachSession(int session_id) = 0;
80
81 // Retrieves the context associated to a session.
82 virtual SpeechRecognitionSessionContext& GetSessionContext(
83 int session_id) const = 0;
84
85 // Looks-up an existing session using a caller-provided matcher function.
86 virtual int LookupSessionByContext(
87 base::Callback<bool(
88 const content::SpeechRecognitionSessionContext&)> matcher)
89 const = 0;
31 90
32 // Returns true if the OS reports existence of audio recording devices. 91 // Returns true if the OS reports existence of audio recording devices.
33 virtual bool HasAudioInputDevices() = 0; 92 virtual bool HasAudioInputDevices() = 0;
34 93
35 // Used to determine if something else is currently making use of audio input. 94 // Used to determine if something else is currently making use of audio input.
36 virtual bool IsCapturingAudio() = 0; 95 virtual bool IsCapturingAudio() = 0;
37 96
38 // Returns a human readable string for the model/make of the active audio 97 // Returns a human readable string for the model/make of the active audio
39 // input device for this computer. 98 // input device for this computer.
40 virtual string16 GetAudioInputDeviceModel() = 0; 99 virtual string16 GetAudioInputDeviceModel() = 0;
41 100
42 // Invokes the platform provided microphone settings UI in a non-blocking way, 101 // Invokes the platform provided microphone settings UI in a non-blocking way,
43 // via the BrowserThread::FILE thread. 102 // via the BrowserThread::FILE thread.
44 virtual void ShowAudioInputSettings() = 0; 103 virtual void ShowAudioInputSettings() = 0;
45 104
46 protected: 105 protected:
47 virtual ~SpeechRecognitionManager() {} 106 virtual ~SpeechRecognitionManager() {}
48 }; 107 };
49 108
50 } // namespace content 109 } // namespace content
51 110
52 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ 111 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698