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

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

Issue 7086005: Context menu for "Voice recognition options" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: No changes (Just trying to get commit-bot to wake up) Created 9 years, 4 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 "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "content/browser/browser_thread.h" 9 #include "content/browser/browser_thread.h"
10 #include "net/url_request/url_request_context_getter.h" 10 #include "net/url_request/url_request_context_getter.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const int SpeechRecognizer::kAudioPacketIntervalMs = 100; 51 const int SpeechRecognizer::kAudioPacketIntervalMs = 100;
52 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; 52 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO;
53 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; 53 const int SpeechRecognizer::kNumBitsPerAudioSample = 16;
54 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; 54 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8;
55 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; 55 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300;
56 56
57 SpeechRecognizer::SpeechRecognizer(Delegate* delegate, 57 SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
58 int caller_id, 58 int caller_id,
59 const std::string& language, 59 const std::string& language,
60 const std::string& grammar, 60 const std::string& grammar,
61 bool censor_results,
61 const std::string& hardware_info, 62 const std::string& hardware_info,
62 const std::string& origin_url) 63 const std::string& origin_url)
63 : delegate_(delegate), 64 : delegate_(delegate),
64 caller_id_(caller_id), 65 caller_id_(caller_id),
65 language_(language), 66 language_(language),
66 grammar_(grammar), 67 grammar_(grammar),
68 censor_results_(censor_results),
67 hardware_info_(hardware_info), 69 hardware_info_(hardware_info),
68 origin_url_(origin_url), 70 origin_url_(origin_url),
69 codec_(AudioEncoder::CODEC_FLAC), 71 codec_(AudioEncoder::CODEC_FLAC),
70 encoder_(NULL), 72 encoder_(NULL),
71 endpointer_(kAudioSampleRate), 73 endpointer_(kAudioSampleRate),
72 num_samples_recorded_(0), 74 num_samples_recorded_(0),
73 audio_level_(0.0f) { 75 audio_level_(0.0f) {
74 endpointer_.set_speech_input_complete_silence_length( 76 endpointer_.set_speech_input_complete_silence_length(
75 base::Time::kMicrosecondsPerSecond / 2); 77 base::Time::kMicrosecondsPerSecond / 2);
76 endpointer_.set_long_speech_input_complete_silence_length( 78 endpointer_.set_long_speech_input_complete_silence_length(
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bool did_clip = Clipping(samples, num_samples); 218 bool did_clip = Clipping(samples, num_samples);
217 delete data; 219 delete data;
218 num_samples_recorded_ += num_samples; 220 num_samples_recorded_ += num_samples;
219 221
220 if (request_ == NULL) { 222 if (request_ == NULL) {
221 // This was the first audio packet recorded, so start a request to the 223 // This was the first audio packet recorded, so start a request to the
222 // server to send the data and inform the delegate. 224 // server to send the data and inform the delegate.
223 delegate_->DidStartReceivingAudio(caller_id_); 225 delegate_->DidStartReceivingAudio(caller_id_);
224 request_.reset(new SpeechRecognitionRequest( 226 request_.reset(new SpeechRecognitionRequest(
225 Profile::Deprecated::GetDefaultRequestContext(), this)); 227 Profile::Deprecated::GetDefaultRequestContext(), this));
226 request_->Start(language_, grammar_, hardware_info_, origin_url_, 228 request_->Start(language_, grammar_, censor_results_, hardware_info_,
227 encoder_->mime_type()); 229 origin_url_, encoder_->mime_type());
228 } 230 }
229 231
230 string encoded_data; 232 string encoded_data;
231 encoder_->GetEncodedDataAndClear(&encoded_data); 233 encoder_->GetEncodedDataAndClear(&encoded_data);
232 DCHECK(!encoded_data.empty()); 234 DCHECK(!encoded_data.empty());
233 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */); 235 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */);
234 236
235 if (endpointer_.IsEstimatingEnvironment()) { 237 if (endpointer_.IsEstimatingEnvironment()) {
236 // 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
237 // 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
294 296
295 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) { 297 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) {
296 CancelRecognition(); 298 CancelRecognition();
297 299
298 // Guard against the delegate freeing us until we finish our job. 300 // Guard against the delegate freeing us until we finish our job.
299 scoped_refptr<SpeechRecognizer> me(this); 301 scoped_refptr<SpeechRecognizer> me(this);
300 delegate_->OnRecognizerError(caller_id_, error); 302 delegate_->OnRecognizerError(caller_id_, error);
301 } 303 }
302 304
303 } // 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