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

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

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

Powered by Google App Engine
This is Rietveld 408576698