OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 6 #define CHROME_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/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "chrome/browser/speech/audio_encoder.h" |
14 #include "chrome/browser/speech/endpointer/endpointer.h" | 15 #include "chrome/browser/speech/endpointer/endpointer.h" |
15 #include "chrome/browser/speech/speech_recognition_request.h" | 16 #include "chrome/browser/speech/speech_recognition_request.h" |
16 #include "media/audio/audio_input_controller.h" | 17 #include "media/audio/audio_input_controller.h" |
17 | 18 |
18 namespace speech_input { | 19 namespace speech_input { |
19 | 20 |
20 class SpeexEncoder; | |
21 | |
22 // Records audio, sends recorded audio to server and translates server response | 21 // Records audio, sends recorded audio to server and translates server response |
23 // to recognition result. | 22 // to recognition result. |
24 class SpeechRecognizer | 23 class SpeechRecognizer |
25 : public base::RefCountedThreadSafe<SpeechRecognizer>, | 24 : public base::RefCountedThreadSafe<SpeechRecognizer>, |
26 public media::AudioInputController::EventHandler, | 25 public media::AudioInputController::EventHandler, |
27 public SpeechRecognitionRequestDelegate { | 26 public SpeechRecognitionRequestDelegate { |
28 public: | 27 public: |
29 enum ErrorCode { | 28 enum ErrorCode { |
30 RECOGNIZER_NO_ERROR, | 29 RECOGNIZER_NO_ERROR, |
31 RECOGNIZER_ERROR_CAPTURE, | 30 RECOGNIZER_ERROR_CAPTURE, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 120 |
122 // Handles OnData in the IO thread. Takes ownership of |data|. | 121 // Handles OnData in the IO thread. Takes ownership of |data|. |
123 void HandleOnData(std::string* data); | 122 void HandleOnData(std::string* data); |
124 | 123 |
125 Delegate* delegate_; | 124 Delegate* delegate_; |
126 int caller_id_; | 125 int caller_id_; |
127 std::string language_; | 126 std::string language_; |
128 std::string grammar_; | 127 std::string grammar_; |
129 std::string hardware_info_; | 128 std::string hardware_info_; |
130 | 129 |
131 // Buffer holding the recorded audio. Owns the strings inside the list. | |
132 typedef std::list<std::string*> AudioBufferQueue; | |
133 AudioBufferQueue audio_buffers_; | |
134 | |
135 scoped_ptr<SpeechRecognitionRequest> request_; | 130 scoped_ptr<SpeechRecognitionRequest> request_; |
136 scoped_refptr<media::AudioInputController> audio_controller_; | 131 scoped_refptr<media::AudioInputController> audio_controller_; |
137 scoped_ptr<SpeexEncoder> encoder_; | 132 AudioEncoder::Codec codec_; |
| 133 scoped_ptr<AudioEncoder> encoder_; |
138 Endpointer endpointer_; | 134 Endpointer endpointer_; |
139 int num_samples_recorded_; | 135 int num_samples_recorded_; |
140 float audio_level_; | 136 float audio_level_; |
141 | 137 |
142 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | 138 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); |
143 }; | 139 }; |
144 | 140 |
145 // This typedef is to workaround the issue with certain versions of | 141 // This typedef is to workaround the issue with certain versions of |
146 // Visual Studio where it gets confused between multiple Delegate | 142 // Visual Studio where it gets confused between multiple Delegate |
147 // classes and gives a C2500 error. (I saw this error on the try bots - | 143 // classes and gives a C2500 error. (I saw this error on the try bots - |
148 // the workaround was not needed for my machine). | 144 // the workaround was not needed for my machine). |
149 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; | 145 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; |
150 | 146 |
151 } // namespace speech_input | 147 } // namespace speech_input |
152 | 148 |
153 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 149 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
OLD | NEW |