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_RECOGNIZER_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 protected: | 80 protected: |
81 virtual ~Delegate() {} | 81 virtual ~Delegate() {} |
82 }; | 82 }; |
83 | 83 |
84 SpeechRecognizer(Delegate* delegate, | 84 SpeechRecognizer(Delegate* delegate, |
85 int caller_id, | 85 int caller_id, |
86 const std::string& language, | 86 const std::string& language, |
87 const std::string& grammar, | 87 const std::string& grammar, |
88 net::URLRequestContextGetter* context_getter, | 88 net::URLRequestContextGetter* context_getter, |
| 89 AudioManager* audio_manager, |
89 bool filter_profanities, | 90 bool filter_profanities, |
90 const std::string& hardware_info, | 91 const std::string& hardware_info, |
91 const std::string& origin_url); | 92 const std::string& origin_url); |
92 | 93 |
93 virtual ~SpeechRecognizer(); | 94 virtual ~SpeechRecognizer(); |
94 | 95 |
95 // Starts audio recording and does recognition after recording ends. The same | 96 // Starts audio recording and does recognition after recording ends. The same |
96 // SpeechRecognizer instance can be used multiple times for speech recognition | 97 // SpeechRecognizer instance can be used multiple times for speech recognition |
97 // though each recognition request can be made only after the previous one | 98 // though each recognition request can be made only after the previous one |
98 // completes (i.e. after receiving Delegate::DidCompleteRecognition). | 99 // completes (i.e. after receiving Delegate::DidCompleteRecognition). |
(...skipping 12 matching lines...) Expand all Loading... |
111 virtual void OnError(media::AudioInputController* controller, | 112 virtual void OnError(media::AudioInputController* controller, |
112 int error_code) OVERRIDE; | 113 int error_code) OVERRIDE; |
113 virtual void OnData(media::AudioInputController* controller, | 114 virtual void OnData(media::AudioInputController* controller, |
114 const uint8* data, | 115 const uint8* data, |
115 uint32 size) OVERRIDE; | 116 uint32 size) OVERRIDE; |
116 | 117 |
117 // SpeechRecognitionRequest::Delegate methods. | 118 // SpeechRecognitionRequest::Delegate methods. |
118 virtual void SetRecognitionResult( | 119 virtual void SetRecognitionResult( |
119 const content::SpeechInputResult& result) OVERRIDE; | 120 const content::SpeechInputResult& result) OVERRIDE; |
120 | 121 |
| 122 AudioManager* audio_manager() const { return audio_manager_; } |
| 123 |
121 static const int kAudioSampleRate; | 124 static const int kAudioSampleRate; |
122 static const int kAudioPacketIntervalMs; // Duration of each audio packet. | 125 static const int kAudioPacketIntervalMs; // Duration of each audio packet. |
123 static const ChannelLayout kChannelLayout; | 126 static const ChannelLayout kChannelLayout; |
124 static const int kNumBitsPerAudioSample; | 127 static const int kNumBitsPerAudioSample; |
125 static const int kNoSpeechTimeoutSec; | 128 static const int kNoSpeechTimeoutSec; |
126 static const int kEndpointerEstimationTimeMs; | 129 static const int kEndpointerEstimationTimeMs; |
127 | 130 |
128 private: | 131 private: |
129 void InformErrorAndCancelRecognition(content::SpeechInputError error); | 132 void InformErrorAndCancelRecognition(content::SpeechInputError error); |
130 void SendRecordedAudioToServer(); | 133 void SendRecordedAudioToServer(); |
131 | 134 |
132 void HandleOnError(int error_code); // Handles OnError in the IO thread. | 135 void HandleOnError(int error_code); // Handles OnError in the IO thread. |
133 | 136 |
134 // Handles OnData in the IO thread. Takes ownership of |data|. | 137 // Handles OnData in the IO thread. Takes ownership of |data|. |
135 void HandleOnData(std::string* data); | 138 void HandleOnData(std::string* data); |
136 | 139 |
137 Delegate* delegate_; | 140 Delegate* delegate_; |
138 int caller_id_; | 141 int caller_id_; |
139 std::string language_; | 142 std::string language_; |
140 std::string grammar_; | 143 std::string grammar_; |
141 bool filter_profanities_; | 144 bool filter_profanities_; |
142 std::string hardware_info_; | 145 std::string hardware_info_; |
143 std::string origin_url_; | 146 std::string origin_url_; |
144 | 147 |
145 scoped_ptr<SpeechRecognitionRequest> request_; | 148 scoped_ptr<SpeechRecognitionRequest> request_; |
146 scoped_refptr<media::AudioInputController> audio_controller_; | 149 scoped_refptr<media::AudioInputController> audio_controller_; |
147 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 150 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 151 scoped_refptr<AudioManager> audio_manager_; |
148 AudioEncoder::Codec codec_; | 152 AudioEncoder::Codec codec_; |
149 scoped_ptr<AudioEncoder> encoder_; | 153 scoped_ptr<AudioEncoder> encoder_; |
150 Endpointer endpointer_; | 154 Endpointer endpointer_; |
151 int num_samples_recorded_; | 155 int num_samples_recorded_; |
152 float audio_level_; | 156 float audio_level_; |
153 | 157 |
154 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | 158 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); |
155 }; | 159 }; |
156 | 160 |
157 // This typedef is to workaround the issue with certain versions of | 161 // This typedef is to workaround the issue with certain versions of |
158 // Visual Studio where it gets confused between multiple Delegate | 162 // Visual Studio where it gets confused between multiple Delegate |
159 // classes and gives a C2500 error. (I saw this error on the try bots - | 163 // classes and gives a C2500 error. (I saw this error on the try bots - |
160 // the workaround was not needed for my machine). | 164 // the workaround was not needed for my machine). |
161 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; | 165 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; |
162 | 166 |
163 } // namespace speech_input | 167 } // namespace speech_input |
164 | 168 |
165 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 169 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
OLD | NEW |