OLD | NEW |
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 "net/url_request/url_request_context_getter.h" | 9 #include "net/url_request/url_request_context_getter.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; | 51 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; |
52 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; | 52 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; |
53 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; | 53 const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; |
54 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; | 54 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; |
55 | 55 |
56 SpeechRecognizer::SpeechRecognizer(Delegate* delegate, | 56 SpeechRecognizer::SpeechRecognizer(Delegate* delegate, |
57 int caller_id, | 57 int caller_id, |
58 const std::string& language, | 58 const std::string& language, |
59 const std::string& grammar, | 59 const std::string& grammar, |
60 net::URLRequestContextGetter* context_getter, | 60 net::URLRequestContextGetter* context_getter, |
61 bool censor_results, | 61 bool filter_profanities, |
62 const std::string& hardware_info, | 62 const std::string& hardware_info, |
63 const std::string& origin_url) | 63 const std::string& origin_url) |
64 : delegate_(delegate), | 64 : delegate_(delegate), |
65 caller_id_(caller_id), | 65 caller_id_(caller_id), |
66 language_(language), | 66 language_(language), |
67 grammar_(grammar), | 67 grammar_(grammar), |
68 censor_results_(censor_results), | 68 filter_profanities_(filter_profanities), |
69 hardware_info_(hardware_info), | 69 hardware_info_(hardware_info), |
70 origin_url_(origin_url), | 70 origin_url_(origin_url), |
71 context_getter_(context_getter), | 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); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 endpointer_.ProcessAudio(samples, num_samples, &rms); | 221 endpointer_.ProcessAudio(samples, num_samples, &rms); |
222 bool did_clip = Clipping(samples, num_samples); | 222 bool did_clip = Clipping(samples, num_samples); |
223 delete data; | 223 delete data; |
224 num_samples_recorded_ += num_samples; | 224 num_samples_recorded_ += num_samples; |
225 | 225 |
226 if (request_ == NULL) { | 226 if (request_ == NULL) { |
227 // This was the first audio packet recorded, so start a request to the | 227 // This was the first audio packet recorded, so start a request to the |
228 // server to send the data and inform the delegate. | 228 // server to send the data and inform the delegate. |
229 delegate_->DidStartReceivingAudio(caller_id_); | 229 delegate_->DidStartReceivingAudio(caller_id_); |
230 request_.reset(new SpeechRecognitionRequest(context_getter_.get(), this)); | 230 request_.reset(new SpeechRecognitionRequest(context_getter_.get(), this)); |
231 request_->Start(language_, grammar_, censor_results_, | 231 request_->Start(language_, grammar_, filter_profanities_, |
232 hardware_info_, origin_url_, encoder_->mime_type()); | 232 hardware_info_, origin_url_, encoder_->mime_type()); |
233 } | 233 } |
234 | 234 |
235 string encoded_data; | 235 string encoded_data; |
236 encoder_->GetEncodedDataAndClear(&encoded_data); | 236 encoder_->GetEncodedDataAndClear(&encoded_data); |
237 DCHECK(!encoded_data.empty()); | 237 DCHECK(!encoded_data.empty()); |
238 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */); | 238 request_->UploadAudioChunk(encoded_data, false /* is_last_chunk */); |
239 | 239 |
240 if (endpointer_.IsEstimatingEnvironment()) { | 240 if (endpointer_.IsEstimatingEnvironment()) { |
241 // Check if we have gathered enough audio for the endpointer to do | 241 // Check if we have gathered enough audio for the endpointer to do |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 SpeechInputError error) { | 299 SpeechInputError error) { |
300 DCHECK_NE(error, kErrorNone); | 300 DCHECK_NE(error, kErrorNone); |
301 CancelRecognition(); | 301 CancelRecognition(); |
302 | 302 |
303 // Guard against the delegate freeing us until we finish our job. | 303 // Guard against the delegate freeing us until we finish our job. |
304 scoped_refptr<SpeechRecognizer> me(this); | 304 scoped_refptr<SpeechRecognizer> me(this); |
305 delegate_->OnRecognizerError(caller_id_, error); | 305 delegate_->OnRecognizerError(caller_id_, error); |
306 } | 306 } |
307 | 307 |
308 } // namespace speech_input | 308 } // namespace speech_input |
OLD | NEW |