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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/speech/audio_buffer.h" | 10 #include "content/browser/speech/audio_buffer.h" |
11 #include "content/browser/speech/google_one_shot_remote_engine.h" | 11 #include "content/browser/speech/google_one_shot_remote_engine.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/speech_recognition_event_listener.h" | 13 #include "content/public/browser/speech_recognition_event_listener.h" |
14 #include "content/public/browser/speech_recognizer.h" | 14 #include "content/public/browser/speech_recognizer.h" |
15 #include "content/public/common/speech_recognition_error.h" | 15 #include "content/public/common/speech_recognition_error.h" |
16 #include "content/public/common/speech_recognition_result.h" | 16 #include "content/public/common/speech_recognition_result.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 | 18 |
19 using content::BrowserMainLoop; | 19 using content::BrowserMainLoop; |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using content::SpeechRecognitionError; | 21 using content::SpeechRecognitionError; |
22 using content::SpeechRecognitionEventListener; | 22 using content::SpeechRecognitionEventListener; |
23 using content::SpeechRecognitionResult; | 23 using content::SpeechRecognitionResult; |
24 using content::SpeechRecognizer; | 24 using content::SpeechRecognizer; |
25 using media::AudioInputController; | 25 using media::AudioInputController; |
| 26 using media::AudioManager; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // The following constants are related to the volume level indicator shown in | 30 // The following constants are related to the volume level indicator shown in |
30 // the UI for recorded audio. | 31 // the UI for recorded audio. |
31 // Multiplier used when new volume is greater than previous level. | 32 // Multiplier used when new volume is greater than previous level. |
32 const float kUpSmoothingFactor = 1.0f; | 33 const float kUpSmoothingFactor = 1.0f; |
33 // Multiplier used when new volume is lesser than previous level. | 34 // Multiplier used when new volume is lesser than previous level. |
34 const float kDownSmoothingFactor = 0.7f; | 35 const float kDownSmoothingFactor = 0.7f; |
35 // RMS dB value of a maximum (unclipped) sine wave for int16 samples. | 36 // RMS dB value of a maximum (unclipped) sine wave for int16 samples. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 DCHECK(!audio_controller_.get()); | 131 DCHECK(!audio_controller_.get()); |
131 DCHECK(!recognition_engine_.get() || | 132 DCHECK(!recognition_engine_.get() || |
132 !recognition_engine_->IsRecognitionPending()); | 133 !recognition_engine_->IsRecognitionPending()); |
133 | 134 |
134 // The endpointer needs to estimate the environment/background noise before | 135 // The endpointer needs to estimate the environment/background noise before |
135 // starting to treat the audio as user input. In |HandleOnData| we wait until | 136 // starting to treat the audio as user input. In |HandleOnData| we wait until |
136 // such time has passed before switching to user input mode. | 137 // such time has passed before switching to user input mode. |
137 endpointer_.SetEnvironmentEstimationMode(); | 138 endpointer_.SetEnvironmentEstimationMode(); |
138 | 139 |
139 AudioManager* audio_manager = (testing_audio_manager_ != NULL) ? | 140 AudioManager* audio_manager = (testing_audio_manager_ != NULL) ? |
140 testing_audio_manager_ : | 141 testing_audio_manager_ : BrowserMainLoop::GetAudioManager(); |
141 BrowserMainLoop::GetAudioManager(); | |
142 const int samples_per_packet = kAudioSampleRate * | 142 const int samples_per_packet = kAudioSampleRate * |
143 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs / 1000; | 143 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs / 1000; |
144 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 144 media::AudioParameters params( |
145 kAudioSampleRate, kNumBitsPerAudioSample, | 145 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
146 samples_per_packet); | 146 kAudioSampleRate, kNumBitsPerAudioSample, samples_per_packet); |
147 audio_controller_ = AudioInputController::Create(audio_manager, this, params); | 147 audio_controller_ = AudioInputController::Create(audio_manager, this, params); |
148 DCHECK(audio_controller_.get()); | 148 DCHECK(audio_controller_.get()); |
149 VLOG(1) << "SpeechRecognizer starting record."; | 149 VLOG(1) << "SpeechRecognizer starting record."; |
150 num_samples_recorded_ = 0; | 150 num_samples_recorded_ = 0; |
151 audio_controller_->Record(); | 151 audio_controller_->Record(); |
152 } | 152 } |
153 | 153 |
154 void SpeechRecognizerImpl::AbortRecognition() { | 154 void SpeechRecognizerImpl::AbortRecognition() { |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
156 DCHECK(audio_controller_.get() || recognition_engine_.get()); | 156 DCHECK(audio_controller_.get() || recognition_engine_.get()); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 return *(recognition_engine_.get()); | 350 return *(recognition_engine_.get()); |
351 } | 351 } |
352 | 352 |
353 void SpeechRecognizerImpl::SetAudioManagerForTesting( | 353 void SpeechRecognizerImpl::SetAudioManagerForTesting( |
354 AudioManager* audio_manager) { | 354 AudioManager* audio_manager) { |
355 testing_audio_manager_ = audio_manager; | 355 testing_audio_manager_ = audio_manager; |
356 } | 356 } |
357 | 357 |
358 | 358 |
359 } // namespace speech | 359 } // namespace speech |
OLD | NEW |