| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/browser/speech/endpointer/endpointer.h" | 10 #include "content/browser/speech/endpointer/endpointer.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 static const int kEndpointerEstimationTimeMs; | 40 static const int kEndpointerEstimationTimeMs; |
| 41 | 41 |
| 42 static void SetAudioManagerForTesting(media::AudioManager* audio_manager); | 42 static void SetAudioManagerForTesting(media::AudioManager* audio_manager); |
| 43 | 43 |
| 44 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, | 44 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, |
| 45 int session_id, | 45 int session_id, |
| 46 bool continuous, | 46 bool continuous, |
| 47 bool provisional_results, | 47 bool provisional_results, |
| 48 SpeechRecognitionEngine* engine); | 48 SpeechRecognitionEngine* engine); |
| 49 | 49 |
| 50 virtual void StartRecognition(const std::string& device_id) override; | 50 void StartRecognition(const std::string& device_id) override; |
| 51 virtual void AbortRecognition() override; | 51 void AbortRecognition() override; |
| 52 virtual void StopAudioCapture() override; | 52 void StopAudioCapture() override; |
| 53 virtual bool IsActive() const override; | 53 bool IsActive() const override; |
| 54 virtual bool IsCapturingAudio() const override; | 54 bool IsCapturingAudio() const override; |
| 55 const SpeechRecognitionEngine& recognition_engine() const; | 55 const SpeechRecognitionEngine& recognition_engine() const; |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 friend class SpeechRecognizerTest; | 58 friend class SpeechRecognizerTest; |
| 59 | 59 |
| 60 enum FSMState { | 60 enum FSMState { |
| 61 STATE_IDLE = 0, | 61 STATE_IDLE = 0, |
| 62 STATE_STARTING, | 62 STATE_STARTING, |
| 63 STATE_ESTIMATING_ENVIRONMENT, | 63 STATE_ESTIMATING_ENVIRONMENT, |
| 64 STATE_WAITING_FOR_SPEECH, | 64 STATE_WAITING_FOR_SPEECH, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 struct FSMEventArgs { | 82 struct FSMEventArgs { |
| 83 explicit FSMEventArgs(FSMEvent event_value); | 83 explicit FSMEventArgs(FSMEvent event_value); |
| 84 ~FSMEventArgs(); | 84 ~FSMEventArgs(); |
| 85 | 85 |
| 86 FSMEvent event; | 86 FSMEvent event; |
| 87 scoped_refptr<AudioChunk> audio_data; | 87 scoped_refptr<AudioChunk> audio_data; |
| 88 SpeechRecognitionResults engine_results; | 88 SpeechRecognitionResults engine_results; |
| 89 SpeechRecognitionError engine_error; | 89 SpeechRecognitionError engine_error; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 virtual ~SpeechRecognizerImpl(); | 92 ~SpeechRecognizerImpl() override; |
| 93 | 93 |
| 94 // Entry point for pushing any new external event into the recognizer FSM. | 94 // Entry point for pushing any new external event into the recognizer FSM. |
| 95 void DispatchEvent(const FSMEventArgs& event_args); | 95 void DispatchEvent(const FSMEventArgs& event_args); |
| 96 | 96 |
| 97 // Defines the behavior of the recognizer FSM, selecting the appropriate | 97 // Defines the behavior of the recognizer FSM, selecting the appropriate |
| 98 // transition according to the current state and event. | 98 // transition according to the current state and event. |
| 99 FSMState ExecuteTransitionAndGetNextState(const FSMEventArgs& args); | 99 FSMState ExecuteTransitionAndGetNextState(const FSMEventArgs& args); |
| 100 | 100 |
| 101 // Process a new audio chunk in the audio pipeline (endpointer, vumeter, etc). | 101 // Process a new audio chunk in the audio pipeline (endpointer, vumeter, etc). |
| 102 void ProcessAudioPipeline(const AudioChunk& raw_audio); | 102 void ProcessAudioPipeline(const AudioChunk& raw_audio); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 // Calculates the input volume to be displayed in the UI, triggering the | 122 // Calculates the input volume to be displayed in the UI, triggering the |
| 123 // OnAudioLevelsChange event accordingly. | 123 // OnAudioLevelsChange event accordingly. |
| 124 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); | 124 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); |
| 125 | 125 |
| 126 void CloseAudioControllerAsynchronously(); | 126 void CloseAudioControllerAsynchronously(); |
| 127 | 127 |
| 128 // Callback called on IO thread by audio_controller->Close(). | 128 // Callback called on IO thread by audio_controller->Close(). |
| 129 void OnAudioClosed(media::AudioInputController*); | 129 void OnAudioClosed(media::AudioInputController*); |
| 130 | 130 |
| 131 // AudioInputController::EventHandler methods. | 131 // AudioInputController::EventHandler methods. |
| 132 virtual void OnCreated(media::AudioInputController* controller) override {} | 132 void OnCreated(media::AudioInputController* controller) override {} |
| 133 virtual void OnRecording(media::AudioInputController* controller) override {} | 133 void OnRecording(media::AudioInputController* controller) override {} |
| 134 virtual void OnError(media::AudioInputController* controller, | 134 void OnError(media::AudioInputController* controller, |
| 135 media::AudioInputController::ErrorCode error_code) override; | 135 media::AudioInputController::ErrorCode error_code) override; |
| 136 virtual void OnData(media::AudioInputController* controller, | 136 void OnData(media::AudioInputController* controller, |
| 137 const media::AudioBus* data) override; | 137 const media::AudioBus* data) override; |
| 138 virtual void OnLog(media::AudioInputController* controller, | 138 void OnLog(media::AudioInputController* controller, |
| 139 const std::string& message) override {} | 139 const std::string& message) override {} |
| 140 | 140 |
| 141 // SpeechRecognitionEngineDelegate methods. | 141 // SpeechRecognitionEngineDelegate methods. |
| 142 virtual void OnSpeechRecognitionEngineResults( | 142 void OnSpeechRecognitionEngineResults( |
| 143 const SpeechRecognitionResults& results) override; | 143 const SpeechRecognitionResults& results) override; |
| 144 virtual void OnSpeechRecognitionEngineError( | 144 void OnSpeechRecognitionEngineError( |
| 145 const SpeechRecognitionError& error) override; | 145 const SpeechRecognitionError& error) override; |
| 146 | 146 |
| 147 static media::AudioManager* audio_manager_for_tests_; | 147 static media::AudioManager* audio_manager_for_tests_; |
| 148 | 148 |
| 149 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; | 149 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; |
| 150 Endpointer endpointer_; | 150 Endpointer endpointer_; |
| 151 scoped_refptr<media::AudioInputController> audio_controller_; | 151 scoped_refptr<media::AudioInputController> audio_controller_; |
| 152 scoped_ptr<media::AudioLog> audio_log_; | 152 scoped_ptr<media::AudioLog> audio_log_; |
| 153 int num_samples_recorded_; | 153 int num_samples_recorded_; |
| 154 float audio_level_; | 154 float audio_level_; |
| 155 bool is_dispatching_event_; | 155 bool is_dispatching_event_; |
| 156 bool provisional_results_; | 156 bool provisional_results_; |
| 157 FSMState state_; | 157 FSMState state_; |
| 158 std::string device_id_; | 158 std::string device_id_; |
| 159 | 159 |
| 160 class OnDataConverter; | 160 class OnDataConverter; |
| 161 | 161 |
| 162 // Converts data between native input format and a WebSpeech specific | 162 // Converts data between native input format and a WebSpeech specific |
| 163 // output format. | 163 // output format. |
| 164 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; | 164 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; |
| 165 | 165 |
| 166 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); | 166 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 } // namespace content | 169 } // namespace content |
| 170 | 170 |
| 171 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ | 171 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ |
| OLD | NEW |