Chromium Code Reviews| 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_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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 : public base::RefCountedThreadSafe<SpeechRecognizer>, | 31 : public base::RefCountedThreadSafe<SpeechRecognizer>, |
| 32 public media::AudioInputController::EventHandler, | 32 public media::AudioInputController::EventHandler, |
| 33 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { | 33 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { |
| 34 public: | 34 public: |
| 35 static const int kAudioSampleRate; | 35 static const int kAudioSampleRate; |
| 36 static const ChannelLayout kChannelLayout; | 36 static const ChannelLayout kChannelLayout; |
| 37 static const int kNumBitsPerAudioSample; | 37 static const int kNumBitsPerAudioSample; |
| 38 static const int kNoSpeechTimeoutMs; | 38 static const int kNoSpeechTimeoutMs; |
| 39 static const int kEndpointerEstimationTimeMs; | 39 static const int kEndpointerEstimationTimeMs; |
| 40 | 40 |
| 41 static void SetAudioManagerForTests(media::AudioManager* audio_manager); | |
| 42 | |
| 41 SpeechRecognizer( | 43 SpeechRecognizer( |
| 42 content::SpeechRecognitionEventListener* listener, | 44 content::SpeechRecognitionEventListener* listener, |
| 43 int session_id, | 45 int session_id, |
| 44 bool is_single_shot, | 46 bool is_single_shot, |
| 45 SpeechRecognitionEngine* engine); | 47 SpeechRecognitionEngine* engine); |
| 46 | 48 |
| 47 void StartRecognition(); | 49 void StartRecognition(); |
| 48 void AbortRecognition(); | 50 void AbortRecognition(); |
| 49 void StopAudioCapture(); | 51 void StopAudioCapture(); |
| 50 bool IsActive() const; | 52 bool IsActive() const; |
| 51 bool IsCapturingAudio() const; | 53 bool IsCapturingAudio() const; |
| 52 const SpeechRecognitionEngine& recognition_engine() const; | 54 const SpeechRecognitionEngine& recognition_engine() const; |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 friend class base::RefCountedThreadSafe<SpeechRecognizer>; | 57 friend class base::RefCountedThreadSafe<SpeechRecognizer>; |
| 56 friend class SpeechRecognizerTest; | 58 friend class SpeechRecognizerTest; |
| 57 | 59 |
| 60 static media::AudioManager* audio_manager_for_tests_; | |
|
tommi (sloooow) - chröme
2012/07/11 11:12:30
nit: keep this down where the other variables are.
Primiano Tucci (use gerrit)
2012/07/11 14:33:30
Done.
| |
| 61 | |
| 58 enum FSMState { | 62 enum FSMState { |
| 59 STATE_IDLE = 0, | 63 STATE_IDLE = 0, |
| 60 STATE_STARTING, | 64 STATE_STARTING, |
| 61 STATE_ESTIMATING_ENVIRONMENT, | 65 STATE_ESTIMATING_ENVIRONMENT, |
| 62 STATE_WAITING_FOR_SPEECH, | 66 STATE_WAITING_FOR_SPEECH, |
| 63 STATE_RECOGNIZING, | 67 STATE_RECOGNIZING, |
| 64 STATE_WAITING_FINAL_RESULT, | 68 STATE_WAITING_FINAL_RESULT, |
| 65 STATE_MAX_VALUE = STATE_WAITING_FINAL_RESULT | 69 STATE_MAX_VALUE = STATE_WAITING_FINAL_RESULT |
| 66 }; | 70 }; |
| 67 | 71 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 FSMState NotFeasible(const FSMEventArgs& event_args); | 119 FSMState NotFeasible(const FSMEventArgs& event_args); |
| 116 | 120 |
| 117 // Returns the time span of captured audio samples since the start of capture. | 121 // Returns the time span of captured audio samples since the start of capture. |
| 118 int GetElapsedTimeMs() const; | 122 int GetElapsedTimeMs() const; |
| 119 | 123 |
| 120 // Calculates the input volume to be displayed in the UI, triggering the | 124 // Calculates the input volume to be displayed in the UI, triggering the |
| 121 // OnAudioLevelsChange event accordingly. | 125 // OnAudioLevelsChange event accordingly. |
| 122 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); | 126 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); |
| 123 | 127 |
| 124 void CloseAudioControllerAsynchronously(); | 128 void CloseAudioControllerAsynchronously(); |
| 125 void SetAudioManagerForTesting(media::AudioManager* audio_manager); | |
| 126 | 129 |
| 127 // Callback called on IO thread by audio_controller->Close(). | 130 // Callback called on IO thread by audio_controller->Close(). |
| 128 void OnAudioClosed(media::AudioInputController*); | 131 void OnAudioClosed(media::AudioInputController*); |
| 129 | 132 |
| 130 // AudioInputController::EventHandler methods. | 133 // AudioInputController::EventHandler methods. |
| 131 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {} | 134 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {} |
| 132 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {} | 135 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {} |
| 133 virtual void OnError(media::AudioInputController* controller, | 136 virtual void OnError(media::AudioInputController* controller, |
| 134 int error_code) OVERRIDE; | 137 int error_code) OVERRIDE; |
| 135 virtual void OnData(media::AudioInputController* controller, | 138 virtual void OnData(media::AudioInputController* controller, |
| 136 const uint8* data, uint32 size) OVERRIDE; | 139 const uint8* data, uint32 size) OVERRIDE; |
| 137 | 140 |
| 138 // SpeechRecognitionEngineDelegate methods. | 141 // SpeechRecognitionEngineDelegate methods. |
| 139 virtual void OnSpeechRecognitionEngineResult( | 142 virtual void OnSpeechRecognitionEngineResult( |
| 140 const content::SpeechRecognitionResult& result) OVERRIDE; | 143 const content::SpeechRecognitionResult& result) OVERRIDE; |
| 141 virtual void OnSpeechRecognitionEngineError( | 144 virtual void OnSpeechRecognitionEngineError( |
| 142 const content::SpeechRecognitionError& error) OVERRIDE; | 145 const content::SpeechRecognitionError& error) OVERRIDE; |
| 143 | 146 |
| 144 content::SpeechRecognitionEventListener* listener_; | 147 content::SpeechRecognitionEventListener* listener_; |
| 145 media::AudioManager* testing_audio_manager_; | |
| 146 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; | 148 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; |
| 147 Endpointer endpointer_; | 149 Endpointer endpointer_; |
| 148 scoped_refptr<media::AudioInputController> audio_controller_; | 150 scoped_refptr<media::AudioInputController> audio_controller_; |
| 149 int session_id_; | 151 int session_id_; |
| 150 int num_samples_recorded_; | 152 int num_samples_recorded_; |
| 151 float audio_level_; | 153 float audio_level_; |
| 152 bool is_dispatching_event_; | 154 bool is_dispatching_event_; |
| 153 bool is_single_shot_; | 155 bool is_single_shot_; |
| 154 FSMState state_; | 156 FSMState state_; |
| 155 | 157 |
| 156 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | 158 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 } // namespace speech | 161 } // namespace speech |
| 160 | 162 |
| 161 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 163 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
| OLD | NEW |