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

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: Audio Receiver unit test 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
44 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, 47 SpeechRecognizerImpl(SpeechRecognitionEventListener* listener,
45 int session_id, 48 int session_id,
46 bool continuous, 49 bool continuous,
47 bool provisional_results, 50 bool provisional_results,
51 bool using_audio_receiver,
52 const base::ProcessHandle process_handle,
48 SpeechRecognitionEngine* engine); 53 SpeechRecognitionEngine* engine);
49 54
50 virtual void StartRecognition(const std::string& device_id) override; 55 virtual void StartRecognition(const std::string& device_id) override;
51 virtual void AbortRecognition() override; 56 virtual void AbortRecognition() override;
52 virtual void StopAudioCapture() override; 57 virtual void StopAudioCapture() override;
53 virtual bool IsActive() const override; 58 virtual bool IsActive() const override;
54 virtual bool IsCapturingAudio() const override; 59 virtual bool IsCapturingAudio() const override;
55 const SpeechRecognitionEngine& recognition_engine() const; 60 const SpeechRecognitionEngine& recognition_engine() const;
56 61
57 private: 62 private:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args); 114 FSMState StopCaptureAndWaitForResult(const FSMEventArgs& event_args);
110 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args); 115 FSMState ProcessIntermediateResult(const FSMEventArgs& event_args);
111 FSMState ProcessFinalResult(const FSMEventArgs& event_args); 116 FSMState ProcessFinalResult(const FSMEventArgs& event_args);
112 FSMState AbortSilently(const FSMEventArgs& event_args); 117 FSMState AbortSilently(const FSMEventArgs& event_args);
113 FSMState AbortWithError(const FSMEventArgs& event_args); 118 FSMState AbortWithError(const FSMEventArgs& event_args);
114 FSMState Abort(const SpeechRecognitionError& error); 119 FSMState Abort(const SpeechRecognitionError& error);
115 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args); 120 FSMState DetectEndOfSpeech(const FSMEventArgs& event_args);
116 FSMState DoNothing(const FSMEventArgs& event_args) const; 121 FSMState DoNothing(const FSMEventArgs& event_args) const;
117 FSMState NotFeasible(const FSMEventArgs& event_args); 122 FSMState NotFeasible(const FSMEventArgs& event_args);
118 123
124 // Called from |StartRecording()| when using |audio_receiver_|.
125 bool StartRecordingUsingAudioReceiver(const media::AudioParameters& params);
126
119 // Returns the time span of captured audio samples since the start of capture. 127 // Returns the time span of captured audio samples since the start of capture.
120 int GetElapsedTimeMs() const; 128 int GetElapsedTimeMs() const;
121 129
122 // Calculates the input volume to be displayed in the UI, triggering the 130 // Calculates the input volume to be displayed in the UI, triggering the
123 // OnAudioLevelsChange event accordingly. 131 // OnAudioLevelsChange event accordingly.
124 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected); 132 void UpdateSignalAndNoiseLevels(const float& rms, bool clip_detected);
125 133
126 void CloseAudioControllerAsynchronously(); 134 void CloseAudioControllerAsynchronously();
127 135
128 // Callback called on IO thread by audio_controller->Close(). 136 // Callback called on IO thread by audio_controller->Close().
(...skipping 18 matching lines...) Expand all
147 static media::AudioManager* audio_manager_for_tests_; 155 static media::AudioManager* audio_manager_for_tests_;
148 156
149 scoped_ptr<SpeechRecognitionEngine> recognition_engine_; 157 scoped_ptr<SpeechRecognitionEngine> recognition_engine_;
150 Endpointer endpointer_; 158 Endpointer endpointer_;
151 scoped_refptr<media::AudioInputController> audio_controller_; 159 scoped_refptr<media::AudioInputController> audio_controller_;
152 scoped_ptr<media::AudioLog> audio_log_; 160 scoped_ptr<media::AudioLog> audio_log_;
153 int num_samples_recorded_; 161 int num_samples_recorded_;
154 float audio_level_; 162 float audio_level_;
155 bool is_dispatching_event_; 163 bool is_dispatching_event_;
156 bool provisional_results_; 164 bool provisional_results_;
165 bool using_audio_receiver_;
166 base::ProcessHandle peer_process_handle_;
157 FSMState state_; 167 FSMState state_;
158 std::string device_id_; 168 std::string device_id_;
159 169
160 class OnDataConverter; 170 class OnDataConverter;
161 171
162 // Converts data between native input format and a WebSpeech specific 172 // Converts data between native input format and a WebSpeech specific
163 // output format. 173 // output format.
164 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; 174 scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_;
165 175
176 // Used when getting audio data from the renderer.
177 scoped_ptr<SpeechRecognitionAudioReceiver> audio_receiver_;
178
166 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); 179 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl);
167 }; 180 };
168 181
169 } // namespace content 182 } // namespace content
170 183
171 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 184 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698