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> |
| 6 #include <stdint.h> |
| 7 |
5 #include <vector> | 8 #include <vector> |
6 | 9 |
7 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
8 #include "content/browser/speech/google_one_shot_remote_engine.h" | 11 #include "content/browser/speech/google_one_shot_remote_engine.h" |
9 #include "content/browser/speech/speech_recognizer_impl.h" | 12 #include "content/browser/speech/speech_recognizer_impl.h" |
10 #include "content/public/browser/speech_recognition_event_listener.h" | 13 #include "content/public/browser/speech_recognition_event_listener.h" |
11 #include "media/audio/audio_manager_base.h" | 14 #include "media/audio/audio_manager_base.h" |
12 #include "media/audio/fake_audio_input_stream.h" | 15 #include "media/audio/fake_audio_input_stream.h" |
13 #include "media/audio/fake_audio_output_stream.h" | 16 #include "media/audio/fake_audio_output_stream.h" |
14 #include "media/audio/mock_audio_manager.h" | 17 #include "media/audio/mock_audio_manager.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 160 |
158 void CopyPacketToAudioBus() { | 161 void CopyPacketToAudioBus() { |
159 // Copy the created signal into an audio bus in a deinterleaved format. | 162 // Copy the created signal into an audio bus in a deinterleaved format. |
160 audio_bus_->FromInterleaved( | 163 audio_bus_->FromInterleaved( |
161 &audio_packet_[0], audio_bus_->frames(), bytes_per_sample_); | 164 &audio_packet_[0], audio_bus_->frames(), bytes_per_sample_); |
162 } | 165 } |
163 | 166 |
164 void FillPacketWithTestWaveform() { | 167 void FillPacketWithTestWaveform() { |
165 // Fill the input with a simple pattern, a 125Hz sawtooth waveform. | 168 // Fill the input with a simple pattern, a 125Hz sawtooth waveform. |
166 for (size_t i = 0; i < audio_packet_.size(); ++i) | 169 for (size_t i = 0; i < audio_packet_.size(); ++i) |
167 audio_packet_[i] = static_cast<uint8>(i); | 170 audio_packet_[i] = static_cast<uint8_t>(i); |
168 CopyPacketToAudioBus(); | 171 CopyPacketToAudioBus(); |
169 } | 172 } |
170 | 173 |
171 void FillPacketWithNoise() { | 174 void FillPacketWithNoise() { |
172 int value = 0; | 175 int value = 0; |
173 int factor = 175; | 176 int factor = 175; |
174 for (size_t i = 0; i < audio_packet_.size(); ++i) { | 177 for (size_t i = 0; i < audio_packet_.size(); ++i) { |
175 value += factor; | 178 value += factor; |
176 audio_packet_[i] = value % 100; | 179 audio_packet_[i] = value % 100; |
177 } | 180 } |
178 CopyPacketToAudioBus(); | 181 CopyPacketToAudioBus(); |
179 } | 182 } |
180 | 183 |
181 protected: | 184 protected: |
182 base::MessageLoopForIO message_loop_; | 185 base::MessageLoopForIO message_loop_; |
183 BrowserThreadImpl io_thread_; | 186 BrowserThreadImpl io_thread_; |
184 scoped_refptr<SpeechRecognizerImpl> recognizer_; | 187 scoped_refptr<SpeechRecognizerImpl> recognizer_; |
185 scoped_ptr<AudioManager> audio_manager_; | 188 scoped_ptr<AudioManager> audio_manager_; |
186 bool recognition_started_; | 189 bool recognition_started_; |
187 bool recognition_ended_; | 190 bool recognition_ended_; |
188 bool result_received_; | 191 bool result_received_; |
189 bool audio_started_; | 192 bool audio_started_; |
190 bool audio_ended_; | 193 bool audio_ended_; |
191 bool sound_started_; | 194 bool sound_started_; |
192 bool sound_ended_; | 195 bool sound_ended_; |
193 SpeechRecognitionErrorCode error_; | 196 SpeechRecognitionErrorCode error_; |
194 net::TestURLFetcherFactory url_fetcher_factory_; | 197 net::TestURLFetcherFactory url_fetcher_factory_; |
195 TestAudioInputControllerFactory audio_input_controller_factory_; | 198 TestAudioInputControllerFactory audio_input_controller_factory_; |
196 std::vector<uint8> audio_packet_; | 199 std::vector<uint8_t> audio_packet_; |
197 scoped_ptr<media::AudioBus> audio_bus_; | 200 scoped_ptr<media::AudioBus> audio_bus_; |
198 int bytes_per_sample_; | 201 int bytes_per_sample_; |
199 float volume_; | 202 float volume_; |
200 float noise_volume_; | 203 float noise_volume_; |
201 }; | 204 }; |
202 | 205 |
203 TEST_F(SpeechRecognizerImplTest, StopNoData) { | 206 TEST_F(SpeechRecognizerImplTest, StopNoData) { |
204 // Check for callbacks when stopping record before any audio gets recorded. | 207 // Check for callbacks when stopping record before any audio gets recorded. |
205 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); | 208 recognizer_->StartRecognition(media::AudioManagerBase::kDefaultDeviceId); |
206 recognizer_->StopAudioCapture(); | 209 recognizer_->StopAudioCapture(); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 495 |
493 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); | 496 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); |
494 EXPECT_FALSE(audio_ended_); | 497 EXPECT_FALSE(audio_ended_); |
495 EXPECT_FALSE(recognition_ended_); | 498 EXPECT_FALSE(recognition_ended_); |
496 recognizer_->AbortRecognition(); | 499 recognizer_->AbortRecognition(); |
497 base::MessageLoop::current()->RunUntilIdle(); | 500 base::MessageLoop::current()->RunUntilIdle(); |
498 CheckFinalEventsConsistency(); | 501 CheckFinalEventsConsistency(); |
499 } | 502 } |
500 | 503 |
501 } // namespace content | 504 } // namespace content |
OLD | NEW |