| 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 <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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 SpeechRecognitionEngine* sr_engine = | 48 SpeechRecognitionEngine* sr_engine = |
| 49 new GoogleOneShotRemoteEngine(NULL /* URLRequestContextGetter */); | 49 new GoogleOneShotRemoteEngine(NULL /* URLRequestContextGetter */); |
| 50 SpeechRecognitionEngineConfig config; | 50 SpeechRecognitionEngineConfig config; |
| 51 config.audio_num_bits_per_sample = | 51 config.audio_num_bits_per_sample = |
| 52 SpeechRecognizerImpl::kNumBitsPerAudioSample; | 52 SpeechRecognizerImpl::kNumBitsPerAudioSample; |
| 53 config.audio_sample_rate = SpeechRecognizerImpl::kAudioSampleRate; | 53 config.audio_sample_rate = SpeechRecognizerImpl::kAudioSampleRate; |
| 54 config.filter_profanities = false; | 54 config.filter_profanities = false; |
| 55 sr_engine->SetConfig(config); | 55 sr_engine->SetConfig(config); |
| 56 | 56 |
| 57 const int kTestingSessionId = 1; | 57 const int kTestingSessionId = 1; |
| 58 recognizer_ = new SpeechRecognizerImpl( | 58 recognizer_ = new SpeechRecognizerImpl(this, |
| 59 this, kTestingSessionId, false, false, sr_engine); | 59 kTestingSessionId, |
| 60 false, // continuous |
| 61 false, // provisional_results |
| 62 false, // using_audio_receiver |
| 63 base::kNullProcessHandle, |
| 64 sr_engine); |
| 60 audio_manager_.reset(new media::MockAudioManager( | 65 audio_manager_.reset(new media::MockAudioManager( |
| 61 base::MessageLoop::current()->message_loop_proxy().get())); | 66 base::MessageLoop::current()->message_loop_proxy().get())); |
| 62 recognizer_->SetAudioManagerForTesting(audio_manager_.get()); | 67 recognizer_->SetAudioManagerForTesting(audio_manager_.get()); |
| 63 | 68 |
| 64 int audio_packet_length_bytes = | 69 int audio_packet_length_bytes = |
| 65 (SpeechRecognizerImpl::kAudioSampleRate * | 70 (SpeechRecognizerImpl::kAudioSampleRate * |
| 66 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs * | 71 GoogleOneShotRemoteEngine::kAudioPacketIntervalMs * |
| 67 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout) * | 72 ChannelLayoutToChannelCount(SpeechRecognizerImpl::kChannelLayout) * |
| 68 SpeechRecognizerImpl::kNumBitsPerAudioSample) / (8 * 1000); | 73 SpeechRecognizerImpl::kNumBitsPerAudioSample) / (8 * 1000); |
| 69 audio_packet_.resize(audio_packet_length_bytes); | 74 audio_packet_.resize(audio_packet_length_bytes); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 CheckEventsConsistency(); | 134 CheckEventsConsistency(); |
| 130 } | 135 } |
| 131 | 136 |
| 132 void OnRecognitionStart(int session_id) override { | 137 void OnRecognitionStart(int session_id) override { |
| 133 recognition_started_ = true; | 138 recognition_started_ = true; |
| 134 CheckEventsConsistency(); | 139 CheckEventsConsistency(); |
| 135 } | 140 } |
| 136 | 141 |
| 137 void OnEnvironmentEstimationComplete(int session_id) override {} | 142 void OnEnvironmentEstimationComplete(int session_id) override {} |
| 138 | 143 |
| 144 virtual void OnAudioReceiverReady( |
| 145 int session_id, |
| 146 const media::AudioParameters& params, |
| 147 const base::SharedMemoryHandle memory, |
| 148 const base::SyncSocket::TransitDescriptor socket) override {} |
| 149 |
| 139 void OnSoundStart(int session_id) override { | 150 void OnSoundStart(int session_id) override { |
| 140 sound_started_ = true; | 151 sound_started_ = true; |
| 141 CheckEventsConsistency(); | 152 CheckEventsConsistency(); |
| 142 } | 153 } |
| 143 | 154 |
| 144 void OnSoundEnd(int session_id) override { | 155 void OnSoundEnd(int session_id) override { |
| 145 sound_ended_ = true; | 156 sound_ended_ = true; |
| 146 CheckEventsConsistency(); | 157 CheckEventsConsistency(); |
| 147 } | 158 } |
| 148 | 159 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 510 |
| 500 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 511 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
| 501 EXPECT_FALSE(audio_ended_); | 512 EXPECT_FALSE(audio_ended_); |
| 502 EXPECT_FALSE(recognition_ended_); | 513 EXPECT_FALSE(recognition_ended_); |
| 503 recognizer_->AbortRecognition(); | 514 recognizer_->AbortRecognition(); |
| 504 base::MessageLoop::current()->RunUntilIdle(); | 515 base::MessageLoop::current()->RunUntilIdle(); |
| 505 CheckFinalEventsConsistency(); | 516 CheckFinalEventsConsistency(); |
| 506 } | 517 } |
| 507 | 518 |
| 508 } // namespace content | 519 } // namespace content |
| OLD | NEW |