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

Side by Side Diff: content/browser/speech/speech_recognition_request.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 "content/browser/speech/speech_recognition_request.h" 5 #include "content/browser/speech/speech_recognition_request.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 SpeechRecognitionRequest::SpeechRecognitionRequest( 114 SpeechRecognitionRequest::SpeechRecognitionRequest(
115 URLRequestContextGetter* context, Delegate* delegate) 115 URLRequestContextGetter* context, Delegate* delegate)
116 : url_context_(context), 116 : url_context_(context),
117 delegate_(delegate) { 117 delegate_(delegate) {
118 DCHECK(delegate); 118 DCHECK(delegate);
119 } 119 }
120 120
121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} 121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {}
122 122
123 bool SpeechRecognitionRequest::Send(const std::string& language, 123 void SpeechRecognitionRequest::Start(const std::string& language,
124 const std::string& grammar, 124 const std::string& grammar,
125 const std::string& hardware_info, 125 const std::string& hardware_info,
126 const std::string& origin_url, 126 const std::string& origin_url,
127 const std::string& content_type, 127 const std::string& content_type) {
128 const std::string& audio_data) {
129 DCHECK(!url_fetcher_.get()); 128 DCHECK(!url_fetcher_.get());
130 129
131 std::vector<std::string> parts; 130 std::vector<std::string> parts;
132 131
133 std::string lang_param = language; 132 std::string lang_param = language;
134 if (lang_param.empty() && url_context_) { 133 if (lang_param.empty() && url_context_) {
135 // If no language is provided then we use the first from the accepted 134 // If no language is provided then we use the first from the accepted
136 // language list. If this list is empty then it defaults to "en-US". 135 // language list. If this list is empty then it defaults to "en-US".
137 // Example of the contents of this list: "es,en-GB;q=0.8", "" 136 // Example of the contents of this list: "es,en-GB;q=0.8", ""
138 net::URLRequestContext* request_context = 137 net::URLRequestContext* request_context =
(...skipping 14 matching lines...) Expand all
153 // TODO(satish): Remove this hardcoded value once the page is allowed to 152 // TODO(satish): Remove this hardcoded value once the page is allowed to
154 // set this via an attribute. 153 // set this via an attribute.
155 parts.push_back("maxresults=3"); 154 parts.push_back("maxresults=3");
156 155
157 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 156 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
158 157
159 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 158 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
160 url, 159 url,
161 URLFetcher::POST, 160 URLFetcher::POST,
162 this)); 161 this));
163 url_fetcher_->set_upload_data(content_type, audio_data); 162 url_fetcher_->set_chunked_upload(content_type);
164 url_fetcher_->set_request_context(url_context_); 163 url_fetcher_->set_request_context(url_context_);
165 url_fetcher_->set_referrer(origin_url); 164 url_fetcher_->set_referrer(origin_url);
166 165
167 // The speech recognition API does not require user identification as part 166 // The speech recognition API does not require user identification as part
168 // of requests, so we don't send cookies or auth data for these requests to 167 // of requests, so we don't send cookies or auth data for these requests to
169 // prevent any accidental connection between users who are logged into the 168 // prevent any accidental connection between users who are logged into the
170 // domain for other services (e.g. bookmark sync) with the speech requests. 169 // domain for other services (e.g. bookmark sync) with the speech requests.
171 url_fetcher_->set_load_flags( 170 url_fetcher_->set_load_flags(
172 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | 171 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
173 net::LOAD_DO_NOT_SEND_AUTH_DATA); 172 net::LOAD_DO_NOT_SEND_AUTH_DATA);
174 url_fetcher_->Start(); 173 url_fetcher_->Start();
175 return true; 174 }
175
176 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data,
177 bool is_last_chunk) {
178 DCHECK(url_fetcher_.get());
179 url_fetcher_->AppendChunkToUpload(audio_data, is_last_chunk);
176 } 180 }
177 181
178 void SpeechRecognitionRequest::OnURLFetchComplete( 182 void SpeechRecognitionRequest::OnURLFetchComplete(
179 const URLFetcher* source, 183 const URLFetcher* source,
180 const GURL& url, 184 const GURL& url,
181 const net::URLRequestStatus& status, 185 const net::URLRequestStatus& status,
182 int response_code, 186 int response_code,
183 const ResponseCookies& cookies, 187 const ResponseCookies& cookies,
184 const std::string& data) { 188 const std::string& data) {
185 DCHECK_EQ(url_fetcher_.get(), source); 189 DCHECK_EQ(url_fetcher_.get(), source);
186 190
187 bool error = !status.is_success() || response_code != 200; 191 bool error = !status.is_success() || response_code != 200;
188 SpeechInputResultArray result; 192 SpeechInputResultArray result;
189 if (!error) 193 if (!error)
190 error = !ParseServerResponse(data, &result); 194 error = !ParseServerResponse(data, &result);
191 url_fetcher_.reset(); 195 url_fetcher_.reset();
192 196
193 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 197 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
194 delegate_->SetRecognitionResult(error, result); 198 delegate_->SetRecognitionResult(error, result);
195 } 199 }
196 200
197 } // namespace speech_input 201 } // namespace speech_input
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognition_request.h ('k') | content/browser/speech/speech_recognition_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698