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

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

Issue 7989001: Remove use of default request context and fix use of speech censor flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separate overriden methods in profile_impl.h Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "content/browser/speech/speech_recognizer.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
9 #include "content/browser/content_browser_client.h"
10 #include "content/common/content_client.h"
11 #include "net/url_request/url_request_context_getter.h" 9 #include "net/url_request/url_request_context_getter.h"
12 10
13 using media::AudioInputController; 11 using media::AudioInputController;
14 using std::string; 12 using std::string;
15 13
16 namespace { 14 namespace {
17 15
18 // The following constants are related to the volume level indicator shown in 16 // The following constants are related to the volume level indicator shown in
19 // the UI for recorded audio. 17 // the UI for recorded audio.
20 // Multiplier used when new volume is greater than previous level. 18 // Multiplier used when new volume is greater than previous level.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const int SpeechRecognizer::kAudioPacketIntervalMs = 100; 50 const int SpeechRecognizer::kAudioPacketIntervalMs = 100;
53 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; 51 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO;
54 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; 52 const int SpeechRecognizer::kNumBitsPerAudioSample = 16;
55 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; 53 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8;
56 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; 54 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300;
57 55
58 SpeechRecognizer::SpeechRecognizer(Delegate* delegate, 56 SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
59 int caller_id, 57 int caller_id,
60 const std::string& language, 58 const std::string& language,
61 const std::string& grammar, 59 const std::string& grammar,
60 net::URLRequestContextGetter* context_getter,
62 bool censor_results, 61 bool censor_results,
63 const std::string& hardware_info, 62 const std::string& hardware_info,
64 const std::string& origin_url) 63 const std::string& origin_url)
65 : delegate_(delegate), 64 : delegate_(delegate),
66 caller_id_(caller_id), 65 caller_id_(caller_id),
67 language_(language), 66 language_(language),
68 grammar_(grammar), 67 grammar_(grammar),
69 censor_results_(censor_results), 68 censor_results_(censor_results),
70 hardware_info_(hardware_info), 69 hardware_info_(hardware_info),
71 origin_url_(origin_url), 70 origin_url_(origin_url),
71 context_getter_(context_getter),
72 codec_(AudioEncoder::CODEC_FLAC), 72 codec_(AudioEncoder::CODEC_FLAC),
73 encoder_(NULL), 73 encoder_(NULL),
74 endpointer_(kAudioSampleRate), 74 endpointer_(kAudioSampleRate),
75 num_samples_recorded_(0), 75 num_samples_recorded_(0),
76 audio_level_(0.0f) { 76 audio_level_(0.0f) {
77 endpointer_.set_speech_input_complete_silence_length( 77 endpointer_.set_speech_input_complete_silence_length(
78 base::Time::kMicrosecondsPerSecond / 2); 78 base::Time::kMicrosecondsPerSecond / 2);
79 endpointer_.set_long_speech_input_complete_silence_length( 79 endpointer_.set_long_speech_input_complete_silence_length(
80 base::Time::kMicrosecondsPerSecond); 80 base::Time::kMicrosecondsPerSecond);
81 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond); 81 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 float rms; 217 float rms;
218 endpointer_.ProcessAudio(samples, num_samples, &rms); 218 endpointer_.ProcessAudio(samples, num_samples, &rms);
219 bool did_clip = Clipping(samples, num_samples); 219 bool did_clip = Clipping(samples, num_samples);
220 delete data; 220 delete data;
221 num_samples_recorded_ += num_samples; 221 num_samples_recorded_ += num_samples;
222 222
223 if (request_ == NULL) { 223 if (request_ == NULL) {
224 // This was the first audio packet recorded, so start a request to the 224 // This was the first audio packet recorded, so start a request to the
225 // server to send the data and inform the delegate. 225 // server to send the data and inform the delegate.
226 delegate_->DidStartReceivingAudio(caller_id_); 226 delegate_->DidStartReceivingAudio(caller_id_);
227 // Deprecated; see http://crbug.com/92366 227 request_.reset(new SpeechRecognitionRequest(context_getter_.get(), this));
228 net::URLRequestContextGetter* context_getter = 228 request_->Start(language_, grammar_, censor_results_,
229 content::GetContentClient()->browser()-> 229 hardware_info_, origin_url_, encoder_->mime_type());
230 GetDefaultRequestContextDeprecatedCrBug64339();
231 request_.reset(new SpeechRecognitionRequest(context_getter, this));
232 request_->Start(language_, grammar_, censor_results_, hardware_info_,
233 origin_url_, encoder_->mime_type());
234 } 230 }
235 231
236 string encoded_data; 232 string encoded_data;
237 encoder_->GetEncodedDataAndClear(&encoded_data); 233 encoder_->GetEncodedDataAndClear(&encoded_data);
238 DCHECK(!encoded_data.empty()); 234 DCHECK(!encoded_data.empty());
239 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */); 235 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */);
240 236
241 if (endpointer_.IsEstimatingEnvironment()) { 237 if (endpointer_.IsEstimatingEnvironment()) {
242 // Check if we have gathered enough audio for the endpointer to do 238 // Check if we have gathered enough audio for the endpointer to do
243 // environment estimation and should move on to detect speech/end of speech. 239 // environment estimation and should move on to detect speech/end of speech.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 296
301 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) { 297 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) {
302 CancelRecognition(); 298 CancelRecognition();
303 299
304 // Guard against the delegate freeing us until we finish our job. 300 // Guard against the delegate freeing us until we finish our job.
305 scoped_refptr<SpeechRecognizer> me(this); 301 scoped_refptr<SpeechRecognizer> me(this);
306 delegate_->OnRecognizerError(caller_id_, error); 302 delegate_->OnRecognizerError(caller_id_, error);
307 } 303 }
308 304
309 } // namespace speech_input 305 } // namespace speech_input
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer.h ('k') | content/browser/speech/speech_recognizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698