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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
| 10 #include <memory> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "content/browser/speech/google_streaming_remote_engine.h" | 18 #include "content/browser/speech/google_streaming_remote_engine.h" |
19 #include "content/browser/speech/speech_recognition_manager_impl.h" | 19 #include "content/browser/speech/speech_recognition_manager_impl.h" |
20 #include "content/browser/speech/speech_recognizer_impl.h" | 20 #include "content/browser/speech/speech_recognizer_impl.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 mock_streaming_server_.reset(); | 134 mock_streaming_server_.reset(); |
135 } | 135 } |
136 | 136 |
137 private: | 137 private: |
138 static void FeedSingleBufferToAudioController( | 138 static void FeedSingleBufferToAudioController( |
139 scoped_refptr<media::TestAudioInputController> controller, | 139 scoped_refptr<media::TestAudioInputController> controller, |
140 size_t buffer_size, | 140 size_t buffer_size, |
141 bool fill_with_noise) { | 141 bool fill_with_noise) { |
142 DCHECK(controller.get()); | 142 DCHECK(controller.get()); |
143 const media::AudioParameters& audio_params = controller->audio_parameters(); | 143 const media::AudioParameters& audio_params = controller->audio_parameters(); |
144 scoped_ptr<uint8_t[]> audio_buffer(new uint8_t[buffer_size]); | 144 std::unique_ptr<uint8_t[]> audio_buffer(new uint8_t[buffer_size]); |
145 if (fill_with_noise) { | 145 if (fill_with_noise) { |
146 for (size_t i = 0; i < buffer_size; ++i) | 146 for (size_t i = 0; i < buffer_size; ++i) |
147 audio_buffer[i] = | 147 audio_buffer[i] = |
148 static_cast<uint8_t>(127 * sin(i * 3.14F / (16 * buffer_size))); | 148 static_cast<uint8_t>(127 * sin(i * 3.14F / (16 * buffer_size))); |
149 } else { | 149 } else { |
150 memset(audio_buffer.get(), 0, buffer_size); | 150 memset(audio_buffer.get(), 0, buffer_size); |
151 } | 151 } |
152 | 152 |
153 scoped_ptr<media::AudioBus> audio_bus = | 153 std::unique_ptr<media::AudioBus> audio_bus = |
154 media::AudioBus::Create(audio_params); | 154 media::AudioBus::Create(audio_params); |
155 audio_bus->FromInterleaved(&audio_buffer.get()[0], | 155 audio_bus->FromInterleaved(&audio_buffer.get()[0], |
156 audio_bus->frames(), | 156 audio_bus->frames(), |
157 audio_params.bits_per_sample() / 8); | 157 audio_params.bits_per_sample() / 8); |
158 controller->event_handler()->OnData(controller.get(), audio_bus.get()); | 158 controller->event_handler()->OnData(controller.get(), audio_bus.get()); |
159 } | 159 } |
160 | 160 |
161 void FeedAudioController(int duration_ms, bool feed_with_noise) { | 161 void FeedAudioController(int duration_ms, bool feed_with_noise) { |
162 media::TestAudioInputController* controller = | 162 media::TestAudioInputController* controller = |
163 test_audio_input_controller_factory_.controller(); | 163 test_audio_input_controller_factory_.controller(); |
(...skipping 18 matching lines...) Expand all Loading... |
182 } | 182 } |
183 | 183 |
184 SpeechRecognitionResult GetGoodSpeechResult() { | 184 SpeechRecognitionResult GetGoodSpeechResult() { |
185 SpeechRecognitionResult result; | 185 SpeechRecognitionResult result; |
186 result.hypotheses.push_back(SpeechRecognitionHypothesis( | 186 result.hypotheses.push_back(SpeechRecognitionHypothesis( |
187 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); | 187 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); |
188 return result; | 188 return result; |
189 } | 189 } |
190 | 190 |
191 StreamingServerState streaming_server_state_; | 191 StreamingServerState streaming_server_state_; |
192 scoped_ptr<MockGoogleStreamingServer> mock_streaming_server_; | 192 std::unique_ptr<MockGoogleStreamingServer> mock_streaming_server_; |
193 media::TestAudioInputControllerFactory test_audio_input_controller_factory_; | 193 media::TestAudioInputControllerFactory test_audio_input_controller_factory_; |
194 }; | 194 }; |
195 | 195 |
196 // Simply loads the test page and checks if it was able to create a Speech | 196 // Simply loads the test page and checks if it was able to create a Speech |
197 // Recognition object in JavaScript, to make sure the Web Speech API is enabled. | 197 // Recognition object in JavaScript, to make sure the Web Speech API is enabled. |
198 // Flaky on all platforms. http://crbug.com/396414. | 198 // Flaky on all platforms. http://crbug.com/396414. |
199 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) { | 199 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) { |
200 NavigateToURLBlockUntilNavigationsComplete( | 200 NavigateToURLBlockUntilNavigationsComplete( |
201 shell(), GetTestUrlFromFragment("precheck"), 2); | 201 shell(), GetTestUrlFromFragment("precheck"), 2); |
202 | 202 |
203 EXPECT_EQ(kIdle, streaming_server_state()); | 203 EXPECT_EQ(kIdle, streaming_server_state()); |
204 EXPECT_EQ("success", GetPageFragment()); | 204 EXPECT_EQ("success", GetPageFragment()); |
205 } | 205 } |
206 | 206 |
207 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { | 207 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { |
208 NavigateToURLBlockUntilNavigationsComplete( | 208 NavigateToURLBlockUntilNavigationsComplete( |
209 shell(), GetTestUrlFromFragment("oneshot"), 2); | 209 shell(), GetTestUrlFromFragment("oneshot"), 2); |
210 | 210 |
211 EXPECT_EQ(kClientDisconnected, streaming_server_state()); | 211 EXPECT_EQ(kClientDisconnected, streaming_server_state()); |
212 EXPECT_EQ("goodresult1", GetPageFragment()); | 212 EXPECT_EQ("goodresult1", GetPageFragment()); |
213 } | 213 } |
214 | 214 |
215 } // namespace content | 215 } // namespace content |
OLD | NEW |