| 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_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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/browser/speech/endpointer/endpointer.h" | 12 #include "content/browser/speech/endpointer/endpointer.h" |
| 13 #include "content/browser/speech/speech_recognition_engine.h" | 13 #include "content/browser/speech/speech_recognition_engine.h" |
| 14 #include "content/public/browser/speech_recognizer.h" | |
| 15 #include "content/public/common/speech_recognition_error.h" | 14 #include "content/public/common/speech_recognition_error.h" |
| 16 #include "content/public/common/speech_recognition_result.h" | 15 #include "content/public/common/speech_recognition_result.h" |
| 17 #include "media/audio/audio_input_controller.h" | 16 #include "media/audio/audio_input_controller.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 class SpeechRecognitionEventListener; | 20 class SpeechRecognitionEventListener; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace media { | 23 namespace media { |
| 25 class AudioManager; | 24 class AudioManager; |
| 26 } | 25 } |
| 27 | 26 |
| 28 namespace speech { | 27 namespace speech { |
| 29 | 28 |
| 30 // TODO(primiano) Next CL: Remove the Impl suffix and the exported | 29 // TODO(primiano) Next CL: Remove the Impl suffix. |
| 31 // /content/public/browser/speech_recognizer.h interface since this class should | |
| 32 // not be visible outside (currently we need it for speech input extension API). | |
| 33 | 30 |
| 34 // Handles speech recognition for a session (identified by |session_id|), taking | 31 // Handles speech recognition for a session (identified by |session_id|), taking |
| 35 // care of audio capture, silence detection/endpointer and interaction with the | 32 // care of audio capture, silence detection/endpointer and interaction with the |
| 36 // SpeechRecognitionEngine. | 33 // SpeechRecognitionEngine. |
| 37 class CONTENT_EXPORT SpeechRecognizerImpl | 34 class CONTENT_EXPORT SpeechRecognizerImpl |
| 38 : public NON_EXPORTED_BASE(content::SpeechRecognizer), | 35 : public base::RefCountedThreadSafe<SpeechRecognizerImpl>, |
| 39 public media::AudioInputController::EventHandler, | 36 public media::AudioInputController::EventHandler, |
| 40 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { | 37 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { |
| 41 public: | 38 public: |
| 42 static const int kAudioSampleRate; | 39 static const int kAudioSampleRate; |
| 43 static const ChannelLayout kChannelLayout; | 40 static const ChannelLayout kChannelLayout; |
| 44 static const int kNumBitsPerAudioSample; | 41 static const int kNumBitsPerAudioSample; |
| 45 static const int kNoSpeechTimeoutMs; | 42 static const int kNoSpeechTimeoutMs; |
| 46 static const int kEndpointerEstimationTimeMs; | 43 static const int kEndpointerEstimationTimeMs; |
| 47 | 44 |
| 48 SpeechRecognizerImpl( | 45 SpeechRecognizerImpl( |
| 49 content::SpeechRecognitionEventListener* listener, | 46 content::SpeechRecognitionEventListener* listener, |
| 50 int session_id, | 47 int session_id, |
| 51 SpeechRecognitionEngine* engine); | 48 SpeechRecognitionEngine* engine); |
| 52 | 49 |
| 53 // content::SpeechRecognizer methods. | 50 void StartRecognition(); |
| 54 virtual void StartRecognition() OVERRIDE; | 51 void AbortRecognition(); |
| 55 virtual void AbortRecognition() OVERRIDE; | 52 void StopAudioCapture(); |
| 56 virtual void StopAudioCapture() OVERRIDE; | 53 bool IsActive() const; |
| 57 virtual bool IsActive() const OVERRIDE; | 54 bool IsCapturingAudio() const; |
| 58 virtual bool IsCapturingAudio() const OVERRIDE; | |
| 59 const SpeechRecognitionEngine& recognition_engine() const; | 55 const SpeechRecognitionEngine& recognition_engine() const; |
| 60 | 56 |
| 61 protected: | |
| 62 virtual ~SpeechRecognizerImpl(); | |
| 63 | |
| 64 private: | 57 private: |
| 58 friend class base::RefCountedThreadSafe<SpeechRecognizerImpl>; |
| 65 friend class SpeechRecognizerImplTest; | 59 friend class SpeechRecognizerImplTest; |
| 66 | 60 |
| 67 enum FSMState { | 61 enum FSMState { |
| 68 STATE_IDLE = 0, | 62 STATE_IDLE = 0, |
| 69 STATE_STARTING, | 63 STATE_STARTING, |
| 70 STATE_ESTIMATING_ENVIRONMENT, | 64 STATE_ESTIMATING_ENVIRONMENT, |
| 71 STATE_WAITING_FOR_SPEECH, | 65 STATE_WAITING_FOR_SPEECH, |
| 72 STATE_RECOGNIZING, | 66 STATE_RECOGNIZING, |
| 73 STATE_WAITING_FINAL_RESULT, | 67 STATE_WAITING_FINAL_RESULT, |
| 74 STATE_MAX_VALUE = STATE_WAITING_FINAL_RESULT | 68 STATE_MAX_VALUE = STATE_WAITING_FINAL_RESULT |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 explicit FSMEventArgs(FSMEvent event_value); | 83 explicit FSMEventArgs(FSMEvent event_value); |
| 90 ~FSMEventArgs(); | 84 ~FSMEventArgs(); |
| 91 | 85 |
| 92 FSMEvent event; | 86 FSMEvent event; |
| 93 int audio_error_code; | 87 int audio_error_code; |
| 94 scoped_refptr<AudioChunk> audio_data; | 88 scoped_refptr<AudioChunk> audio_data; |
| 95 content::SpeechRecognitionResult engine_result; | 89 content::SpeechRecognitionResult engine_result; |
| 96 content::SpeechRecognitionError engine_error; | 90 content::SpeechRecognitionError engine_error; |
| 97 }; | 91 }; |
| 98 | 92 |
| 93 virtual ~SpeechRecognizerImpl(); |
| 94 |
| 99 // Entry point for pushing any new external event into the recognizer FSM. | 95 // Entry point for pushing any new external event into the recognizer FSM. |
| 100 void DispatchEvent(const FSMEventArgs& event_args); | 96 void DispatchEvent(const FSMEventArgs& event_args); |
| 101 | 97 |
| 102 // Defines the behavior of the recognizer FSM, selecting the appropriate | 98 // Defines the behavior of the recognizer FSM, selecting the appropriate |
| 103 // transition according to the current state and event. | 99 // transition according to the current state and event. |
| 104 FSMState ExecuteTransitionAndGetNextState(const FSMEventArgs& args); | 100 FSMState ExecuteTransitionAndGetNextState(const FSMEventArgs& args); |
| 105 | 101 |
| 106 // Process a new audio chunk in the audio pipeline (endpointer, vumeter, etc). | 102 // Process a new audio chunk in the audio pipeline (endpointer, vumeter, etc). |
| 107 void ProcessAudioPipeline(const AudioChunk& raw_audio); | 103 void ProcessAudioPipeline(const AudioChunk& raw_audio); |
| 108 | 104 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 float audio_level_; | 154 float audio_level_; |
| 159 bool is_dispatching_event_; | 155 bool is_dispatching_event_; |
| 160 FSMState state_; | 156 FSMState state_; |
| 161 | 157 |
| 162 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); | 158 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); |
| 163 }; | 159 }; |
| 164 | 160 |
| 165 } // namespace speech | 161 } // namespace speech |
| 166 | 162 |
| 167 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ | 163 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ |
| OLD | NEW |