OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
7 #include "base/bind.h" | 11 #include "base/bind.h" |
8 #include "base/time.h" | 12 #include "base/time.h" |
9 #include "content/browser/browser_main_loop.h" | 13 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/speech/audio_buffer.h" | 14 #include "content/browser/speech/audio_buffer.h" |
11 #include "content/public/browser/speech_recognition_event_listener.h" | 15 #include "content/public/browser/speech_recognition_event_listener.h" |
12 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/common/speech_recognition_result.h" | 17 #include "content/public/common/speech_recognition_result.h" |
14 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
15 | 19 |
16 using content::BrowserMainLoop; | 20 using content::BrowserMainLoop; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 DCHECK(!encoder_.get()); | 129 DCHECK(!encoder_.get()); |
126 | 130 |
127 // The endpointer needs to estimate the environment/background noise before | 131 // The endpointer needs to estimate the environment/background noise before |
128 // starting to treat the audio as user input. In |HandleOnData| we wait until | 132 // starting to treat the audio as user input. In |HandleOnData| we wait until |
129 // such time has passed before switching to user input mode. | 133 // such time has passed before switching to user input mode. |
130 endpointer_.SetEnvironmentEstimationMode(); | 134 endpointer_.SetEnvironmentEstimationMode(); |
131 | 135 |
132 encoder_.reset(AudioEncoder::Create(codec_, kAudioSampleRate, | 136 encoder_.reset(AudioEncoder::Create(codec_, kAudioSampleRate, |
133 kNumBitsPerAudioSample)); | 137 kNumBitsPerAudioSample)); |
134 int samples_per_packet = (kAudioSampleRate * kAudioPacketIntervalMs) / 1000; | 138 int samples_per_packet = (kAudioSampleRate * kAudioPacketIntervalMs) / 1000; |
135 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 139 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 140 false, kChannelLayout, |
136 kAudioSampleRate, kNumBitsPerAudioSample, | 141 kAudioSampleRate, kNumBitsPerAudioSample, |
137 samples_per_packet); | 142 samples_per_packet); |
138 audio_controller_ = AudioInputController::Create( | 143 audio_controller_ = AudioInputController::Create( |
139 audio_manager_ ? audio_manager_ : BrowserMainLoop::GetAudioManager(), | 144 audio_manager_ ? audio_manager_ : BrowserMainLoop::GetAudioManager(), |
140 this, params); | 145 this, params); |
141 DCHECK(audio_controller_.get()); | 146 DCHECK(audio_controller_.get()); |
142 VLOG(1) << "SpeechRecognizer starting record."; | 147 VLOG(1) << "SpeechRecognizer starting record."; |
143 num_samples_recorded_ = 0; | 148 num_samples_recorded_ = 0; |
144 audio_controller_->Record(); | 149 audio_controller_->Record(); |
145 | 150 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 350 |
346 bool SpeechRecognizerImpl::IsActive() const { | 351 bool SpeechRecognizerImpl::IsActive() const { |
347 return (request_.get() != NULL); | 352 return (request_.get() != NULL); |
348 } | 353 } |
349 | 354 |
350 bool SpeechRecognizerImpl::IsCapturingAudio() const { | 355 bool SpeechRecognizerImpl::IsCapturingAudio() const { |
351 return (audio_controller_.get() != NULL); | 356 return (audio_controller_.get() != NULL); |
352 } | 357 } |
353 | 358 |
354 } // namespace speech | 359 } // namespace speech |
OLD | NEW |