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

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

Issue 2785463005: Removing AudioSystem::GetAudioManager() usage from speech recognition (Closed)
Patch Set: Created 3 years, 8 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 #include "content/browser/speech/speech_recognizer_impl.h" 5 #include "content/browser/speech/speech_recognizer_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 } // namespace 108 } // namespace
109 109
110 const int SpeechRecognizerImpl::kAudioSampleRate = 16000; 110 const int SpeechRecognizerImpl::kAudioSampleRate = 16000;
111 const ChannelLayout SpeechRecognizerImpl::kChannelLayout = 111 const ChannelLayout SpeechRecognizerImpl::kChannelLayout =
112 media::CHANNEL_LAYOUT_MONO; 112 media::CHANNEL_LAYOUT_MONO;
113 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16; 113 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16;
114 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000; 114 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000;
115 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300; 115 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300;
116 media::AudioSystem* SpeechRecognizerImpl::audio_system_for_tests_ = nullptr; 116 media::AudioSystem* SpeechRecognizerImpl::audio_system_for_tests_ = nullptr;
117 media::AudioManager* SpeechRecognizerImpl::audio_manager_for_tests_ = nullptr;
117 118
118 static_assert(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0, 119 static_assert(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0,
119 "kNumBitsPerAudioSample must be a multiple of 8"); 120 "kNumBitsPerAudioSample must be a multiple of 8");
120 121
121 // SpeechRecognizerImpl::OnDataConverter implementation 122 // SpeechRecognizerImpl::OnDataConverter implementation
122 123
123 SpeechRecognizerImpl::OnDataConverter::OnDataConverter( 124 SpeechRecognizerImpl::OnDataConverter::OnDataConverter(
124 const AudioParameters& input_params, 125 const AudioParameters& input_params,
125 const AudioParameters& output_params) 126 const AudioParameters& output_params)
126 : audio_converter_(input_params, output_params, false), 127 : audio_converter_(input_params, output_params, false),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Indicate that the recorded audio has in fact been used by the converter. 172 // Indicate that the recorded audio has in fact been used by the converter.
172 data_was_converted_ = true; 173 data_was_converted_ = true;
173 return 1; 174 return 1;
174 } 175 }
175 176
176 // SpeechRecognizerImpl implementation 177 // SpeechRecognizerImpl implementation
177 178
178 SpeechRecognizerImpl::SpeechRecognizerImpl( 179 SpeechRecognizerImpl::SpeechRecognizerImpl(
179 SpeechRecognitionEventListener* listener, 180 SpeechRecognitionEventListener* listener,
180 media::AudioSystem* audio_system, 181 media::AudioSystem* audio_system,
182 media::AudioManager* audio_manager,
181 int session_id, 183 int session_id,
182 bool continuous, 184 bool continuous,
183 bool provisional_results, 185 bool provisional_results,
184 SpeechRecognitionEngine* engine) 186 SpeechRecognitionEngine* engine)
185 : SpeechRecognizer(listener, session_id), 187 : SpeechRecognizer(listener, session_id),
186 audio_system_(audio_system), 188 audio_system_(audio_system),
189 audio_manager_(audio_manager),
187 recognition_engine_(engine), 190 recognition_engine_(engine),
188 endpointer_(kAudioSampleRate), 191 endpointer_(kAudioSampleRate),
189 audio_log_(MediaInternals::GetInstance()->CreateAudioLog( 192 audio_log_(MediaInternals::GetInstance()->CreateAudioLog(
190 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER)), 193 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER)),
191 is_dispatching_event_(false), 194 is_dispatching_event_(false),
192 provisional_results_(provisional_results), 195 provisional_results_(provisional_results),
193 end_of_utterance_(false), 196 end_of_utterance_(false),
194 state_(STATE_IDLE), 197 state_(STATE_IDLE),
195 weak_ptr_factory_(this) { 198 weak_ptr_factory_(this) {
196 DCHECK(recognition_engine_ != nullptr); 199 DCHECK(recognition_engine_ != nullptr);
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 DVLOG(1) << "SRI::input_parameters: " 629 DVLOG(1) << "SRI::input_parameters: "
627 << input_parameters.AsHumanReadableString(); 630 << input_parameters.AsHumanReadableString();
628 } 631 }
629 632
630 // Create an audio converter which converts data between native input format 633 // Create an audio converter which converts data between native input format
631 // and WebSpeech specific output format. 634 // and WebSpeech specific output format.
632 audio_converter_.reset( 635 audio_converter_.reset(
633 new OnDataConverter(input_parameters, output_parameters)); 636 new OnDataConverter(input_parameters, output_parameters));
634 637
635 audio_controller_ = AudioInputController::Create( 638 audio_controller_ = AudioInputController::Create(
636 GetAudioSystem()->GetAudioManager(), this, this, nullptr, 639 GetAudioManager(), this, this, nullptr, input_parameters, device_id_,
637 input_parameters, device_id_,
638 /*agc_is_enabled*/ false, 640 /*agc_is_enabled*/ false,
639 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); 641 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
640 642
641 if (!audio_controller_.get()) { 643 if (!audio_controller_.get()) {
642 return Abort( 644 return Abort(
643 SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE)); 645 SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE));
644 } 646 }
645 647
646 audio_log_->OnCreated(0, input_parameters, device_id_); 648 audio_log_->OnCreated(0, input_parameters, device_id_);
647 649
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 878
877 float noise_level = (endpointer_.NoiseLevelDb() - kAudioMeterMinDb) / 879 float noise_level = (endpointer_.NoiseLevelDb() - kAudioMeterMinDb) /
878 (kAudioMeterDbRange / kAudioMeterRangeMaxUnclipped); 880 (kAudioMeterDbRange / kAudioMeterRangeMaxUnclipped);
879 noise_level = std::min(std::max(0.0f, noise_level), 881 noise_level = std::min(std::max(0.0f, noise_level),
880 kAudioMeterRangeMaxUnclipped); 882 kAudioMeterRangeMaxUnclipped);
881 883
882 listener()->OnAudioLevelsChange( 884 listener()->OnAudioLevelsChange(
883 session_id(), clip_detected ? 1.0f : audio_level_, noise_level); 885 session_id(), clip_detected ? 1.0f : audio_level_, noise_level);
884 } 886 }
885 887
886 void SpeechRecognizerImpl::SetAudioSystemForTesting( 888 void SpeechRecognizerImpl::SetAudioEnvironmentForTesting(
887 media::AudioSystem* audio_system) { 889 media::AudioSystem* audio_system,
890 media::AudioManager* audio_manager) {
888 audio_system_for_tests_ = audio_system; 891 audio_system_for_tests_ = audio_system;
892 audio_manager_for_tests_ = audio_manager;
889 } 893 }
890 894
891 media::AudioSystem* SpeechRecognizerImpl::GetAudioSystem() { 895 media::AudioSystem* SpeechRecognizerImpl::GetAudioSystem() {
892 return audio_system_for_tests_ ? audio_system_for_tests_ : audio_system_; 896 return audio_system_for_tests_ ? audio_system_for_tests_ : audio_system_;
893 } 897 }
894 898
899 media::AudioManager* SpeechRecognizerImpl::GetAudioManager() {
900 return audio_manager_for_tests_ ? audio_manager_for_tests_ : audio_manager_;
901 }
902
895 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 903 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
896 : event(event_value), 904 : event(event_value),
897 audio_data(NULL), 905 audio_data(NULL),
898 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { 906 engine_error(SPEECH_RECOGNITION_ERROR_NONE) {
899 } 907 }
900 908
901 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(const FSMEventArgs& other) = 909 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(const FSMEventArgs& other) =
902 default; 910 default;
903 911
904 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { 912 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() {
905 } 913 }
906 914
907 } // namespace content 915 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer_impl.h ('k') | content/browser/speech/speech_recognizer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698