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

Side by Side Diff: trunk/src/content/browser/speech/speech_recognizer_impl_unittest.cc

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <vector> 5 #include <vector>
6 6
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/speech/google_one_shot_remote_engine.h" 8 #include "content/browser/speech/google_one_shot_remote_engine.h"
9 #include "content/browser/speech/speech_recognizer_impl.h" 9 #include "content/browser/speech/speech_recognizer_impl.h"
10 #include "content/public/browser/speech_recognition_event_listener.h" 10 #include "content/public/browser/speech_recognition_event_listener.h"
11 #include "media/audio/audio_manager_base.h" 11 #include "media/audio/audio_manager_base.h"
12 #include "media/audio/fake_audio_input_stream.h" 12 #include "media/audio/fake_audio_input_stream.h"
13 #include "media/audio/fake_audio_output_stream.h" 13 #include "media/audio/fake_audio_output_stream.h"
14 #include "media/audio/mock_audio_manager.h" 14 #include "media/audio/mock_audio_manager.h"
15 #include "media/audio/test_audio_input_controller_factory.h" 15 #include "media/audio/test_audio_input_controller_factory.h"
16 #include "media/base/audio_bus.h"
17 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
18 #include "net/url_request/test_url_fetcher_factory.h" 17 #include "net/url_request/test_url_fetcher_factory.h"
19 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 using base::MessageLoopProxy; 21 using base::MessageLoopProxy;
23 using media::AudioInputController; 22 using media::AudioInputController;
24 using media::AudioInputStream; 23 using media::AudioInputStream;
25 using media::AudioManager; 24 using media::AudioManager;
26 using media::AudioOutputStream; 25 using media::AudioOutputStream;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 audio_manager_.reset(new media::MockAudioManager( 59 audio_manager_.reset(new media::MockAudioManager(
61 base::MessageLoop::current()->message_loop_proxy().get())); 60 base::MessageLoop::current()->message_loop_proxy().get()));
62 recognizer_->SetAudioManagerForTesting(audio_manager_.get()); 61 recognizer_->SetAudioManagerForTesting(audio_manager_.get());
63 62
64 int audio_packet_length_bytes = 63 int audio_packet_length_bytes =
65 (SpeechRecognizerImpl::kAudioSampleRate * 64 (SpeechRecognizerImpl::kAudioSampleRate *
66 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs * 65 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs *
67 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout) * 66 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout) *
68 SpeechRecognizerImpl::kNumBitsPerAudioSample) / (8 * 1000); 67 SpeechRecognizerImpl::kNumBitsPerAudioSample) / (8 * 1000);
69 audio_packet_.resize(audio_packet_length_bytes); 68 audio_packet_.resize(audio_packet_length_bytes);
70
71 const int channels =
72 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout);
73 bytes_per_sample_ = SpeechRecognizerImpl::kNumBitsPerAudioSample / 8;
74 const int frames = audio_packet_length_bytes / channels / bytes_per_sample_;
75 audio_bus_ = media::AudioBus::Create(channels, frames);
76 audio_bus_->Zero();
77 } 69 }
78 70
79 void CheckEventsConsistency() { 71 void CheckEventsConsistency() {
80 // Note: "!x || y" == "x implies y". 72 // Note: "!x || y" == "x implies y".
81 EXPECT_TRUE(!recognition_ended_ || recognition_started_); 73 EXPECT_TRUE(!recognition_ended_ || recognition_started_);
82 EXPECT_TRUE(!audio_ended_ || audio_started_); 74 EXPECT_TRUE(!audio_ended_ || audio_started_);
83 EXPECT_TRUE(!sound_ended_ || sound_started_); 75 EXPECT_TRUE(!sound_ended_ || sound_started_);
84 EXPECT_TRUE(!audio_started_ || recognition_started_); 76 EXPECT_TRUE(!audio_started_ || recognition_started_);
85 EXPECT_TRUE(!sound_started_ || audio_started_); 77 EXPECT_TRUE(!sound_started_ || audio_started_);
86 EXPECT_TRUE(!audio_ended_ || (sound_ended_ || !sound_started_)); 78 EXPECT_TRUE(!audio_ended_ || (sound_ended_ || !sound_started_));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // testing::Test methods. 140 // testing::Test methods.
149 virtual void SetUp() OVERRIDE { 141 virtual void SetUp() OVERRIDE {
150 AudioInputController::set_factory_for_testing( 142 AudioInputController::set_factory_for_testing(
151 &audio_input_controller_factory_); 143 &audio_input_controller_factory_);
152 } 144 }
153 145
154 virtual void TearDown() OVERRIDE { 146 virtual void TearDown() OVERRIDE {
155 AudioInputController::set_factory_for_testing(NULL); 147 AudioInputController::set_factory_for_testing(NULL);
156 } 148 }
157 149
158 void CopyPacketToAudioBus() {
159 // Copy the created signal into an audio bus in a deinterleaved format.
160 audio_bus_->FromInterleaved(
161 &audio_packet_[0], audio_bus_->frames(), bytes_per_sample_);
162 }
163
164 void FillPacketWithTestWaveform() { 150 void FillPacketWithTestWaveform() {
165 // Fill the input with a simple pattern, a 125Hz sawtooth waveform. 151 // Fill the input with a simple pattern, a 125Hz sawtooth waveform.
166 for (size_t i = 0; i < audio_packet_.size(); ++i) 152 for (size_t i = 0; i < audio_packet_.size(); ++i)
167 audio_packet_[i] = static_cast<uint8>(i); 153 audio_packet_[i] = static_cast<uint8>(i);
168 CopyPacketToAudioBus();
169 } 154 }
170 155
171 void FillPacketWithNoise() { 156 void FillPacketWithNoise() {
172 int value = 0; 157 int value = 0;
173 int factor = 175; 158 int factor = 175;
174 for (size_t i = 0; i < audio_packet_.size(); ++i) { 159 for (size_t i = 0; i < audio_packet_.size(); ++i) {
175 value += factor; 160 value += factor;
176 audio_packet_[i] = value % 100; 161 audio_packet_[i] = value % 100;
177 } 162 }
178 CopyPacketToAudioBus();
179 } 163 }
180 164
181 protected: 165 protected:
182 base::MessageLoopForIO message_loop_; 166 base::MessageLoopForIO message_loop_;
183 BrowserThreadImpl io_thread_; 167 BrowserThreadImpl io_thread_;
184 scoped_refptr<SpeechRecognizerImpl> recognizer_; 168 scoped_refptr<SpeechRecognizerImpl> recognizer_;
185 scoped_ptr<AudioManager> audio_manager_; 169 scoped_ptr<AudioManager> audio_manager_;
186 bool recognition_started_; 170 bool recognition_started_;
187 bool recognition_ended_; 171 bool recognition_ended_;
188 bool result_received_; 172 bool result_received_;
189 bool audio_started_; 173 bool audio_started_;
190 bool audio_ended_; 174 bool audio_ended_;
191 bool sound_started_; 175 bool sound_started_;
192 bool sound_ended_; 176 bool sound_ended_;
193 SpeechRecognitionErrorCode error_; 177 SpeechRecognitionErrorCode error_;
194 net::TestURLFetcherFactory url_fetcher_factory_; 178 net::TestURLFetcherFactory url_fetcher_factory_;
195 TestAudioInputControllerFactory audio_input_controller_factory_; 179 TestAudioInputControllerFactory audio_input_controller_factory_;
196 std::vector<uint8> audio_packet_; 180 std::vector<uint8> audio_packet_;
197 scoped_ptr<media::AudioBus> audio_bus_;
198 int bytes_per_sample_;
199 float volume_; 181 float volume_;
200 float noise_volume_; 182 float noise_volume_;
201 }; 183 };
202 184
203 TEST_F(SpeechRecognizerImplTest, StopNoData) { 185 TEST_F(SpeechRecognizerImplTest, StopNoData) {
204 // Check for callbacks when stopping record before any audio gets recorded. 186 // Check for callbacks when stopping record before any audio gets recorded.
205 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 187 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
206 recognizer_->StopAudioCapture(); 188 recognizer_->StopAudioCapture();
207 base::MessageLoop::current()->RunUntilIdle(); 189 base::MessageLoop::current()->RunUntilIdle();
208 EXPECT_TRUE(recognition_started_); 190 EXPECT_TRUE(recognition_started_);
(...skipping 24 matching lines...) Expand all
233 TestAudioInputController* controller = 215 TestAudioInputController* controller =
234 audio_input_controller_factory_.controller(); 216 audio_input_controller_factory_.controller();
235 ASSERT_TRUE(controller); 217 ASSERT_TRUE(controller);
236 218
237 // Try sending 5 chunks of mock audio data and verify that each of them 219 // Try sending 5 chunks of mock audio data and verify that each of them
238 // resulted immediately in a packet sent out via the network. This verifies 220 // resulted immediately in a packet sent out via the network. This verifies
239 // that we are streaming out encoded data as chunks without waiting for the 221 // that we are streaming out encoded data as chunks without waiting for the
240 // full recording to complete. 222 // full recording to complete.
241 const size_t kNumChunks = 5; 223 const size_t kNumChunks = 5;
242 for (size_t i = 0; i < kNumChunks; ++i) { 224 for (size_t i = 0; i < kNumChunks; ++i) {
243 controller->event_handler()->OnData(controller, audio_bus_.get()); 225 controller->event_handler()->OnData(controller, &audio_packet_[0],
226 audio_packet_.size());
244 base::MessageLoop::current()->RunUntilIdle(); 227 base::MessageLoop::current()->RunUntilIdle();
245 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 228 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
246 ASSERT_TRUE(fetcher); 229 ASSERT_TRUE(fetcher);
247 EXPECT_EQ(i + 1, fetcher->upload_chunks().size()); 230 EXPECT_EQ(i + 1, fetcher->upload_chunks().size());
248 } 231 }
249 232
250 recognizer_->StopAudioCapture(); 233 recognizer_->StopAudioCapture();
251 base::MessageLoop::current()->RunUntilIdle(); 234 base::MessageLoop::current()->RunUntilIdle();
252 EXPECT_TRUE(audio_started_); 235 EXPECT_TRUE(audio_started_);
253 EXPECT_TRUE(audio_ended_); 236 EXPECT_TRUE(audio_ended_);
(...skipping 20 matching lines...) Expand all
274 CheckFinalEventsConsistency(); 257 CheckFinalEventsConsistency();
275 } 258 }
276 259
277 TEST_F(SpeechRecognizerImplTest, CancelWithData) { 260 TEST_F(SpeechRecognizerImplTest, CancelWithData) {
278 // Start recording, give some data and then cancel. 261 // Start recording, give some data and then cancel.
279 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 262 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
280 base::MessageLoop::current()->RunUntilIdle(); 263 base::MessageLoop::current()->RunUntilIdle();
281 TestAudioInputController* controller = 264 TestAudioInputController* controller =
282 audio_input_controller_factory_.controller(); 265 audio_input_controller_factory_.controller();
283 ASSERT_TRUE(controller); 266 ASSERT_TRUE(controller);
284 controller->event_handler()->OnData(controller, audio_bus_.get()); 267 controller->event_handler()->OnData(controller, &audio_packet_[0],
268 audio_packet_.size());
285 base::MessageLoop::current()->RunUntilIdle(); 269 base::MessageLoop::current()->RunUntilIdle();
286 recognizer_->AbortRecognition(); 270 recognizer_->AbortRecognition();
287 base::MessageLoop::current()->RunUntilIdle(); 271 base::MessageLoop::current()->RunUntilIdle();
288 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); 272 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0));
289 EXPECT_TRUE(recognition_started_); 273 EXPECT_TRUE(recognition_started_);
290 EXPECT_TRUE(audio_started_); 274 EXPECT_TRUE(audio_started_);
291 EXPECT_FALSE(result_received_); 275 EXPECT_FALSE(result_received_);
292 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); 276 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_);
293 CheckFinalEventsConsistency(); 277 CheckFinalEventsConsistency();
294 } 278 }
295 279
296 TEST_F(SpeechRecognizerImplTest, ConnectionError) { 280 TEST_F(SpeechRecognizerImplTest, ConnectionError) {
297 // Start recording, give some data and then stop. Issue the network callback 281 // Start recording, give some data and then stop. Issue the network callback
298 // with a connection error and verify that the recognizer bubbles the error up 282 // with a connection error and verify that the recognizer bubbles the error up
299 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 283 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
300 base::MessageLoop::current()->RunUntilIdle(); 284 base::MessageLoop::current()->RunUntilIdle();
301 TestAudioInputController* controller = 285 TestAudioInputController* controller =
302 audio_input_controller_factory_.controller(); 286 audio_input_controller_factory_.controller();
303 ASSERT_TRUE(controller); 287 ASSERT_TRUE(controller);
304 controller->event_handler()->OnData(controller, audio_bus_.get()); 288 controller->event_handler()->OnData(controller, &audio_packet_[0],
289 audio_packet_.size());
305 base::MessageLoop::current()->RunUntilIdle(); 290 base::MessageLoop::current()->RunUntilIdle();
306 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 291 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
307 ASSERT_TRUE(fetcher); 292 ASSERT_TRUE(fetcher);
308 293
309 recognizer_->StopAudioCapture(); 294 recognizer_->StopAudioCapture();
310 base::MessageLoop::current()->RunUntilIdle(); 295 base::MessageLoop::current()->RunUntilIdle();
311 EXPECT_TRUE(audio_started_); 296 EXPECT_TRUE(audio_started_);
312 EXPECT_TRUE(audio_ended_); 297 EXPECT_TRUE(audio_ended_);
313 EXPECT_FALSE(recognition_ended_); 298 EXPECT_FALSE(recognition_ended_);
314 EXPECT_FALSE(result_received_); 299 EXPECT_FALSE(result_received_);
(...skipping 16 matching lines...) Expand all
331 } 316 }
332 317
333 TEST_F(SpeechRecognizerImplTest, ServerError) { 318 TEST_F(SpeechRecognizerImplTest, ServerError) {
334 // Start recording, give some data and then stop. Issue the network callback 319 // Start recording, give some data and then stop. Issue the network callback
335 // with a 500 error and verify that the recognizer bubbles the error up 320 // with a 500 error and verify that the recognizer bubbles the error up
336 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 321 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
337 base::MessageLoop::current()->RunUntilIdle(); 322 base::MessageLoop::current()->RunUntilIdle();
338 TestAudioInputController* controller = 323 TestAudioInputController* controller =
339 audio_input_controller_factory_.controller(); 324 audio_input_controller_factory_.controller();
340 ASSERT_TRUE(controller); 325 ASSERT_TRUE(controller);
341 controller->event_handler()->OnData(controller, audio_bus_.get()); 326 controller->event_handler()->OnData(controller, &audio_packet_[0],
327 audio_packet_.size());
342 base::MessageLoop::current()->RunUntilIdle(); 328 base::MessageLoop::current()->RunUntilIdle();
343 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 329 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
344 ASSERT_TRUE(fetcher); 330 ASSERT_TRUE(fetcher);
345 331
346 recognizer_->StopAudioCapture(); 332 recognizer_->StopAudioCapture();
347 base::MessageLoop::current()->RunUntilIdle(); 333 base::MessageLoop::current()->RunUntilIdle();
348 EXPECT_TRUE(audio_started_); 334 EXPECT_TRUE(audio_started_);
349 EXPECT_TRUE(audio_ended_); 335 EXPECT_TRUE(audio_ended_);
350 EXPECT_FALSE(recognition_ended_); 336 EXPECT_FALSE(recognition_ended_);
351 EXPECT_FALSE(result_received_); 337 EXPECT_FALSE(result_received_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 370 }
385 371
386 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) { 372 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) {
387 // Check if things tear down properly if AudioInputController threw an error 373 // Check if things tear down properly if AudioInputController threw an error
388 // after giving some audio data. 374 // after giving some audio data.
389 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 375 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
390 base::MessageLoop::current()->RunUntilIdle(); 376 base::MessageLoop::current()->RunUntilIdle();
391 TestAudioInputController* controller = 377 TestAudioInputController* controller =
392 audio_input_controller_factory_.controller(); 378 audio_input_controller_factory_.controller();
393 ASSERT_TRUE(controller); 379 ASSERT_TRUE(controller);
394 controller->event_handler()->OnData(controller, audio_bus_.get()); 380 controller->event_handler()->OnData(controller, &audio_packet_[0],
381 audio_packet_.size());
395 controller->event_handler()->OnError(controller, 382 controller->event_handler()->OnError(controller,
396 AudioInputController::UNKNOWN_ERROR); 383 AudioInputController::UNKNOWN_ERROR);
397 base::MessageLoop::current()->RunUntilIdle(); 384 base::MessageLoop::current()->RunUntilIdle();
398 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); 385 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0));
399 EXPECT_TRUE(recognition_started_); 386 EXPECT_TRUE(recognition_started_);
400 EXPECT_TRUE(audio_started_); 387 EXPECT_TRUE(audio_started_);
401 EXPECT_FALSE(result_received_); 388 EXPECT_FALSE(result_received_);
402 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO, error_); 389 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO, error_);
403 CheckFinalEventsConsistency(); 390 CheckFinalEventsConsistency();
404 } 391 }
405 392
406 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) { 393 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) {
407 // Start recording and give a lot of packets with audio samples set to zero. 394 // Start recording and give a lot of packets with audio samples set to zero.
408 // This should trigger the no-speech detector and issue a callback. 395 // This should trigger the no-speech detector and issue a callback.
409 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 396 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
410 base::MessageLoop::current()->RunUntilIdle(); 397 base::MessageLoop::current()->RunUntilIdle();
411 TestAudioInputController* controller = 398 TestAudioInputController* controller =
412 audio_input_controller_factory_.controller(); 399 audio_input_controller_factory_.controller();
413 ASSERT_TRUE(controller); 400 ASSERT_TRUE(controller);
414 401
415 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / 402 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) /
416 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs + 1; 403 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs + 1;
417 // The vector is already filled with zero value samples on create. 404 // The vector is already filled with zero value samples on create.
418 for (int i = 0; i < num_packets; ++i) { 405 for (int i = 0; i < num_packets; ++i) {
419 controller->event_handler()->OnData(controller, audio_bus_.get()); 406 controller->event_handler()->OnData(controller, &audio_packet_[0],
407 audio_packet_.size());
420 } 408 }
421 base::MessageLoop::current()->RunUntilIdle(); 409 base::MessageLoop::current()->RunUntilIdle();
422 EXPECT_TRUE(recognition_started_); 410 EXPECT_TRUE(recognition_started_);
423 EXPECT_TRUE(audio_started_); 411 EXPECT_TRUE(audio_started_);
424 EXPECT_FALSE(result_received_); 412 EXPECT_FALSE(result_received_);
425 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); 413 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_);
426 CheckFinalEventsConsistency(); 414 CheckFinalEventsConsistency();
427 } 415 }
428 416
429 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) { 417 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) {
430 // Start recording and give a lot of packets with audio samples set to zero 418 // Start recording and give a lot of packets with audio samples set to zero
431 // and then some more with reasonably loud audio samples. This should be 419 // and then some more with reasonably loud audio samples. This should be
432 // treated as normal speech input and the no-speech detector should not get 420 // treated as normal speech input and the no-speech detector should not get
433 // triggered. 421 // triggered.
434 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); 422 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId);
435 base::MessageLoop::current()->RunUntilIdle(); 423 base::MessageLoop::current()->RunUntilIdle();
436 TestAudioInputController* controller = 424 TestAudioInputController* controller =
437 audio_input_controller_factory_.controller(); 425 audio_input_controller_factory_.controller();
438 ASSERT_TRUE(controller); 426 ASSERT_TRUE(controller);
439 controller = audio_input_controller_factory_.controller(); 427 controller = audio_input_controller_factory_.controller();
440 ASSERT_TRUE(controller); 428 ASSERT_TRUE(controller);
441 429
442 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / 430 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) /
443 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs; 431 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs;
444 432
445 // The vector is already filled with zero value samples on create. 433 // The vector is already filled with zero value samples on create.
446 for (int i = 0; i < num_packets / 2; ++i) { 434 for (int i = 0; i < num_packets / 2; ++i) {
447 controller->event_handler()->OnData(controller, audio_bus_.get()); 435 controller->event_handler()->OnData(controller, &audio_packet_[0],
436 audio_packet_.size());
448 } 437 }
449 438
450 FillPacketWithTestWaveform(); 439 FillPacketWithTestWaveform();
451 for (int i = 0; i < num_packets / 2; ++i) { 440 for (int i = 0; i < num_packets / 2; ++i) {
452 controller->event_handler()->OnData(controller, audio_bus_.get()); 441 controller->event_handler()->OnData(controller, &audio_packet_[0],
442 audio_packet_.size());
453 } 443 }
454 444
455 base::MessageLoop::current()->RunUntilIdle(); 445 base::MessageLoop::current()->RunUntilIdle();
456 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 446 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
457 EXPECT_TRUE(audio_started_); 447 EXPECT_TRUE(audio_started_);
458 EXPECT_FALSE(audio_ended_); 448 EXPECT_FALSE(audio_ended_);
459 EXPECT_FALSE(recognition_ended_); 449 EXPECT_FALSE(recognition_ended_);
460 recognizer_->AbortRecognition(); 450 recognizer_->AbortRecognition();
461 base::MessageLoop::current()->RunUntilIdle(); 451 base::MessageLoop::current()->RunUntilIdle();
462 CheckFinalEventsConsistency(); 452 CheckFinalEventsConsistency();
(...skipping 10 matching lines...) Expand all
473 audio_input_controller_factory_.controller(); 463 audio_input_controller_factory_.controller();
474 ASSERT_TRUE(controller); 464 ASSERT_TRUE(controller);
475 controller = audio_input_controller_factory_.controller(); 465 controller = audio_input_controller_factory_.controller();
476 ASSERT_TRUE(controller); 466 ASSERT_TRUE(controller);
477 467
478 // Feed some samples to begin with for the endpointer to do noise estimation. 468 // Feed some samples to begin with for the endpointer to do noise estimation.
479 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs / 469 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs /
480 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs; 470 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs;
481 FillPacketWithNoise(); 471 FillPacketWithNoise();
482 for (int i = 0; i < num_packets; ++i) { 472 for (int i = 0; i < num_packets; ++i) {
483 controller->event_handler()->OnData(controller, audio_bus_.get()); 473 controller->event_handler()->OnData(controller, &audio_packet_[0],
474 audio_packet_.size());
484 } 475 }
485 base::MessageLoop::current()->RunUntilIdle(); 476 base::MessageLoop::current()->RunUntilIdle();
486 EXPECT_EQ(-1.0f, volume_); // No audio volume set yet. 477 EXPECT_EQ(-1.0f, volume_); // No audio volume set yet.
487 478
488 // The vector is already filled with zero value samples on create. 479 // The vector is already filled with zero value samples on create.
489 controller->event_handler()->OnData(controller, audio_bus_.get()); 480 controller->event_handler()->OnData(controller, &audio_packet_[0],
481 audio_packet_.size());
490 base::MessageLoop::current()->RunUntilIdle(); 482 base::MessageLoop::current()->RunUntilIdle();
491 EXPECT_FLOAT_EQ(0.74939233f, volume_); 483 EXPECT_FLOAT_EQ(0.74939233f, volume_);
492 484
493 FillPacketWithTestWaveform(); 485 FillPacketWithTestWaveform();
494 controller->event_handler()->OnData(controller, audio_bus_.get()); 486 controller->event_handler()->OnData(controller, &audio_packet_[0],
487 audio_packet_.size());
495 base::MessageLoop::current()->RunUntilIdle(); 488 base::MessageLoop::current()->RunUntilIdle();
496 EXPECT_NEAR(0.89926866f, volume_, 0.00001f); 489 EXPECT_NEAR(0.89926866f, volume_, 0.00001f);
497 EXPECT_FLOAT_EQ(0.75071919f, noise_volume_); 490 EXPECT_FLOAT_EQ(0.75071919f, noise_volume_);
498 491
499 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 492 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
500 EXPECT_FALSE(audio_ended_); 493 EXPECT_FALSE(audio_ended_);
501 EXPECT_FALSE(recognition_ended_); 494 EXPECT_FALSE(recognition_ended_);
502 recognizer_->AbortRecognition(); 495 recognizer_->AbortRecognition();
503 base::MessageLoop::current()->RunUntilIdle(); 496 base::MessageLoop::current()->RunUntilIdle();
504 CheckFinalEventsConsistency(); 497 CheckFinalEventsConsistency();
505 } 498 }
506 499
507 } // namespace content 500 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/browser/speech/speech_recognizer_impl.cc ('k') | trunk/src/media/audio/agc_audio_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698