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

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: Tommi's comments 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
20 namespace base {
21 class Thread;
22 }
23
19 namespace media { 24 namespace media {
20 class AudioBus; 25 class AudioBus;
21 class AudioManager; 26 class AudioManager;
27 class AudioParameters;
22 } 28 }
23 29
24 namespace content { 30 namespace content {
25 31
32 class SpeechRecognitionAudioReceiver;
26 class SpeechRecognitionEventListener; 33 class SpeechRecognitionEventListener;
27 34
28 // Handles speech recognition for a session (identified by |session_id|), taking 35 // Handles speech recognition for a session (identified by |session_id|), taking
29 // care of audio capture, silence detection/endpointer and interaction with the 36 // care of audio capture, silence detection/endpointer and interaction with the
30 // SpeechRecognitionEngine. 37 // SpeechRecognitionEngine.
31 class CONTENT_EXPORT SpeechRecognizerImpl 38 class CONTENT_EXPORT SpeechRecognizerImpl
32 : public SpeechRecognizer, 39 : public SpeechRecognizer,
33 public media::AudioInputController::EventHandler, 40 public media::AudioInputController::EventHandler,
34 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) { 41 public NON_EXPORTED_BASE(SpeechRecognitionEngineDelegate) {
35 public: 42 public:
36 static const int kAudioSampleRate; 43 static const int kAudioSampleRate;
37 static const media::ChannelLayout kChannelLayout; 44 static const media::ChannelLayout kChannelLayout;
38 static const int kNumBitsPerAudioSample; 45 static const int kNumBitsPerAudioSample;
39 static const int kNoSpeechTimeoutMs; 46 static const int kNoSpeechTimeoutMs;
40 static const int kEndpointerEstimationTimeMs; 47 static const int kEndpointerEstimationTimeMs;
41 48
42 static void SetAudioManagerForTesting(media::AudioManager* audio_manager); 49 static void SetAudioManagerForTesting(media::AudioManager* audio_manager);
43 50
44 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, 51 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener,
45 int session_id, 52 int session_id,
46 bool continuous, 53 bool continuous,
47 bool provisional_results, 54 bool provisional_results,
55 bool using_audio_receiver,
56 const base::ProcessHandle process_handle,
48 SpeechRecognitionEngine* engine); 57 SpeechRecognitionEngine* engine);
49 58
50 virtual void StartRecognition(const std::string& device_id) override; 59 virtual void StartRecognition(const std::string& device_id) override;
51 virtual void AbortRecognition() override; 60 virtual void AbortRecognition() override;
52 virtual void StopAudioCapture() override; 61 virtual void StopAudioCapture() override;
53 virtual bool IsActive() const override; 62 virtual bool IsActive() const override;
54 virtual bool IsCapturingAudio() const override; 63 virtual bool IsCapturingAudio() const override;
55 const SpeechRecognitionEngine& recognition_engine() const; 64 const SpeechRecognitionEngine& recognition_engine() const;
56 65
57 private: 66 private:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args); 118 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args);
110 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args); 119 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args);
111 FSMState ProcessFinalResult(const FSMEventArgs& event_args); 120 FSMState ProcessFinalResult(const FSMEventArgs& event_args);
112 FSMState AbortSilently(const FSMEventArgs& event_args); 121 FSMState AbortSilently(const FSMEventArgs& event_args);
113 FSMState AbortWithError(const FSMEventArgs& event_args); 122 FSMState AbortWithError(const FSMEventArgs& event_args);
114 FSMState Abort(const SpeechRecognitionError& error); 123 FSMState Abort(const SpeechRecognitionError& error);
115 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args); 124 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args);
116 FSMState DoNothing(const FSMEventArgs& event_args) const; 125 FSMState DoNothing(const FSMEventArgs& event_args) const;
117 FSMState NotFeasible(const FSMEventArgs& event_args); 126 FSMState NotFeasible(const FSMEventArgs& event_args);
118 127
128 // Called from |StartRecording()| when using |audio_receiver_|.
129 bool StartRecordingUsingAudioReceiver(const media::AudioParameters& params);
130
131 // Called when the session ends due to error or when being stopped.
132 void ResetAudioReceiver();
133
119 // Returns the time span of captured audio samples since the start of capture. 134 // Returns the time span of captured audio samples since the start of capture.
120 int GetElapsedTimeMs() const; 135 int GetElapsedTimeMs() const;
121 136
122 // Calculates the input volume to be displayed in the UI, triggering the 137 // Calculates the input volume to be displayed in the UI, triggering the
123 // OnAudioLevelsChange event accordingly. 138 // OnAudioLevelsChange event accordingly.
124 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); 139 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected);
125 140
126 void CloseAudioControllerAsynchronously(); 141 void CloseAudioControllerAsynchronously();
127 142
128 // Callback called on IO thread by audio_controller->Close(). 143 // Callback called on IO thread by audio_controller->Close().
(...skipping 18 matching lines...) Expand all
147 static media::AudioManager* audio_manager_for_tests_; 162 static media::AudioManager* audio_manager_for_tests_;
148 163
149 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; 164 scoped_ptr<SpeechRecognitionEngine> recognition_engine_;
150 Endpointer endpointer_; 165 Endpointer endpointer_;
151 scoped_refptr<media::AudioInputController> audio_controller_; 166 scoped_refptr<media::AudioInputController> audio_controller_;
152 scoped_ptr<media::AudioLog> audio_log_; 167 scoped_ptr<media::AudioLog> audio_log_;
153 int num_samples_recorded_; 168 int num_samples_recorded_;
154 float audio_level_; 169 float audio_level_;
155 bool is_dispatching_event_; 170 bool is_dispatching_event_;
156 bool provisional_results_; 171 bool provisional_results_;
172 bool using_audio_receiver_;
173 base::ProcessHandle peer_process_handle_;
157 FSMState state_; 174 FSMState state_;
158 std::string device_id_; 175 std::string device_id_;
159 176
160 class OnDataConverter; 177 class OnDataConverter;
161 178
162 // Converts data between native input format and a WebSpeech specific 179 // Converts data between native input format and a WebSpeech specific
163 // output format. 180 // output format.
164 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; 181 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_;
165 182
183 // Used when getting audio data from the renderer.
184 scoped_ptr<base::Thread> audio_thread_;
185 scoped_ptr<SpeechRecognitionAudioReceiver> audio_receiver_;
186
166 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); 187 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl);
167 }; 188 };
168 189
169 } // namespace content 190 } // namespace content
170 191
171 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 192 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698