Index: content/browser/speech/speech_recognizer_impl.h |
diff --git a/content/browser/speech/speech_recognizer_impl.h b/content/browser/speech/speech_recognizer_impl.h |
index 48196c3ae77f377dcea64cf2073e259afaeed827..66203079aa82eb6f8d033988de3a15d47c174dd8 100644 |
--- a/content/browser/speech/speech_recognizer_impl.h |
+++ b/content/browser/speech/speech_recognizer_impl.h |
@@ -6,27 +6,28 @@ |
#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ |
#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "content/browser/speech/endpointer/endpointer.h" |
#include "content/browser/speech/speech_recognition_engine.h" |
#include "content/public/browser/speech_recognizer.h" |
#include "content/public/common/speech_recognition_error.h" |
+#include "content/public/common/speech_recognition_result.h" |
#include "media/audio/audio_input_controller.h" |
#include "net/url_request/url_request_context_getter.h" |
namespace content { |
class SpeechRecognitionEventListener; |
-struct SpeechRecognitionResult; |
-} |
- |
-namespace media { |
-class AudioInputController; |
} |
namespace speech { |
+// TODO(primiano) Next CL: Remove the Impl suffix and the exported |
+// /content/public/browser/speech_recognizer.h interface since this class should |
+// not be visible outside (currently we need it for speech input extension API). |
-// Records audio, sends recorded audio to server and translates server response |
-// to recognition result. |
+// Handles speech recognition for a session (identified by |caller_id|), taking |
+// care of audio capture, silence detection/endpointer and interaction with the |
+// SpeechRecognitionEngine. |
class CONTENT_EXPORT SpeechRecognizerImpl |
: public NON_EXPORTED_BASE(content::SpeechRecognizer), |
public media::AudioInputController::EventHandler, |
@@ -39,14 +40,9 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
static const int kEndpointerEstimationTimeMs; |
SpeechRecognizerImpl( |
- content::SpeechRecognitionEventListener* listener, |
- int caller_id, |
- const std::string& language, |
- const std::string& grammar, |
- net::URLRequestContextGetter* context_getter, |
- bool filter_profanities, |
- const std::string& hardware_info, |
- const std::string& origin_url); |
+ content::SpeechRecognitionEventListener* listener, |
+ int caller_id, |
+ SpeechRecognitionEngine* engine); |
virtual ~SpeechRecognizerImpl(); |
// content::SpeechRecognizer methods. |
@@ -57,14 +53,45 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
virtual bool IsCapturingAudio() const OVERRIDE; |
const SpeechRecognitionEngine& recognition_engine() const; |
+ private: |
+ friend class SpeechRecognizerImplTest; |
+ |
+ enum FSMState { |
+ kIdle = 0, |
Satish
2012/03/27 09:47:42
enum values should be MACRO_STYLE
http://dev.chrom
Primiano Tucci (use gerrit)
2012/03/28 13:24:44
Done.
|
+ kStartingRecognition, |
+ kEstimatingEnvironment, |
+ kWaitingForSpeech, |
+ kRecognizingSpeech, |
+ kWaitingFinalResult, |
+ kMaxState = kWaitingFinalResult |
+ }; |
+ |
+ enum FSMEvent { |
+ kAbortRequest = 0, |
Satish
2012/03/27 09:47:42
seems like we can drop the 'Request' suffix in the
Primiano Tucci (use gerrit)
2012/03/28 13:24:44
I added the suffix because their name should repre
|
+ kStartRequest, |
+ kStopCaptureRequest, |
+ kAudioData, |
+ kRecognitionResult, |
+ kRecognitionError, |
+ kAudioError, |
+ kMaxEvent = kAudioError |
+ }; |
+ |
+ struct FSMEventArgs { |
+ int audio_error_code; |
+ AudioChunk* audio_data; |
+ content::SpeechRecognitionResult speech_result; |
+ content::SpeechRecognitionError error; |
Satish
2012/03/27 09:47:42
change to speech_error
Primiano Tucci (use gerrit)
2012/03/28 13:24:44
Done.
|
+ FSMEventArgs(); |
+ }; |
+ |
// AudioInputController::EventHandler methods. |
virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {} |
virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {} |
virtual void OnError(media::AudioInputController* controller, |
int error_code) OVERRIDE; |
virtual void OnData(media::AudioInputController* controller, |
- const uint8* data, |
- uint32 size) OVERRIDE; |
+ const uint8* data, uint32 size) OVERRIDE; |
// SpeechRecognitionEngineDelegate methods. |
virtual void OnSpeechRecognitionEngineResult( |
@@ -72,21 +99,24 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
virtual void OnSpeechRecognitionEngineError( |
const content::SpeechRecognitionError& error) OVERRIDE; |
- private: |
- friend class SpeechRecognizerImplTest; |
- |
- void InformErrorAndAbortRecognition( |
- content::SpeechRecognitionErrorCode error); |
- void SendRecordedAudioToServer(); |
- |
- void HandleOnError(int error_code); // Handles OnError in the IO thread. |
- |
- // Handles OnData in the IO thread. Takes ownership of |raw_audio|. |
- void HandleOnData(AudioChunk* raw_audio); |
- |
- // Helper method which closes the audio controller and blocks until done. |
+ void DispatchEvent(FSMEvent event, FSMEventArgs); |
+ void ProcessAudioPipeline(); |
+ FSMState ProcessEvent(FSMEvent event); |
+ FSMState InitializeAndStartRecording(); |
Satish
2012/03/27 09:47:42
rename to StartRecording
Primiano Tucci (use gerrit)
2012/03/28 13:24:44
Done.
|
+ FSMState StartSpeechRecognition(); |
Satish
2012/03/27 09:47:42
rename to StartRecognitionEngine
Primiano Tucci (use gerrit)
2012/03/28 13:24:44
Done.
|
+ FSMState EnvironmentEstimation(); |
+ FSMState DetectUserSpeechOrTimeout(); |
+ FSMState StopCaptureAndWaitForResult(); |
+ FSMState ProcessIntermediateRecognitionResult(); |
+ FSMState ProcessFinalRecognitionResult(); |
+ FSMState Abort(); |
+ FSMState Abort(const content::SpeechRecognitionError& error); |
+ FSMState Abort(bool has_error, const content::SpeechRecognitionError& error); |
+ FSMState DetectEndOfSpeech(); |
+ FSMState DoNothing() const; |
+ int GetElapsedTimeMs() const; |
+ void UpdateSignalAndNoiseLevels(const float& rms); |
void CloseAudioControllerSynchronously(); |
- |
void SetAudioManagerForTesting(AudioManager* audio_manager); |
content::SpeechRecognitionEventListener* listener_; |
@@ -94,15 +124,15 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
scoped_ptr<SpeechRecognitionEngine> recognition_engine_; |
Endpointer endpointer_; |
scoped_refptr<media::AudioInputController> audio_controller_; |
- scoped_refptr<net::URLRequestContextGetter> context_getter_; |
int caller_id_; |
- std::string language_; |
- std::string grammar_; |
- bool filter_profanities_; |
- std::string hardware_info_; |
- std::string origin_url_; |
int num_samples_recorded_; |
+ bool clipper_detected_clip_; |
float audio_level_; |
+ float rms_; |
+ int event_dispatch_nesting_level_; |
+ FSMState state_; |
+ FSMEvent event_; |
+ FSMEventArgs* event_args_; |
DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); |
}; |