Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: content/browser/speech/speech_recognizer_unittest.cc

Issue 6615020: Stream speech audio to server as it gets recorded, instead of waiting until end of recording. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/net/test_url_fetcher_factory.h" 7 #include "chrome/common/net/test_url_fetcher_factory.h"
8 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
9 #include "content/browser/speech/speech_recognizer.h" 9 #include "content/browser/speech/speech_recognizer.h"
10 #include "media/audio/test_audio_input_controller_factory.h" 10 #include "media/audio/test_audio_input_controller_factory.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 TEST_F(SpeechRecognizerTest, StopWithData) { 132 TEST_F(SpeechRecognizerTest, StopWithData) {
133 // Start recording, give some data and then stop. This should wait for the 133 // Start recording, give some data and then stop. This should wait for the
134 // network callback to arrive before completion. 134 // network callback to arrive before completion.
135 EXPECT_TRUE(recognizer_->StartRecording()); 135 EXPECT_TRUE(recognizer_->StartRecording());
136 TestAudioInputController* controller = 136 TestAudioInputController* controller =
137 audio_input_controller_factory_.controller(); 137 audio_input_controller_factory_.controller();
138 ASSERT_TRUE(controller); 138 ASSERT_TRUE(controller);
139 controller = audio_input_controller_factory_.controller(); 139 controller = audio_input_controller_factory_.controller();
140 ASSERT_TRUE(controller); 140 ASSERT_TRUE(controller);
141 controller->event_handler()->OnData(controller, &audio_packet_[0], 141
142 audio_packet_.size()); 142 // Try sending 5 chunks of mock audio data and verify that each of them
143 MessageLoop::current()->RunAllPending(); 143 // resulted immediately in a packet sent out via the network. This verifies
144 // that we are streaming out encoded data as chunks without waiting for the
145 // full recording to complete.
146 const int kNumChunks = 5;
147 for (int i = 0; i < kNumChunks; ++i) {
bulach 2011/03/04 12:41:08 size_t both here and the const above (I think 153
148 controller->event_handler()->OnData(controller, &audio_packet_[0],
149 audio_packet_.size());
150 MessageLoop::current()->RunAllPending();
151 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
152 ASSERT_TRUE(fetcher);
153 EXPECT_EQ(i + 1, fetcher->upload_chunks().size());
154 }
155
144 recognizer_->StopRecording(); 156 recognizer_->StopRecording();
145 EXPECT_TRUE(recording_complete_); 157 EXPECT_TRUE(recording_complete_);
146 EXPECT_FALSE(recognition_complete_); 158 EXPECT_FALSE(recognition_complete_);
147 EXPECT_FALSE(result_received_); 159 EXPECT_FALSE(result_received_);
148 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); 160 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
149 161
150 // Issue the network callback to complete the process. 162 // Issue the network callback to complete the process.
151 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 163 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
152 ASSERT_TRUE(fetcher); 164 ASSERT_TRUE(fetcher);
153 net::URLRequestStatus status; 165 net::URLRequestStatus status;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_FLOAT_EQ(0.81907868f, volume_); 316 EXPECT_FLOAT_EQ(0.81907868f, volume_);
305 EXPECT_FLOAT_EQ(0.52143687f, noise_volume_); 317 EXPECT_FLOAT_EQ(0.52143687f, noise_volume_);
306 318
307 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); 319 EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
308 EXPECT_FALSE(recording_complete_); 320 EXPECT_FALSE(recording_complete_);
309 EXPECT_FALSE(recognition_complete_); 321 EXPECT_FALSE(recognition_complete_);
310 recognizer_->CancelRecognition(); 322 recognizer_->CancelRecognition();
311 } 323 }
312 324
313 } // namespace speech_input 325 } // namespace speech_input
OLDNEW
« content/browser/speech/speech_recognizer.cc ('K') | « content/browser/speech/speech_recognizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698