| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "content/browser/speech/speech_recognizer.h" | 12 #include "content/browser/speech/speech_recognizer.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 class SpeechInputPreferences; | 16 class SpeechInputPreferences; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class ResourceContext; |
| 19 struct SpeechInputResult; | 20 struct SpeechInputResult; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace speech_input { | 23 namespace speech_input { |
| 23 | 24 |
| 24 // This is the gatekeeper for speech recognition in the browser process. It | 25 // This is the gatekeeper for speech recognition in the browser process. It |
| 25 // handles requests received from various render views and makes sure only one | 26 // handles requests received from various render views and makes sure only one |
| 26 // of them can use speech recognition at a time. It also sends recognition | 27 // of them can use speech recognition at a time. It also sends recognition |
| 27 // results and status events to the render views when required. | 28 // results and status events to the render views when required. |
| 28 class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate { | 29 class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 // Describes the microphone errors that are reported via ShowMicError. | 44 // Describes the microphone errors that are reported via ShowMicError. |
| 44 enum MicError { | 45 enum MicError { |
| 45 kNoDeviceAvailable = 0, | 46 kNoDeviceAvailable = 0, |
| 46 kDeviceInUse | 47 kDeviceInUse |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 SpeechInputManager(); | 50 SpeechInputManager(); |
| 50 | 51 |
| 51 // Invokes the platform provided microphone settings UI in a non-blocking way, | 52 // Invokes the platform provided microphone settings UI in a non-blocking way, |
| 52 // via the BrowserThread::FILE thread. | 53 // via the BrowserThread::FILE thread. |
| 53 static void ShowAudioInputSettings(); | 54 static void ShowAudioInputSettings(AudioManager* audio_manager); |
| 55 |
| 56 // Same as ShowAudioInputSettings above but can be called from the UI thread |
| 57 // where the caller has a pointer to a resource context, but due to not |
| 58 // running on the IO thread, cannot access its properties. |
| 59 static void ShowAudioInputSettingsFromUI( |
| 60 const content::ResourceContext* resource_context); |
| 54 | 61 |
| 55 virtual ~SpeechInputManager(); | 62 virtual ~SpeechInputManager(); |
| 56 | 63 |
| 57 // Handlers for requests from render views. | 64 // Handlers for requests from render views. |
| 58 | 65 |
| 59 // |delegate| is a weak pointer and should remain valid until | 66 // |delegate| is a weak pointer and should remain valid until |
| 60 // its |DidCompleteRecognition| method is called or recognition is cancelled. | 67 // its |DidCompleteRecognition| method is called or recognition is cancelled. |
| 61 // |render_process_id| is the ID of the renderer process initiating the | 68 // |render_process_id| is the ID of the renderer process initiating the |
| 62 // request. | 69 // request. |
| 63 // |element_rect| is the display bounds of the html element requesting speech | 70 // |element_rect| is the display bounds of the html element requesting speech |
| 64 // input (in page coordinates). | 71 // input (in page coordinates). |
| 65 virtual void StartRecognition(Delegate* delegate, | 72 virtual void StartRecognition(Delegate* delegate, |
| 66 int caller_id, | 73 int caller_id, |
| 67 int render_process_id, | 74 int render_process_id, |
| 68 int render_view_id, | 75 int render_view_id, |
| 69 const gfx::Rect& element_rect, | 76 const gfx::Rect& element_rect, |
| 70 const std::string& language, | 77 const std::string& language, |
| 71 const std::string& grammar, | 78 const std::string& grammar, |
| 72 const std::string& origin_url, | 79 const std::string& origin_url, |
| 73 net::URLRequestContextGetter* context_getter, | 80 net::URLRequestContextGetter* context_getter, |
| 74 SpeechInputPreferences* speech_input_prefs); | 81 SpeechInputPreferences* speech_input_prefs, |
| 82 AudioManager* audio_manager); |
| 75 virtual void CancelRecognition(int caller_id); | 83 virtual void CancelRecognition(int caller_id); |
| 76 virtual void CancelAllRequestsWithDelegate(Delegate* delegate); | 84 virtual void CancelAllRequestsWithDelegate(Delegate* delegate); |
| 77 virtual void StopRecording(int caller_id); | 85 virtual void StopRecording(int caller_id); |
| 78 | 86 |
| 79 // SpeechRecognizerDelegate methods. | 87 // SpeechRecognizerDelegate methods. |
| 80 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; | 88 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; |
| 81 virtual void SetRecognitionResult( | 89 virtual void SetRecognitionResult( |
| 82 int caller_id, | 90 int caller_id, |
| 83 const content::SpeechInputResult& result) OVERRIDE; | 91 const content::SpeechInputResult& result) OVERRIDE; |
| 84 virtual void DidCompleteRecording(int caller_id) OVERRIDE; | 92 virtual void DidCompleteRecording(int caller_id) OVERRIDE; |
| 85 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; | 93 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; |
| 86 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; | 94 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; |
| 87 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; | 95 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; |
| 88 | 96 |
| 89 virtual void OnRecognizerError(int caller_id, | 97 virtual void OnRecognizerError(int caller_id, |
| 90 content::SpeechInputError error) OVERRIDE; | 98 content::SpeechInputError error) OVERRIDE; |
| 91 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; | 99 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; |
| 92 virtual void SetInputVolume(int caller_id, float volume, | 100 virtual void SetInputVolume(int caller_id, float volume, |
| 93 float noise_volume) OVERRIDE; | 101 float noise_volume) OVERRIDE; |
| 94 | 102 |
| 95 protected: | 103 protected: |
| 96 // The pure virtual methods are used for displaying the current state of | 104 // The pure virtual methods are used for displaying the current state of |
| 97 // recognition and for fetching optional request information. | 105 // recognition and for fetching optional request information. |
| 98 | 106 |
| 99 // Get the optional request information if available. | 107 // Get the optional request information if available. |
| 100 virtual void GetRequestInfo(bool* can_report_metrics, | 108 virtual void GetRequestInfo(AudioManager* audio_manager, |
| 109 bool* can_report_metrics, |
| 101 std::string* request_info) = 0; | 110 std::string* request_info) = 0; |
| 102 | 111 |
| 103 // Called when recognition has been requested from point |element_rect_| on | 112 // Called when recognition has been requested from point |element_rect_| on |
| 104 // the view port for the given caller. | 113 // the view port for the given caller. |
| 105 virtual void ShowRecognitionRequested(int caller_id, | 114 virtual void ShowRecognitionRequested(int caller_id, |
| 106 int render_process_id, | 115 int render_process_id, |
| 107 int render_view_id, | 116 int render_view_id, |
| 108 const gfx::Rect& element_rect) = 0; | 117 const gfx::Rect& element_rect) = 0; |
| 109 | 118 |
| 110 // Called when recognition is starting up. | 119 // Called when recognition is starting up. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 176 |
| 168 // This typedef is to workaround the issue with certain versions of | 177 // This typedef is to workaround the issue with certain versions of |
| 169 // Visual Studio where it gets confused between multiple Delegate | 178 // Visual Studio where it gets confused between multiple Delegate |
| 170 // classes and gives a C2500 error. (I saw this error on the try bots - | 179 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 171 // the workaround was not needed for my machine). | 180 // the workaround was not needed for my machine). |
| 172 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; | 181 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; |
| 173 | 182 |
| 174 } // namespace speech_input | 183 } // namespace speech_input |
| 175 | 184 |
| 176 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 185 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
| OLD | NEW |