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_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_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 "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "content/public/browser/speech_recognition_event_listener.h" |
15 #include "content/public/browser/speech_recognition_manager.h" | 16 #include "content/public/browser/speech_recognition_manager.h" |
16 #include "content/public/browser/speech_recognizer_delegate.h" | |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 | 18 |
19 class AudioManager; | |
20 | |
21 namespace content { | 19 namespace content { |
22 class ResourceContext; | 20 class ResourceContext; |
23 class SpeechRecognitionManagerDelegate; | 21 class SpeechRecognitionManagerDelegate; |
24 class SpeechRecognitionPreferences; | 22 class SpeechRecognitionPreferences; |
25 struct SpeechRecognitionResult; | 23 struct SpeechRecognitionResult; |
| 24 class SpeechRecognizer; |
26 } | 25 } |
27 | 26 |
28 namespace net { | 27 namespace net { |
29 class URLRequestContextGetter; | 28 class URLRequestContextGetter; |
30 } | 29 } |
31 | 30 |
32 namespace speech { | 31 namespace speech { |
33 | 32 |
34 class InputTagSpeechDispatcherHost; | 33 class InputTagSpeechDispatcherHost; |
35 class SpeechRecognizerImpl; | |
36 | 34 |
37 class CONTENT_EXPORT SpeechRecognitionManagerImpl | 35 class CONTENT_EXPORT SpeechRecognitionManagerImpl |
38 : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), | 36 : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), |
39 NON_EXPORTED_BASE(public content::SpeechRecognizerDelegate) { | 37 NON_EXPORTED_BASE(public content::SpeechRecognitionEventListener) { |
40 public: | 38 public: |
41 static SpeechRecognitionManagerImpl* GetInstance(); | 39 static SpeechRecognitionManagerImpl* GetInstance(); |
42 | 40 |
43 // SpeechRecognitionManager implementation: | 41 // SpeechRecognitionManager implementation: |
44 virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; | 42 virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; |
45 virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; | 43 virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; |
46 virtual void FocusLostForRequest(int caller_id) OVERRIDE; | 44 virtual void FocusLostForRequest(int caller_id) OVERRIDE; |
47 virtual bool HasAudioInputDevices() OVERRIDE; | 45 virtual bool HasAudioInputDevices() OVERRIDE; |
48 virtual bool IsCapturingAudio() OVERRIDE; | 46 virtual bool IsCapturingAudio() OVERRIDE; |
49 virtual string16 GetAudioInputDeviceModel() OVERRIDE; | 47 virtual string16 GetAudioInputDeviceModel() OVERRIDE; |
(...skipping 16 matching lines...) Expand all Loading... |
66 const std::string& language, | 64 const std::string& language, |
67 const std::string& grammar, | 65 const std::string& grammar, |
68 const std::string& origin_url, | 66 const std::string& origin_url, |
69 net::URLRequestContextGetter* context_getter, | 67 net::URLRequestContextGetter* context_getter, |
70 content::SpeechRecognitionPreferences* speech_recognition_prefs); | 68 content::SpeechRecognitionPreferences* speech_recognition_prefs); |
71 virtual void CancelRecognition(int caller_id); | 69 virtual void CancelRecognition(int caller_id); |
72 virtual void CancelAllRequestsWithDelegate( | 70 virtual void CancelAllRequestsWithDelegate( |
73 InputTagSpeechDispatcherHost* delegate); | 71 InputTagSpeechDispatcherHost* delegate); |
74 virtual void StopRecording(int caller_id); | 72 virtual void StopRecording(int caller_id); |
75 | 73 |
76 // Overridden from content::SpeechRecognizerDelegate: | 74 // SpeechRecognitionEventListener methods. |
77 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; | 75 virtual void OnRecognitionStart(int caller_id) OVERRIDE; |
78 virtual void SetRecognitionResult( | 76 virtual void OnAudioStart(int caller_id) OVERRIDE; |
| 77 virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE; |
| 78 virtual void OnSoundStart(int caller_id) OVERRIDE; |
| 79 virtual void OnSoundEnd(int caller_id) OVERRIDE; |
| 80 virtual void OnAudioEnd(int caller_id) OVERRIDE; |
| 81 virtual void OnRecognitionEnd(int caller_id) OVERRIDE; |
| 82 virtual void OnRecognitionResult( |
79 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; | 83 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; |
80 virtual void DidCompleteRecording(int caller_id) OVERRIDE; | 84 virtual void OnRecognitionError( |
81 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; | 85 int caller_id, const content::SpeechRecognitionErrorCode& error) OVERRIDE; |
82 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; | 86 virtual void OnAudioLevelsChange( |
83 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; | 87 int caller_id, float volume, float noise_volume) OVERRIDE; |
84 | |
85 virtual void OnRecognizerError( | |
86 int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE; | |
87 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; | |
88 virtual void SetInputVolume(int caller_id, float volume, | |
89 float noise_volume) OVERRIDE; | |
90 | 88 |
91 protected: | 89 protected: |
92 // Private constructor to enforce singleton. | 90 // Private constructor to enforce singleton. |
93 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; | 91 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; |
94 SpeechRecognitionManagerImpl(); | 92 SpeechRecognitionManagerImpl(); |
95 virtual ~SpeechRecognitionManagerImpl(); | 93 virtual ~SpeechRecognitionManagerImpl(); |
96 | 94 |
97 bool HasPendingRequest(int caller_id) const; | 95 bool HasPendingRequest(int caller_id) const; |
98 | 96 |
99 private: | 97 private: |
100 struct Request { | 98 struct Request { |
101 Request(); | 99 Request(); |
102 ~Request(); | 100 ~Request(); |
103 | 101 |
104 InputTagSpeechDispatcherHost* delegate; | 102 InputTagSpeechDispatcherHost* delegate; |
105 scoped_refptr<SpeechRecognizerImpl> recognizer; | 103 scoped_refptr<content::SpeechRecognizer> recognizer; |
106 bool is_active; // Set to true when recording or recognition is going on. | 104 bool is_active; // Set to true when recording or recognition is going on. |
107 }; | 105 }; |
108 | 106 |
109 struct SpeechRecognitionParams; | 107 struct SpeechRecognitionParams; |
110 | 108 |
111 InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; | 109 InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; |
112 | 110 |
113 void CheckRenderViewTypeAndStartRecognition( | 111 void CheckRenderViewTypeAndStartRecognition( |
114 const SpeechRecognitionParams& params); | 112 const SpeechRecognitionParams& params); |
115 void ProceedStartingRecognition(const SpeechRecognitionParams& params); | 113 void ProceedStartingRecognition(const SpeechRecognitionParams& params); |
116 | 114 |
117 void CancelRecognitionAndInformDelegate(int caller_id); | 115 void CancelRecognitionAndInformDelegate(int caller_id); |
118 | 116 |
119 typedef std::map<int, Request> SpeechRecognizerMap; | 117 typedef std::map<int, Request> SpeechRecognizerMap; |
120 SpeechRecognizerMap requests_; | 118 SpeechRecognizerMap requests_; |
121 std::string request_info_; | 119 std::string request_info_; |
122 bool can_report_metrics_; | 120 bool can_report_metrics_; |
123 int recording_caller_id_; | 121 int recording_caller_id_; |
124 content::SpeechRecognitionManagerDelegate* delegate_; | 122 content::SpeechRecognitionManagerDelegate* delegate_; |
125 }; | 123 }; |
126 | 124 |
127 } // namespace speech | 125 } // namespace speech |
128 | 126 |
129 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ | 127 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
OLD | NEW |