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> | |
9 #include <string> | |
10 | |
8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "content/browser/speech/speech_recognizer.h" | |
9 #include "content/common/speech_input_result.h" | 13 #include "content/common/speech_input_result.h" |
10 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
11 | 15 |
12 namespace speech_input { | 16 namespace speech_input { |
13 | 17 |
14 // This is the gatekeeper for speech recognition in the browser process. It | 18 // This is the gatekeeper for speech recognition in the browser process. It |
15 // handles requests received from various render views and makes sure only one | 19 // handles requests received from various render views and makes sure only one |
16 // of them can use speech recognition at a time. It also sends recognition | 20 // of them can use speech recognition at a time. It also sends recognition |
17 // results and status events to the render views when required. | 21 // results and status events to the render views when required. |
18 class SpeechInputManager { | 22 class SpeechInputManager : public SpeechRecognizerDelegate { |
19 public: | 23 public: |
20 // Implemented by the dispatcher host to relay events to the render views. | 24 // Implemented by the dispatcher host to relay events to the render views. |
21 class Delegate { | 25 class Delegate { |
22 public: | 26 public: |
23 virtual void SetRecognitionResult( | 27 virtual void SetRecognitionResult( |
24 int caller_id, | 28 int caller_id, |
25 const SpeechInputResultArray& result) = 0; | 29 const SpeechInputResultArray& result) = 0; |
26 virtual void DidCompleteRecording(int caller_id) = 0; | 30 virtual void DidCompleteRecording(int caller_id) = 0; |
27 virtual void DidCompleteRecognition(int caller_id) = 0; | 31 virtual void DidCompleteRecognition(int caller_id) = 0; |
28 | 32 |
(...skipping 10 matching lines...) Expand all Loading... | |
39 virtual ~SpeechInputManager(); | 43 virtual ~SpeechInputManager(); |
40 | 44 |
41 // Handlers for requests from render views. | 45 // Handlers for requests from render views. |
42 | 46 |
43 // |delegate| is a weak pointer and should remain valid until | 47 // |delegate| is a weak pointer and should remain valid until |
44 // its |DidCompleteRecognition| method is called or recognition is cancelled. | 48 // its |DidCompleteRecognition| method is called or recognition is cancelled. |
45 // |render_process_id| is the ID of the renderer process initiating the | 49 // |render_process_id| is the ID of the renderer process initiating the |
46 // request. | 50 // request. |
47 // |element_rect| is the display bounds of the html element requesting speech | 51 // |element_rect| is the display bounds of the html element requesting speech |
48 // input (in page coordinates). | 52 // input (in page coordinates). |
49 virtual void StartRecognition(Delegate* delegate, | 53 void StartRecognition(Delegate* delegate, |
50 int caller_id, | 54 int caller_id, |
51 int render_process_id, | 55 int render_process_id, |
52 int render_view_id, | 56 int render_view_id, |
53 const gfx::Rect& element_rect, | 57 const gfx::Rect& element_rect, |
54 const std::string& language, | 58 const std::string& language, |
55 const std::string& grammar, | 59 const std::string& grammar, |
56 const std::string& origin_url) = 0; | 60 const std::string& origin_url); |
57 virtual void CancelRecognition(int caller_id) = 0; | 61 void CancelRecognition(int caller_id); |
58 virtual void StopRecording(int caller_id) = 0; | 62 void CancelAllRequestsWithDelegate(Delegate* delegate); |
63 void StopRecording(int caller_id); | |
59 | 64 |
60 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) = 0; | 65 // SpeechRecognizer::Delegate methods. |
66 virtual void DidStartReceivingAudio(int caller_id); | |
67 virtual void SetRecognitionResult(int caller_id, | |
68 bool error, | |
69 const SpeechInputResultArray& result); | |
70 virtual void DidCompleteRecording(int caller_id); | |
71 virtual void DidCompleteRecognition(int caller_id); | |
72 virtual void OnRecognizerError(int caller_id, | |
73 SpeechRecognizer::ErrorCode error); | |
74 virtual void DidCompleteEnvironmentEstimation(int caller_id); | |
75 virtual void SetInputVolume(int caller_id, float volume, float noise_volume); | |
61 | 76 |
62 void set_censor_results(bool censor) { censor_results_ = censor; } | 77 void set_censor_results(bool censor) { censor_results_ = censor; } |
63 | 78 |
64 bool censor_results() { return censor_results_; } | 79 bool censor_results() { return censor_results_; } |
65 | 80 |
81 protected: | |
82 virtual void CreateBubble(int caller_id, | |
Satish
2011/09/12 12:23:05
add comments for each of these explaining what the
allanwoj
2011/09/19 18:30:38
Done.
| |
83 int render_process_id, | |
84 int render_view_id, | |
85 const gfx::Rect& element_rect) = 0; | |
86 virtual void FetchRequestInfo() = 0; | |
87 virtual void NoMicBubbleMessage(int caller_id) = 0; | |
Satish
2011/09/12 12:23:05
perhaps rename this to HandleNoMicError() similar
allanwoj
2011/09/19 18:30:38
Done.
| |
88 virtual void CloseBubble(int caller_id) = 0; | |
Satish
2011/09/12 12:23:05
Since we are separating chrome/ from content/, we
allanwoj
2011/09/19 18:30:38
Done.
| |
89 virtual void SetBubbleWarmUpMode(int caller_id) = 0; | |
90 virtual void SetBubbleRecognizingMode(int caller_id) = 0; | |
91 virtual void SetBubbleRecordingMode(int caller_id) = 0; | |
92 virtual void SetBubbleInputVolume(int caller_id, | |
93 float volume, | |
94 float noise_volume) = 0; | |
95 virtual void HandleRecognizerError(int caller_id, | |
96 SpeechRecognizer::ErrorCode error) = 0; | |
97 | |
98 void OnFocusChanged(int caller_id); | |
Satish
2011/09/12 12:23:05
add explanatory comment since this is used by the
allanwoj
2011/09/19 18:30:38
Added comment but left the name as it is, as I hav
| |
99 | |
100 bool HasPendingRequest(int caller_id) const; | |
101 | |
102 // Starts/restarts recognition for an existing request. | |
103 void StartRecognitionForRequest(int caller_id); | |
104 | |
105 void CancelRecognitionAndInformDelegate(int caller_id); | |
106 | |
107 std::string request_info_; | |
108 bool can_report_metrics_; | |
109 | |
66 private: | 110 private: |
111 struct SpeechInputRequest { | |
112 SpeechInputRequest(); | |
113 ~SpeechInputRequest(); | |
114 | |
115 Delegate* delegate; | |
116 scoped_refptr<SpeechRecognizer> recognizer; | |
117 bool is_active; // Set to true when recording or recognition is going on. | |
118 }; | |
119 | |
120 Delegate* GetDelegate(int caller_id) const; | |
121 | |
122 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | |
123 SpeechRecognizerMap requests_; | |
124 int recording_caller_id_; | |
67 bool censor_results_; | 125 bool censor_results_; |
68 }; | 126 }; |
69 | 127 |
70 // This typedef is to workaround the issue with certain versions of | 128 // This typedef is to workaround the issue with certain versions of |
71 // Visual Studio where it gets confused between multiple Delegate | 129 // Visual Studio where it gets confused between multiple Delegate |
72 // classes and gives a C2500 error. (I saw this error on the try bots - | 130 // classes and gives a C2500 error. (I saw this error on the try bots - |
73 // the workaround was not needed for my machine). | 131 // the workaround was not needed for my machine). |
74 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; | 132 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; |
75 | 133 |
76 } // namespace speech_input | 134 } // namespace speech_input |
77 | 135 |
78 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 136 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
OLD | NEW |