| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 11 #include "content/browser/speech/proto/google_streaming_api.pb.h" | 11 #include "content/browser/speech/proto/google_streaming_api.pb.h" |
| 12 #include "content/browser/speech/speech_recognition_engine.h" | 12 #include "content/browser/speech/speech_recognition_engine.h" |
| 13 #include "content/browser/speech/speech_recognizer_impl.h" | 13 #include "content/browser/speech/speech_recognizer_impl.h" |
| 14 #include "content/public/browser/speech_recognition_event_listener.h" | 14 #include "content/public/browser/speech_recognition_event_listener.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_device_description.h" |
| 17 #include "media/audio/fake_audio_input_stream.h" | 17 #include "media/audio/fake_audio_input_stream.h" |
| 18 #include "media/audio/fake_audio_output_stream.h" | 18 #include "media/audio/fake_audio_output_stream.h" |
| 19 #include "media/audio/mock_audio_manager.h" | 19 #include "media/audio/mock_audio_manager.h" |
| 20 #include "media/audio/test_audio_input_controller_factory.h" | 20 #include "media/audio/test_audio_input_controller_factory.h" |
| 21 #include "media/base/audio_bus.h" | 21 #include "media/base/audio_bus.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 TestAudioInputControllerFactory audio_input_controller_factory_; | 197 TestAudioInputControllerFactory audio_input_controller_factory_; |
| 198 std::vector<uint8_t> audio_packet_; | 198 std::vector<uint8_t> audio_packet_; |
| 199 std::unique_ptr<media::AudioBus> audio_bus_; | 199 std::unique_ptr<media::AudioBus> audio_bus_; |
| 200 int bytes_per_sample_; | 200 int bytes_per_sample_; |
| 201 float volume_; | 201 float volume_; |
| 202 float noise_volume_; | 202 float noise_volume_; |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 TEST_F(SpeechRecognizerImplTest, StopNoData) { | 205 TEST_F(SpeechRecognizerImplTest, StopNoData) { |
| 206 // Check for callbacks when stopping record before any audio gets recorded. | 206 // Check for callbacks when stopping record before any audio gets recorded. |
| 207 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 207 recognizer_->StartRecognition( |
| 208 media::AudioDeviceDescription::kDefaultDeviceId); |
| 208 recognizer_->StopAudioCapture(); | 209 recognizer_->StopAudioCapture(); |
| 209 base::MessageLoop::current()->RunUntilIdle(); | 210 base::MessageLoop::current()->RunUntilIdle(); |
| 210 EXPECT_TRUE(recognition_started_); | 211 EXPECT_TRUE(recognition_started_); |
| 211 EXPECT_FALSE(audio_started_); | 212 EXPECT_FALSE(audio_started_); |
| 212 EXPECT_FALSE(result_received_); | 213 EXPECT_FALSE(result_received_); |
| 213 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 214 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
| 214 CheckFinalEventsConsistency(); | 215 CheckFinalEventsConsistency(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 TEST_F(SpeechRecognizerImplTest, CancelNoData) { | 218 TEST_F(SpeechRecognizerImplTest, CancelNoData) { |
| 218 // Check for callbacks when canceling recognition before any audio gets | 219 // Check for callbacks when canceling recognition before any audio gets |
| 219 // recorded. | 220 // recorded. |
| 220 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 221 recognizer_->StartRecognition( |
| 222 media::AudioDeviceDescription::kDefaultDeviceId); |
| 221 recognizer_->AbortRecognition(); | 223 recognizer_->AbortRecognition(); |
| 222 base::MessageLoop::current()->RunUntilIdle(); | 224 base::MessageLoop::current()->RunUntilIdle(); |
| 223 EXPECT_TRUE(recognition_started_); | 225 EXPECT_TRUE(recognition_started_); |
| 224 EXPECT_FALSE(audio_started_); | 226 EXPECT_FALSE(audio_started_); |
| 225 EXPECT_FALSE(result_received_); | 227 EXPECT_FALSE(result_received_); |
| 226 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); | 228 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); |
| 227 CheckFinalEventsConsistency(); | 229 CheckFinalEventsConsistency(); |
| 228 } | 230 } |
| 229 | 231 |
| 230 TEST_F(SpeechRecognizerImplTest, StopWithData) { | 232 TEST_F(SpeechRecognizerImplTest, StopWithData) { |
| 231 // Start recording, give some data and then stop. This should wait for the | 233 // Start recording, give some data and then stop. This should wait for the |
| 232 // network callback to arrive before completion. | 234 // network callback to arrive before completion. |
| 233 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 235 recognizer_->StartRecognition( |
| 236 media::AudioDeviceDescription::kDefaultDeviceId); |
| 234 base::MessageLoop::current()->RunUntilIdle(); | 237 base::MessageLoop::current()->RunUntilIdle(); |
| 235 TestAudioInputController* controller = | 238 TestAudioInputController* controller = |
| 236 audio_input_controller_factory_.controller(); | 239 audio_input_controller_factory_.controller(); |
| 237 ASSERT_TRUE(controller); | 240 ASSERT_TRUE(controller); |
| 238 | 241 |
| 239 // Try sending 5 chunks of mock audio data and verify that each of them | 242 // Try sending 5 chunks of mock audio data and verify that each of them |
| 240 // resulted immediately in a packet sent out via the network. This verifies | 243 // resulted immediately in a packet sent out via the network. This verifies |
| 241 // that we are streaming out encoded data as chunks without waiting for the | 244 // that we are streaming out encoded data as chunks without waiting for the |
| 242 // full recording to complete. | 245 // full recording to complete. |
| 243 const size_t kNumChunks = 5; | 246 const size_t kNumChunks = 5; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 287 |
| 285 base::MessageLoop::current()->RunUntilIdle(); | 288 base::MessageLoop::current()->RunUntilIdle(); |
| 286 EXPECT_TRUE(recognition_ended_); | 289 EXPECT_TRUE(recognition_ended_); |
| 287 EXPECT_TRUE(result_received_); | 290 EXPECT_TRUE(result_received_); |
| 288 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 291 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
| 289 CheckFinalEventsConsistency(); | 292 CheckFinalEventsConsistency(); |
| 290 } | 293 } |
| 291 | 294 |
| 292 TEST_F(SpeechRecognizerImplTest, CancelWithData) { | 295 TEST_F(SpeechRecognizerImplTest, CancelWithData) { |
| 293 // Start recording, give some data and then cancel. | 296 // Start recording, give some data and then cancel. |
| 294 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 297 recognizer_->StartRecognition( |
| 298 media::AudioDeviceDescription::kDefaultDeviceId); |
| 295 base::MessageLoop::current()->RunUntilIdle(); | 299 base::MessageLoop::current()->RunUntilIdle(); |
| 296 TestAudioInputController* controller = | 300 TestAudioInputController* controller = |
| 297 audio_input_controller_factory_.controller(); | 301 audio_input_controller_factory_.controller(); |
| 298 ASSERT_TRUE(controller); | 302 ASSERT_TRUE(controller); |
| 299 controller->event_handler()->OnData(controller, audio_bus_.get()); | 303 controller->event_handler()->OnData(controller, audio_bus_.get()); |
| 300 base::MessageLoop::current()->RunUntilIdle(); | 304 base::MessageLoop::current()->RunUntilIdle(); |
| 301 recognizer_->AbortRecognition(); | 305 recognizer_->AbortRecognition(); |
| 302 base::MessageLoop::current()->RunUntilIdle(); | 306 base::MessageLoop::current()->RunUntilIdle(); |
| 303 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); | 307 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); |
| 304 EXPECT_TRUE(recognition_started_); | 308 EXPECT_TRUE(recognition_started_); |
| 305 EXPECT_TRUE(audio_started_); | 309 EXPECT_TRUE(audio_started_); |
| 306 EXPECT_FALSE(result_received_); | 310 EXPECT_FALSE(result_received_); |
| 307 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); | 311 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_ABORTED, error_); |
| 308 CheckFinalEventsConsistency(); | 312 CheckFinalEventsConsistency(); |
| 309 } | 313 } |
| 310 | 314 |
| 311 TEST_F(SpeechRecognizerImplTest, ConnectionError) { | 315 TEST_F(SpeechRecognizerImplTest, ConnectionError) { |
| 312 // Start recording, give some data and then stop. Issue the network callback | 316 // Start recording, give some data and then stop. Issue the network callback |
| 313 // with a connection error and verify that the recognizer bubbles the error up | 317 // with a connection error and verify that the recognizer bubbles the error up |
| 314 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 318 recognizer_->StartRecognition( |
| 319 media::AudioDeviceDescription::kDefaultDeviceId); |
| 315 base::MessageLoop::current()->RunUntilIdle(); | 320 base::MessageLoop::current()->RunUntilIdle(); |
| 316 TestAudioInputController* controller = | 321 TestAudioInputController* controller = |
| 317 audio_input_controller_factory_.controller(); | 322 audio_input_controller_factory_.controller(); |
| 318 ASSERT_TRUE(controller); | 323 ASSERT_TRUE(controller); |
| 319 controller->event_handler()->OnData(controller, audio_bus_.get()); | 324 controller->event_handler()->OnData(controller, audio_bus_.get()); |
| 320 base::MessageLoop::current()->RunUntilIdle(); | 325 base::MessageLoop::current()->RunUntilIdle(); |
| 321 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 326 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 322 ASSERT_TRUE(fetcher); | 327 ASSERT_TRUE(fetcher); |
| 323 | 328 |
| 324 recognizer_->StopAudioCapture(); | 329 recognizer_->StopAudioCapture(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 339 base::MessageLoop::current()->RunUntilIdle(); | 344 base::MessageLoop::current()->RunUntilIdle(); |
| 340 EXPECT_TRUE(recognition_ended_); | 345 EXPECT_TRUE(recognition_ended_); |
| 341 EXPECT_FALSE(result_received_); | 346 EXPECT_FALSE(result_received_); |
| 342 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); | 347 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); |
| 343 CheckFinalEventsConsistency(); | 348 CheckFinalEventsConsistency(); |
| 344 } | 349 } |
| 345 | 350 |
| 346 TEST_F(SpeechRecognizerImplTest, ServerError) { | 351 TEST_F(SpeechRecognizerImplTest, ServerError) { |
| 347 // Start recording, give some data and then stop. Issue the network callback | 352 // Start recording, give some data and then stop. Issue the network callback |
| 348 // with a 500 error and verify that the recognizer bubbles the error up | 353 // with a 500 error and verify that the recognizer bubbles the error up |
| 349 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 354 recognizer_->StartRecognition( |
| 355 media::AudioDeviceDescription::kDefaultDeviceId); |
| 350 base::MessageLoop::current()->RunUntilIdle(); | 356 base::MessageLoop::current()->RunUntilIdle(); |
| 351 TestAudioInputController* controller = | 357 TestAudioInputController* controller = |
| 352 audio_input_controller_factory_.controller(); | 358 audio_input_controller_factory_.controller(); |
| 353 ASSERT_TRUE(controller); | 359 ASSERT_TRUE(controller); |
| 354 controller->event_handler()->OnData(controller, audio_bus_.get()); | 360 controller->event_handler()->OnData(controller, audio_bus_.get()); |
| 355 base::MessageLoop::current()->RunUntilIdle(); | 361 base::MessageLoop::current()->RunUntilIdle(); |
| 356 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 362 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 357 ASSERT_TRUE(fetcher); | 363 ASSERT_TRUE(fetcher); |
| 358 | 364 |
| 359 recognizer_->StopAudioCapture(); | 365 recognizer_->StopAudioCapture(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 fetcher->delegate()->OnURLFetchComplete(fetcher); | 378 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 373 base::MessageLoop::current()->RunUntilIdle(); | 379 base::MessageLoop::current()->RunUntilIdle(); |
| 374 EXPECT_TRUE(recognition_ended_); | 380 EXPECT_TRUE(recognition_ended_); |
| 375 EXPECT_FALSE(result_received_); | 381 EXPECT_FALSE(result_received_); |
| 376 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); | 382 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NETWORK, error_); |
| 377 CheckFinalEventsConsistency(); | 383 CheckFinalEventsConsistency(); |
| 378 } | 384 } |
| 379 | 385 |
| 380 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorNoData) { | 386 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorNoData) { |
| 381 // Check if things tear down properly if AudioInputController threw an error. | 387 // Check if things tear down properly if AudioInputController threw an error. |
| 382 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 388 recognizer_->StartRecognition( |
| 389 media::AudioDeviceDescription::kDefaultDeviceId); |
| 383 base::MessageLoop::current()->RunUntilIdle(); | 390 base::MessageLoop::current()->RunUntilIdle(); |
| 384 TestAudioInputController* controller = | 391 TestAudioInputController* controller = |
| 385 audio_input_controller_factory_.controller(); | 392 audio_input_controller_factory_.controller(); |
| 386 ASSERT_TRUE(controller); | 393 ASSERT_TRUE(controller); |
| 387 controller->event_handler()->OnError(controller, | 394 controller->event_handler()->OnError(controller, |
| 388 AudioInputController::UNKNOWN_ERROR); | 395 AudioInputController::UNKNOWN_ERROR); |
| 389 base::MessageLoop::current()->RunUntilIdle(); | 396 base::MessageLoop::current()->RunUntilIdle(); |
| 390 EXPECT_TRUE(recognition_started_); | 397 EXPECT_TRUE(recognition_started_); |
| 391 EXPECT_FALSE(audio_started_); | 398 EXPECT_FALSE(audio_started_); |
| 392 EXPECT_FALSE(result_received_); | 399 EXPECT_FALSE(result_received_); |
| 393 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); | 400 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); |
| 394 CheckFinalEventsConsistency(); | 401 CheckFinalEventsConsistency(); |
| 395 } | 402 } |
| 396 | 403 |
| 397 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) { | 404 TEST_F(SpeechRecognizerImplTest, AudioControllerErrorWithData) { |
| 398 // Check if things tear down properly if AudioInputController threw an error | 405 // Check if things tear down properly if AudioInputController threw an error |
| 399 // after giving some audio data. | 406 // after giving some audio data. |
| 400 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 407 recognizer_->StartRecognition( |
| 408 media::AudioDeviceDescription::kDefaultDeviceId); |
| 401 base::MessageLoop::current()->RunUntilIdle(); | 409 base::MessageLoop::current()->RunUntilIdle(); |
| 402 TestAudioInputController* controller = | 410 TestAudioInputController* controller = |
| 403 audio_input_controller_factory_.controller(); | 411 audio_input_controller_factory_.controller(); |
| 404 ASSERT_TRUE(controller); | 412 ASSERT_TRUE(controller); |
| 405 controller->event_handler()->OnData(controller, audio_bus_.get()); | 413 controller->event_handler()->OnData(controller, audio_bus_.get()); |
| 406 controller->event_handler()->OnError(controller, | 414 controller->event_handler()->OnError(controller, |
| 407 AudioInputController::UNKNOWN_ERROR); | 415 AudioInputController::UNKNOWN_ERROR); |
| 408 base::MessageLoop::current()->RunUntilIdle(); | 416 base::MessageLoop::current()->RunUntilIdle(); |
| 409 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); | 417 ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); |
| 410 EXPECT_TRUE(recognition_started_); | 418 EXPECT_TRUE(recognition_started_); |
| 411 EXPECT_TRUE(audio_started_); | 419 EXPECT_TRUE(audio_started_); |
| 412 EXPECT_FALSE(result_received_); | 420 EXPECT_FALSE(result_received_); |
| 413 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); | 421 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE, error_); |
| 414 CheckFinalEventsConsistency(); | 422 CheckFinalEventsConsistency(); |
| 415 } | 423 } |
| 416 | 424 |
| 417 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) { | 425 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackIssued) { |
| 418 // Start recording and give a lot of packets with audio samples set to zero. | 426 // Start recording and give a lot of packets with audio samples set to zero. |
| 419 // This should trigger the no-speech detector and issue a callback. | 427 // This should trigger the no-speech detector and issue a callback. |
| 420 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 428 recognizer_->StartRecognition( |
| 429 media::AudioDeviceDescription::kDefaultDeviceId); |
| 421 base::MessageLoop::current()->RunUntilIdle(); | 430 base::MessageLoop::current()->RunUntilIdle(); |
| 422 TestAudioInputController* controller = | 431 TestAudioInputController* controller = |
| 423 audio_input_controller_factory_.controller(); | 432 audio_input_controller_factory_.controller(); |
| 424 ASSERT_TRUE(controller); | 433 ASSERT_TRUE(controller); |
| 425 | 434 |
| 426 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / | 435 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / |
| 427 SpeechRecognitionEngine::kAudioPacketIntervalMs + 1; | 436 SpeechRecognitionEngine::kAudioPacketIntervalMs + 1; |
| 428 // The vector is already filled with zero value samples on create. | 437 // The vector is already filled with zero value samples on create. |
| 429 for (int i = 0; i < num_packets; ++i) { | 438 for (int i = 0; i < num_packets; ++i) { |
| 430 controller->event_handler()->OnData(controller, audio_bus_.get()); | 439 controller->event_handler()->OnData(controller, audio_bus_.get()); |
| 431 } | 440 } |
| 432 base::MessageLoop::current()->RunUntilIdle(); | 441 base::MessageLoop::current()->RunUntilIdle(); |
| 433 EXPECT_TRUE(recognition_started_); | 442 EXPECT_TRUE(recognition_started_); |
| 434 EXPECT_TRUE(audio_started_); | 443 EXPECT_TRUE(audio_started_); |
| 435 EXPECT_FALSE(result_received_); | 444 EXPECT_FALSE(result_received_); |
| 436 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); | 445 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); |
| 437 CheckFinalEventsConsistency(); | 446 CheckFinalEventsConsistency(); |
| 438 } | 447 } |
| 439 | 448 |
| 440 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) { | 449 TEST_F(SpeechRecognizerImplTest, NoSpeechCallbackNotIssued) { |
| 441 // Start recording and give a lot of packets with audio samples set to zero | 450 // Start recording and give a lot of packets with audio samples set to zero |
| 442 // and then some more with reasonably loud audio samples. This should be | 451 // and then some more with reasonably loud audio samples. This should be |
| 443 // treated as normal speech input and the no-speech detector should not get | 452 // treated as normal speech input and the no-speech detector should not get |
| 444 // triggered. | 453 // triggered. |
| 445 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 454 recognizer_->StartRecognition( |
| 455 media::AudioDeviceDescription::kDefaultDeviceId); |
| 446 base::MessageLoop::current()->RunUntilIdle(); | 456 base::MessageLoop::current()->RunUntilIdle(); |
| 447 TestAudioInputController* controller = | 457 TestAudioInputController* controller = |
| 448 audio_input_controller_factory_.controller(); | 458 audio_input_controller_factory_.controller(); |
| 449 ASSERT_TRUE(controller); | 459 ASSERT_TRUE(controller); |
| 450 controller = audio_input_controller_factory_.controller(); | 460 controller = audio_input_controller_factory_.controller(); |
| 451 ASSERT_TRUE(controller); | 461 ASSERT_TRUE(controller); |
| 452 | 462 |
| 453 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / | 463 int num_packets = (SpeechRecognizerImpl::kNoSpeechTimeoutMs) / |
| 454 SpeechRecognitionEngine::kAudioPacketIntervalMs; | 464 SpeechRecognitionEngine::kAudioPacketIntervalMs; |
| 455 | 465 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 471 recognizer_->AbortRecognition(); | 481 recognizer_->AbortRecognition(); |
| 472 base::MessageLoop::current()->RunUntilIdle(); | 482 base::MessageLoop::current()->RunUntilIdle(); |
| 473 CheckFinalEventsConsistency(); | 483 CheckFinalEventsConsistency(); |
| 474 } | 484 } |
| 475 | 485 |
| 476 TEST_F(SpeechRecognizerImplTest, SetInputVolumeCallback) { | 486 TEST_F(SpeechRecognizerImplTest, SetInputVolumeCallback) { |
| 477 // Start recording and give a lot of packets with audio samples set to zero | 487 // Start recording and give a lot of packets with audio samples set to zero |
| 478 // and then some more with reasonably loud audio samples. Check that we don't | 488 // and then some more with reasonably loud audio samples. Check that we don't |
| 479 // get the callback during estimation phase, then get zero for the silence | 489 // get the callback during estimation phase, then get zero for the silence |
| 480 // samples and proper volume for the loud audio. | 490 // samples and proper volume for the loud audio. |
| 481 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 491 recognizer_->StartRecognition( |
| 492 media::AudioDeviceDescription::kDefaultDeviceId); |
| 482 base::MessageLoop::current()->RunUntilIdle(); | 493 base::MessageLoop::current()->RunUntilIdle(); |
| 483 TestAudioInputController* controller = | 494 TestAudioInputController* controller = |
| 484 audio_input_controller_factory_.controller(); | 495 audio_input_controller_factory_.controller(); |
| 485 ASSERT_TRUE(controller); | 496 ASSERT_TRUE(controller); |
| 486 controller = audio_input_controller_factory_.controller(); | 497 controller = audio_input_controller_factory_.controller(); |
| 487 ASSERT_TRUE(controller); | 498 ASSERT_TRUE(controller); |
| 488 | 499 |
| 489 // Feed some samples to begin with for the endpointer to do noise estimation. | 500 // Feed some samples to begin with for the endpointer to do noise estimation. |
| 490 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs / | 501 int num_packets = SpeechRecognizerImpl::kEndpointerEstimationTimeMs / |
| 491 SpeechRecognitionEngine::kAudioPacketIntervalMs; | 502 SpeechRecognitionEngine::kAudioPacketIntervalMs; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 509 | 520 |
| 510 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 521 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
| 511 EXPECT_FALSE(audio_ended_); | 522 EXPECT_FALSE(audio_ended_); |
| 512 EXPECT_FALSE(recognition_ended_); | 523 EXPECT_FALSE(recognition_ended_); |
| 513 recognizer_->AbortRecognition(); | 524 recognizer_->AbortRecognition(); |
| 514 base::MessageLoop::current()->RunUntilIdle(); | 525 base::MessageLoop::current()->RunUntilIdle(); |
| 515 CheckFinalEventsConsistency(); | 526 CheckFinalEventsConsistency(); |
| 516 } | 527 } |
| 517 | 528 |
| 518 } // namespace content | 529 } // namespace content |
| OLD | NEW |