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

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

Issue 10629003: Adding support for the SpeechRecognition.maxAlternatives JS API parameter (Speech CL2.5) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits + rebase Created 8 years, 6 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
« no previous file with comments | « no previous file | content/browser/speech/google_streaming_remote_engine.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google_one_shot_remote_engine.h" 5 #include "content/browser/speech/google_one_shot_remote_engine.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_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 19 matching lines...) Expand all
30 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; 30 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&";
31 const char* const kStatusString = "status"; 31 const char* const kStatusString = "status";
32 const char* const kHypothesesString = "hypotheses"; 32 const char* const kHypothesesString = "hypotheses";
33 const char* const kUtteranceString = "utterance"; 33 const char* const kUtteranceString = "utterance";
34 const char* const kConfidenceString = "confidence"; 34 const char* const kConfidenceString = "confidence";
35 const int kWebServiceStatusNoError = 0; 35 const int kWebServiceStatusNoError = 0;
36 const int kWebServiceStatusNoSpeech = 4; 36 const int kWebServiceStatusNoSpeech = 4;
37 const int kWebServiceStatusNoMatch = 5; 37 const int kWebServiceStatusNoMatch = 5;
38 const speech::AudioEncoder::Codec kDefaultAudioCodec = 38 const speech::AudioEncoder::Codec kDefaultAudioCodec =
39 speech::AudioEncoder::CODEC_FLAC; 39 speech::AudioEncoder::CODEC_FLAC;
40 // TODO(satish): Remove this hardcoded value once the page is allowed to
41 // set this via an attribute.
42 const int kMaxResults = 6;
43 40
44 bool ParseServerResponse(const std::string& response_body, 41 bool ParseServerResponse(const std::string& response_body,
45 SpeechRecognitionResult* result, 42 SpeechRecognitionResult* result,
46 SpeechRecognitionError* error) { 43 SpeechRecognitionError* error) {
47 if (response_body.empty()) { 44 if (response_body.empty()) {
48 LOG(WARNING) << "ParseServerResponse: Response was empty."; 45 LOG(WARNING) << "ParseServerResponse: Response was empty.";
49 return false; 46 return false;
50 } 47 }
51 DVLOG(1) << "ParseServerResponse: Parsing response " << response_body; 48 DVLOG(1) << "ParseServerResponse: Parsing response " << response_body;
52 49
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 188
192 if (!config_.grammars.empty()) { 189 if (!config_.grammars.empty()) {
193 DCHECK_EQ(config_.grammars.size(), 1U); 190 DCHECK_EQ(config_.grammars.size(), 1U);
194 parts.push_back("lm=" + net::EscapeQueryParamValue(config_.grammars[0].url, 191 parts.push_back("lm=" + net::EscapeQueryParamValue(config_.grammars[0].url,
195 true)); 192 true));
196 } 193 }
197 194
198 if (!config_.hardware_info.empty()) 195 if (!config_.hardware_info.empty())
199 parts.push_back("xhw=" + net::EscapeQueryParamValue(config_.hardware_info, 196 parts.push_back("xhw=" + net::EscapeQueryParamValue(config_.hardware_info,
200 true)); 197 true));
201 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); 198 parts.push_back("maxresults=" + base::UintToString(config_.max_hypotheses));
202 parts.push_back(config_.filter_profanities ? "pfilter=2" : "pfilter=0"); 199 parts.push_back(config_.filter_profanities ? "pfilter=2" : "pfilter=0");
203 200
204 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 201 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
205 202
206 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, 203 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec,
207 config_.audio_sample_rate, 204 config_.audio_sample_rate,
208 config_.audio_num_bits_per_sample)); 205 config_.audio_num_bits_per_sample));
209 DCHECK(encoder_.get()); 206 DCHECK(encoder_.get());
210 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests, 207 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests,
211 url, 208 url,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 282
286 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { 283 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const {
287 return url_fetcher_ != NULL; 284 return url_fetcher_ != NULL;
288 } 285 }
289 286
290 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { 287 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const {
291 return kAudioPacketIntervalMs; 288 return kAudioPacketIntervalMs;
292 } 289 }
293 290
294 } // namespace speech 291 } // namespace speech
OLDNEW
« no previous file with comments | « no previous file | content/browser/speech/google_streaming_remote_engine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698