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

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: Update SpeechInputPreferences when preference changes 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" 9 #include "content/browser/speech/speech_input_preferences.h"
10 #include "content/common/content_client.h"
11 #include "net/url_request/url_request_context_getter.h" 10 #include "net/url_request/url_request_context_getter.h"
12 11
13 using media::AudioInputController; 12 using media::AudioInputController;
14 using std::string; 13 using std::string;
15 14
16 namespace { 15 namespace {
17 16
18 // The following constants are related to the volume level indicator shown in 17 // The following constants are related to the volume level indicator shown in
19 // the UI for recorded audio. 18 // the UI for recorded audio.
20 // Multiplier used when new volume is greater than previous level. 19 // 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; 51 const int SpeechRecognizer::kAudioPacketIntervalMs = 100;
53 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; 52 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO;
54 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; 53 const int SpeechRecognizer::kNumBitsPerAudioSample = 16;
55 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; 54 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8;
56 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; 55 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300;
57 56
58 SpeechRecognizer::SpeechRecognizer(Delegate* delegate, 57 SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
59 int caller_id, 58 int caller_id,
60 const std::string& language, 59 const std::string& language,
61 const std::string& grammar, 60 const std::string& grammar,
62 bool censor_results, 61 net::URLRequestContextGetter* context_getter,
62 SpeechInputPreferences* speech_input_prefs,
63 const std::string& hardware_info, 63 const std::string& hardware_info,
64 const std::string& origin_url) 64 const std::string& origin_url)
65 : delegate_(delegate), 65 : delegate_(delegate),
66 caller_id_(caller_id), 66 caller_id_(caller_id),
67 language_(language), 67 language_(language),
68 grammar_(grammar), 68 grammar_(grammar),
69 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 speech_input_prefs_(speech_input_prefs),
72 codec_(AudioEncoder::CODEC_FLAC), 73 codec_(AudioEncoder::CODEC_FLAC),
73 encoder_(NULL), 74 encoder_(NULL),
74 endpointer_(kAudioSampleRate), 75 endpointer_(kAudioSampleRate),
75 num_samples_recorded_(0), 76 num_samples_recorded_(0),
76 audio_level_(0.0f) { 77 audio_level_(0.0f) {
77 endpointer_.set_speech_input_complete_silence_length( 78 endpointer_.set_speech_input_complete_silence_length(
78 base::Time::kMicrosecondsPerSecond / 2); 79 base::Time::kMicrosecondsPerSecond / 2);
79 endpointer_.set_long_speech_input_complete_silence_length( 80 endpointer_.set_long_speech_input_complete_silence_length(
80 base::Time::kMicrosecondsPerSecond); 81 base::Time::kMicrosecondsPerSecond);
81 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond); 82 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 float rms; 218 float rms;
218 endpointer_.ProcessAudio(samples, num_samples, &rms); 219 endpointer_.ProcessAudio(samples, num_samples, &rms);
219 bool did_clip = Clipping(samples, num_samples); 220 bool did_clip = Clipping(samples, num_samples);
220 delete data; 221 delete data;
221 num_samples_recorded_ += num_samples; 222 num_samples_recorded_ += num_samples;
222 223
223 if (request_ == NULL) { 224 if (request_ == NULL) {
224 // This was the first audio packet recorded, so start a request to the 225 // This was the first audio packet recorded, so start a request to the
225 // server to send the data and inform the delegate. 226 // server to send the data and inform the delegate.
226 delegate_->DidStartReceivingAudio(caller_id_); 227 delegate_->DidStartReceivingAudio(caller_id_);
227 // Deprecated; see http://crbug.com/92366 228 request_.reset(new SpeechRecognitionRequest(context_getter_.get(), this));
228 net::URLRequestContextGetter* context_getter = 229 request_->Start(language_, grammar_, speech_input_prefs_.get(),
229 content::GetContentClient()->browser()-> 230 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 } 231 }
235 232
236 string encoded_data; 233 string encoded_data;
237 encoder_->GetEncodedDataAndClear(&encoded_data); 234 encoder_->GetEncodedDataAndClear(&encoded_data);
238 DCHECK(!encoded_data.empty()); 235 DCHECK(!encoded_data.empty());
239 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */); 236 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */);
240 237
241 if (endpointer_.IsEstimatingEnvironment()) { 238 if (endpointer_.IsEstimatingEnvironment()) {
242 // Check if we have gathered enough audio for the endpointer to do 239 // 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. 240 // 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 297
301 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) { 298 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) {
302 CancelRecognition(); 299 CancelRecognition();
303 300
304 // Guard against the delegate freeing us until we finish our job. 301 // Guard against the delegate freeing us until we finish our job.
305 scoped_refptr<SpeechRecognizer> me(this); 302 scoped_refptr<SpeechRecognizer> me(this);
306 delegate_->OnRecognizerError(caller_id_, error); 303 delegate_->OnRecognizerError(caller_id_, error);
307 } 304 }
308 305
309 } // namespace speech_input 306 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698