OLD | NEW |
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 |
| 19 // The SpeechRecognitionManager (SRM) is a singleton class that handles SR |
| 20 // functionalities within Chrome. Everyone that needs to perform SR should |
| 21 // interface exclusively with the SRM, receiving events through the callback |
| 22 // interface SpeechRecognitionEventListener. |
| 23 // Since many different sources can use SR in different times (some overlapping |
| 24 // is allowed while waiting for results), the SRM has the further responsibility |
| 25 // of handling separately and reliably (taking into account also call sequences |
| 26 // that might not make sense, e.g., two subsequent AbortSession calls). |
| 27 // In this sense a session, within the SRM, models the ongoing evolution of a |
| 28 // SR request from the viewpoint of the end-user, abstracting all the concrete |
| 29 // operations that must be carried out, that will be handled by inner classes. |
17 class SpeechRecognitionManager { | 30 class SpeechRecognitionManager { |
18 public: | 31 public: |
| 32 static const int kSessionIDInvalid; |
| 33 |
19 // Returns the singleton instance. | 34 // Returns the singleton instance. |
20 CONTENT_EXPORT static SpeechRecognitionManager* GetInstance(); | 35 static CONTENT_EXPORT SpeechRecognitionManager* GetInstance(); |
21 | 36 |
22 // Starts/restarts recognition for an existing request. | 37 // Creates a new recognition session. |
23 virtual void StartRecognitionForRequest(int session_id) = 0; | 38 virtual int CreateSession(const SpeechRecognitionSessionConfig& config, |
| 39 SpeechRecognitionEventListener* listener) = 0; |
24 | 40 |
25 // Cancels recognition for an existing request. | 41 // Starts/restarts recognition for an existing session, after performing a |
26 virtual void CancelRecognitionForRequest(int session_id) = 0; | 42 // premilinary check on the delegate (CheckRecognitionIsAllowed). |
| 43 virtual void StartSession(int session_id) = 0; |
27 | 44 |
28 // Called when the user clicks outside the speech input UI causing it to close | 45 // Aborts recognition for an existing session, without providing any result. |
29 // and possibly have speech input go to another element. | 46 virtual void AbortSession(int session_id) = 0; |
30 virtual void FocusLostForRequest(int session_id) = 0; | 47 |
| 48 // Aborts all sessions for a given listener, without providing any result. |
| 49 virtual void AbortAllSessionsForListener( |
| 50 SpeechRecognitionEventListener* listener) = 0; |
| 51 |
| 52 // Stops audio capture for an existing session. The audio captured before the |
| 53 // call will be processed, possibly ending up with a result. |
| 54 virtual void StopAudioCaptureForSession(int session_id) = 0; |
| 55 |
| 56 // Sends the session to background preventing it from further interacting with |
| 57 // the browser (typically invoked when the user clicks outside the speech UI). |
| 58 // The session will be silently continued in background if possible (in case |
| 59 // it already finished capturing audio and was just waiting for the result) or |
| 60 // will be aborted if user interaction (e.g., audio recording) was involved |
| 61 // when this function was called. |
| 62 virtual void SendSessionToBackground(int session_id) = 0; |
| 63 |
| 64 // Retrieves the context associated to a session. |
| 65 virtual SpeechRecognitionSessionContext GetSessionContext( |
| 66 int session_id) const = 0; |
| 67 |
| 68 // Looks-up an existing session using a caller-provided matcher function. |
| 69 virtual int LookupSessionByContext( |
| 70 base::Callback<bool( |
| 71 const content::SpeechRecognitionSessionContext&)> matcher) |
| 72 const = 0; |
31 | 73 |
32 // Returns true if the OS reports existence of audio recording devices. | 74 // Returns true if the OS reports existence of audio recording devices. |
33 virtual bool HasAudioInputDevices() = 0; | 75 virtual bool HasAudioInputDevices() = 0; |
34 | 76 |
35 // Used to determine if something else is currently making use of audio input. | 77 // Used to determine if something else is currently making use of audio input. |
36 virtual bool IsCapturingAudio() = 0; | 78 virtual bool IsCapturingAudio() = 0; |
37 | 79 |
38 // Returns a human readable string for the model/make of the active audio | 80 // Returns a human readable string for the model/make of the active audio |
39 // input device for this computer. | 81 // input device for this computer. |
40 virtual string16 GetAudioInputDeviceModel() = 0; | 82 virtual string16 GetAudioInputDeviceModel() = 0; |
41 | 83 |
42 // Invokes the platform provided microphone settings UI in a non-blocking way, | 84 // Invokes the platform provided microphone settings UI in a non-blocking way, |
43 // via the BrowserThread::FILE thread. | 85 // via the BrowserThread::FILE thread. |
44 virtual void ShowAudioInputSettings() = 0; | 86 virtual void ShowAudioInputSettings() = 0; |
45 | 87 |
46 protected: | 88 protected: |
47 virtual ~SpeechRecognitionManager() {} | 89 virtual ~SpeechRecognitionManager() {} |
48 }; | 90 }; |
49 | 91 |
50 } // namespace content | 92 } // namespace content |
51 | 93 |
52 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ | 94 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_ |
OLD | NEW |