| 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> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "content/browser/speech/audio_encoder.h" | 14 #include "content/browser/speech/audio_encoder.h" |
| 15 #include "content/browser/speech/endpointer/endpointer.h" | 15 #include "content/browser/speech/endpointer/endpointer.h" |
| 16 #include "content/browser/speech/speech_recognition_request.h" | 16 #include "content/browser/speech/speech_recognition_request.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "media/audio/audio_input_controller.h" | 18 #include "media/audio/audio_input_controller.h" |
| 19 | 19 |
| 20 namespace net { |
| 21 class URLRequestContextGetter; |
| 22 } |
| 23 |
| 20 namespace speech_input { | 24 namespace speech_input { |
| 21 | 25 |
| 22 // Records audio, sends recorded audio to server and translates server response | 26 // Records audio, sends recorded audio to server and translates server response |
| 23 // to recognition result. | 27 // to recognition result. |
| 24 class CONTENT_EXPORT SpeechRecognizer | 28 class CONTENT_EXPORT SpeechRecognizer |
| 25 : public base::RefCountedThreadSafe<SpeechRecognizer>, | 29 : public base::RefCountedThreadSafe<SpeechRecognizer>, |
| 26 public media::AudioInputController::EventHandler, | 30 public media::AudioInputController::EventHandler, |
| 27 public SpeechRecognitionRequestDelegate { | 31 public SpeechRecognitionRequestDelegate { |
| 28 public: | 32 public: |
| 29 enum ErrorCode { | 33 enum ErrorCode { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 float noise_volume) = 0; | 80 float noise_volume) = 0; |
| 77 | 81 |
| 78 protected: | 82 protected: |
| 79 virtual ~Delegate() {} | 83 virtual ~Delegate() {} |
| 80 }; | 84 }; |
| 81 | 85 |
| 82 SpeechRecognizer(Delegate* delegate, | 86 SpeechRecognizer(Delegate* delegate, |
| 83 int caller_id, | 87 int caller_id, |
| 84 const std::string& language, | 88 const std::string& language, |
| 85 const std::string& grammar, | 89 const std::string& grammar, |
| 90 net::URLRequestContextGetter* context_getter, |
| 86 bool censor_results, | 91 bool censor_results, |
| 87 const std::string& hardware_info, | 92 const std::string& hardware_info, |
| 88 const std::string& origin_url); | 93 const std::string& origin_url); |
| 89 virtual ~SpeechRecognizer(); | 94 virtual ~SpeechRecognizer(); |
| 90 | 95 |
| 91 // Starts audio recording and does recognition after recording ends. The same | 96 // Starts audio recording and does recognition after recording ends. The same |
| 92 // SpeechRecognizer instance can be used multiple times for speech recognition | 97 // SpeechRecognizer instance can be used multiple times for speech recognition |
| 93 // 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 |
| 94 // completes (i.e. after receiving Delegate::DidCompleteRecognition). | 99 // completes (i.e. after receiving Delegate::DidCompleteRecognition). |
| 95 bool StartRecording(); | 100 bool StartRecording(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Delegate* delegate_; | 137 Delegate* delegate_; |
| 133 int caller_id_; | 138 int caller_id_; |
| 134 std::string language_; | 139 std::string language_; |
| 135 std::string grammar_; | 140 std::string grammar_; |
| 136 bool censor_results_; | 141 bool censor_results_; |
| 137 std::string hardware_info_; | 142 std::string hardware_info_; |
| 138 std::string origin_url_; | 143 std::string origin_url_; |
| 139 | 144 |
| 140 scoped_ptr<SpeechRecognitionRequest> request_; | 145 scoped_ptr<SpeechRecognitionRequest> request_; |
| 141 scoped_refptr<media::AudioInputController> audio_controller_; | 146 scoped_refptr<media::AudioInputController> audio_controller_; |
| 147 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 142 AudioEncoder::Codec codec_; | 148 AudioEncoder::Codec codec_; |
| 143 scoped_ptr<AudioEncoder> encoder_; | 149 scoped_ptr<AudioEncoder> encoder_; |
| 144 Endpointer endpointer_; | 150 Endpointer endpointer_; |
| 145 int num_samples_recorded_; | 151 int num_samples_recorded_; |
| 146 float audio_level_; | 152 float audio_level_; |
| 147 | 153 |
| 148 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | 154 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); |
| 149 }; | 155 }; |
| 150 | 156 |
| 151 // This typedef is to workaround the issue with certain versions of | 157 // This typedef is to workaround the issue with certain versions of |
| 152 // Visual Studio where it gets confused between multiple Delegate | 158 // Visual Studio where it gets confused between multiple Delegate |
| 153 // classes and gives a C2500 error. (I saw this error on the try bots - | 159 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 154 // the workaround was not needed for my machine). | 160 // the workaround was not needed for my machine). |
| 155 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; | 161 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; |
| 156 | 162 |
| 157 } // namespace speech_input | 163 } // namespace speech_input |
| 158 | 164 |
| 159 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 165 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
| OLD | NEW |