Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: content/browser/speech/speech_recognizer_impl.h

Issue 549373003: Binding media stream audio track to speech recognition [browser] Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce SpeechRecognitionAudioReceiver Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/process/process_handle.h"
10 #include "content/browser/speech/endpointer/endpointer.h" 11 #include "content/browser/speech/endpointer/endpointer.h"
11 #include "content/browser/speech/speech_recognition_engine.h" 12 #include "content/browser/speech/speech_recognition_engine.h"
12 #include "content/browser/speech/speech_recognizer.h" 13 #include "content/browser/speech/speech_recognizer.h"
13 #include "content/public/common/speech_recognition_error.h" 14 #include "content/public/common/speech_recognition_error.h"
14 #include "content/public/common/speech_recognition_result.h" 15 #include "content/public/common/speech_recognition_result.h"
15 #include "media/audio/audio_input_controller.h" 16 #include "media/audio/audio_input_controller.h"
16 #include "media/audio/audio_logging.h" 17 #include "media/audio/audio_logging.h"
17 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
18 19
19 namespace media { 20 namespace media {
20 class AudioBus; 21 class AudioBus;
21 class AudioManager; 22 class AudioManager;
23 class AudioParameters;
22 } 24 }
23 25
24 namespace content { 26 namespace content {
25 27
28 class SpeechRecognitionAudioReceiver;
26 class SpeechRecognitionEventListener; 29 class SpeechRecognitionEventListener;
27 30
28 // Handles speech recognition for a session (identified by |session_id|), taking 31 // Handles speech recognition for a session (identified by |session_id|), taking
29 // care of audio capture, silence detection/endpointer and interaction with the 32 // care of audio capture, silence detection/endpointer and interaction with the
30 // SpeechRecognitionEngine. 33 // SpeechRecognitionEngine.
31 class CONTENT_EXPORT SpeechRecognizerImpl 34 class CONTENT_EXPORT SpeechRecognizerImpl
32 : public SpeechRecognizer, 35 : public SpeechRecognizer,
33 public media::AudioInputController::EventHandler, 36 public media::AudioInputController::EventHandler,
34 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { 37 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) {
35 public: 38 public:
36 static const int kAudioSampleRate; 39 static const int kAudioSampleRate;
37 static const media::ChannelLayout kChannelLayout; 40 static const media::ChannelLayout kChannelLayout;
38 static const int kNumBitsPerAudioSample; 41 static const int kNumBitsPerAudioSample;
39 static const int kNoSpeechTimeoutMs; 42 static const int kNoSpeechTimeoutMs;
40 static const int kEndpointerEstimationTimeMs; 43 static const int kEndpointerEstimationTimeMs;
41 44
42 static void SetAudioManagerForTesting(media::AudioManager* audio_manager); 45 static void SetAudioManagerForTesting(media::AudioManager* audio_manager);
43 46 // TODO(burnik): abstract out the process_handle. Pass differently.
44 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, 47 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, int session_id,
burnik 2014/10/15 14:52:27 Will move each param on it's own line.
45 int session_id, 48 bool continuous, bool provisional_results,
46 bool continuous, 49 bool using_audio_receiver,
47 bool provisional_results, 50 base::ProcessHandle process_handle,
48 SpeechRecognitionEngine* engine); 51 SpeechRecognitionEngine* engine);
49 52
50 virtual void StartRecognition(const std::string& device_id) OVERRIDE; 53 virtual void StartRecognition(const std::string& device_id) OVERRIDE;
51 virtual void AbortRecognition() OVERRIDE; 54 virtual void AbortRecognition() OVERRIDE;
52 virtual void StopAudioCapture() OVERRIDE; 55 virtual void StopAudioCapture() OVERRIDE;
53 virtual bool IsActive() const OVERRIDE; 56 virtual bool IsActive() const OVERRIDE;
54 virtual bool IsCapturingAudio() const OVERRIDE; 57 virtual bool IsCapturingAudio() const OVERRIDE;
55 const SpeechRecognitionEngine& recognition_engine() const; 58 const SpeechRecognitionEngine& recognition_engine() const;
56 59
57 private: 60 private:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args); 112 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args);
110 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args); 113 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args);
111 FSMState ProcessFinalResult(const FSMEventArgs& event_args); 114 FSMState ProcessFinalResult(const FSMEventArgs& event_args);
112 FSMState AbortSilently(const FSMEventArgs& event_args); 115 FSMState AbortSilently(const FSMEventArgs& event_args);
113 FSMState AbortWithError(const FSMEventArgs& event_args); 116 FSMState AbortWithError(const FSMEventArgs& event_args);
114 FSMState Abort(const SpeechRecognitionError& error); 117 FSMState Abort(const SpeechRecognitionError& error);
115 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args); 118 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args);
116 FSMState DoNothing(const FSMEventArgs& event_args) const; 119 FSMState DoNothing(const FSMEventArgs& event_args) const;
117 FSMState NotFeasible(const FSMEventArgs& event_args); 120 FSMState NotFeasible(const FSMEventArgs& event_args);
118 121
122 // Called from |StartRecording()| when using |audio_receiver_|.
123 bool StartRecordingUsingAudioReceiver(const media::AudioParameters& params);
124
119 // Returns the time span of captured audio samples since the start of capture. 125 // Returns the time span of captured audio samples since the start of capture.
120 int GetElapsedTimeMs() const; 126 int GetElapsedTimeMs() const;
121 127
122 // Calculates the input volume to be displayed in the UI, triggering the 128 // Calculates the input volume to be displayed in the UI, triggering the
123 // OnAudioLevelsChange event accordingly. 129 // OnAudioLevelsChange event accordingly.
124 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); 130 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected);
125 131
126 void CloseAudioControllerAsynchronously(); 132 void CloseAudioControllerAsynchronously();
127 133
128 // Callback called on IO thread by audio_controller->Close(). 134 // Callback called on IO thread by audio_controller->Close().
(...skipping 18 matching lines...) Expand all
147 static media::AudioManager* audio_manager_for_tests_; 153 static media::AudioManager* audio_manager_for_tests_;
148 154
149 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; 155 scoped_ptr<SpeechRecognitionEngine> recognition_engine_;
150 Endpointer endpointer_; 156 Endpointer endpointer_;
151 scoped_refptr<media::AudioInputController> audio_controller_; 157 scoped_refptr<media::AudioInputController> audio_controller_;
152 scoped_ptr<media::AudioLog> audio_log_; 158 scoped_ptr<media::AudioLog> audio_log_;
153 int num_samples_recorded_; 159 int num_samples_recorded_;
154 float audio_level_; 160 float audio_level_;
155 bool is_dispatching_event_; 161 bool is_dispatching_event_;
156 bool provisional_results_; 162 bool provisional_results_;
163 bool using_audio_receiver_;
164 base::ProcessHandle peer_process_handle_;
157 FSMState state_; 165 FSMState state_;
158 std::string device_id_; 166 std::string device_id_;
159 167
160 class OnDataConverter; 168 class OnDataConverter;
161 169
162 // Converts data between native input format and a WebSpeech specific 170 // Converts data between native input format and a WebSpeech specific
163 // output format. 171 // output format.
164 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; 172 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_;
165 173
174 // Used when getting audio data from the renderer.
175 scoped_ptr<SpeechRecognitionAudioReceiver> audio_receiver_;
176
166 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); 177 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl);
167 }; 178 };
168 179
169 } // namespace content 180 } // namespace content
170 181
171 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 182 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer.h ('k') | content/browser/speech/speech_recognizer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698