OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | |
9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/single_thread_task_runner.h" | |
12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | |
14 #include "content/browser/speech/google_streaming_remote_engine.h" | 11 #include "content/browser/speech/google_streaming_remote_engine.h" |
15 #include "content/browser/speech/speech_recognition_manager_impl.h" | 12 #include "content/browser/speech/speech_recognition_manager_impl.h" |
16 #include "content/browser/speech/speech_recognizer_impl.h" | 13 #include "content/browser/speech/speech_recognizer_impl.h" |
17 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/content_browser_test.h" | 18 #include "content/public/test/content_browser_test.h" |
22 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
23 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const size_t buffer_size = audio_params.GetBytesPerBuffer(); | 159 const size_t buffer_size = audio_params.GetBytesPerBuffer(); |
163 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 / | 160 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 / |
164 audio_params.sample_rate(); | 161 audio_params.sample_rate(); |
165 // We can only simulate durations that are integer multiples of the | 162 // We can only simulate durations that are integer multiples of the |
166 // buffer size. In this regard see | 163 // buffer size. In this regard see |
167 // SpeechRecognitionEngine::GetDesiredAudioChunkDurationMs(). | 164 // SpeechRecognitionEngine::GetDesiredAudioChunkDurationMs(). |
168 ASSERT_EQ(0, duration_ms % ms_per_buffer); | 165 ASSERT_EQ(0, duration_ms % ms_per_buffer); |
169 | 166 |
170 const int n_buffers = duration_ms / ms_per_buffer; | 167 const int n_buffers = duration_ms / ms_per_buffer; |
171 for (int i = 0; i < n_buffers; ++i) { | 168 for (int i = 0; i < n_buffers; ++i) { |
172 base::ThreadTaskRunnerHandle::Get()->PostTask( | 169 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
173 FROM_HERE, | 170 &FeedSingleBufferToAudioController, |
174 base::Bind(&FeedSingleBufferToAudioController, | 171 scoped_refptr<media::TestAudioInputController>(controller), |
175 scoped_refptr<media::TestAudioInputController>(controller), | 172 buffer_size, |
176 buffer_size, feed_with_noise)); | 173 feed_with_noise)); |
177 } | 174 } |
178 } | 175 } |
179 | 176 |
180 SpeechRecognitionResult GetGoodSpeechResult() { | 177 SpeechRecognitionResult GetGoodSpeechResult() { |
181 SpeechRecognitionResult result; | 178 SpeechRecognitionResult result; |
182 result.hypotheses.push_back(SpeechRecognitionHypothesis( | 179 result.hypotheses.push_back(SpeechRecognitionHypothesis( |
183 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); | 180 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); |
184 return result; | 181 return result; |
185 } | 182 } |
186 | 183 |
(...skipping 15 matching lines...) Expand all Loading... |
202 | 199 |
203 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { | 200 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { |
204 NavigateToURLBlockUntilNavigationsComplete( | 201 NavigateToURLBlockUntilNavigationsComplete( |
205 shell(), GetTestUrlFromFragment("oneshot"), 2); | 202 shell(), GetTestUrlFromFragment("oneshot"), 2); |
206 | 203 |
207 EXPECT_EQ(kClientDisconnected, streaming_server_state()); | 204 EXPECT_EQ(kClientDisconnected, streaming_server_state()); |
208 EXPECT_EQ("goodresult1", GetPageFragment()); | 205 EXPECT_EQ("goodresult1", GetPageFragment()); |
209 } | 206 } |
210 | 207 |
211 } // namespace content | 208 } // namespace content |
OLD | NEW |