Skip to content

Commit 2b0f67f

Browse files
author
primiano@chromium.org
committed
Adding support for the SpeechRecognition.maxAlternatives JS API parameter (Speech CL2.5)
BUG=116954 TEST=none Review URL: https://chromiumcodereview.appspot.com/10629003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144487 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 2115e1e commit 2b0f67f

11 files changed

+25
-11
lines changed

content/browser/speech/google_one_shot_remote_engine.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const int kWebServiceStatusNoSpeech = 4;
3737
const int kWebServiceStatusNoMatch = 5;
3838
const speech::AudioEncoder::Codec kDefaultAudioCodec =
3939
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;
4340

4441
bool ParseServerResponse(const std::string& response_body,
4542
SpeechRecognitionResult* result,
@@ -198,7 +195,7 @@ void GoogleOneShotRemoteEngine::StartRecognition() {
198195
if (!config_.hardware_info.empty())
199196
parts.push_back("xhw=" + net::EscapeQueryParamValue(config_.hardware_info,
200197
true));
201-
parts.push_back("maxresults=" + base::IntToString(kMaxResults));
198+
parts.push_back("maxresults=" + base::UintToString(config_.max_hypotheses));
202199
parts.push_back(config_.filter_profanities ? "pfilter=2" : "pfilter=0");
203200

204201
GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));

content/browser/speech/google_streaming_remote_engine.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ using net::URLFetcher;
3535

3636
namespace {
3737

38-
// TODO(primiano): This shouldn't be a const, rather it should be taken from
39-
// maxNBest property (which is not yet implemented in WebKit).
40-
const int kMaxResults = 5;
4138
const char kDownstreamUrl[] = "/down?";
4239
const char kUpstreamUrl[] = "/up?";
4340
const int kAudioPacketIntervalMs = 100;
@@ -322,8 +319,6 @@ GoogleStreamingRemoteEngine::ConnectBothStreams(const FSMEventArgs&) {
322319
std::vector<std::string> downstream_args;
323320
downstream_args.push_back("sky=" + GetWebserviceKey());
324321
downstream_args.push_back("pair=" + request_key);
325-
downstream_args.push_back("maxresults=" + base::IntToString(kMaxResults));
326-
327322
GURL downstream_url(GetWebserviceBaseURL() + std::string(kDownstreamUrl) +
328323
JoinString(downstream_args, '&'));
329324
// TODO(primiano): /////////// Remove this after debug stage. /////////////
@@ -347,9 +342,12 @@ GoogleStreamingRemoteEngine::ConnectBothStreams(const FSMEventArgs&) {
347342
"lang=" + net::EscapeQueryParamValue(GetAcceptedLanguages(), true));
348343
upstream_args.push_back(
349344
config_.filter_profanities ? "pfilter=2" : "pfilter=0");
350-
upstream_args.push_back("maxresults=" + base::IntToString(kMaxResults));
345+
if (config_.max_hypotheses > 0U) {
346+
upstream_args.push_back("maxresults=" +
347+
base::UintToString(config_.max_hypotheses));
348+
}
349+
// TODO(primiano) What is this client= parameter? Check with speech team.
351350
upstream_args.push_back("client=myapp.mycompany.com");
352-
// TODO(primiano): Can we remove this feature sending audio HW information?
353351
if (!config_.hardware_info.empty()) {
354352
upstream_args.push_back(
355353
"xhw=" + net::EscapeQueryParamValue(config_.hardware_info, true));

content/browser/speech/input_tag_speech_dispatcher_host.cc

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ using content::SpeechRecognitionManager;
1616
using content::SpeechRecognitionSessionConfig;
1717
using content::SpeechRecognitionSessionContext;
1818

19+
namespace {
20+
const uint32 kMaxHypothesesForSpeechInputTag = 6;
21+
}
22+
1923
namespace speech {
2024
SpeechRecognitionManager* InputTagSpeechDispatcherHost::manager_for_tests_;
2125

@@ -77,6 +81,7 @@ void InputTagSpeechDispatcherHost::OnStartRecognition(
7781
config.grammars.push_back(
7882
content::SpeechRecognitionGrammar(params.grammar));
7983
}
84+
config.max_hypotheses = kMaxHypothesesForSpeechInputTag;
8085
config.origin_url = params.origin_url;
8186
config.initial_context = context;
8287
config.url_request_context_getter = url_request_context_getter_.get();

content/browser/speech/speech_recognition_dispatcher_host.cc

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void SpeechRecognitionDispatcherHost::OnStartRequest(
8383
config.is_one_shot = params.is_one_shot;
8484
config.language = params.language;
8585
config.grammars = params.grammars;
86+
config.max_hypotheses = params.max_hypotheses;
8687
config.origin_url = params.origin_url;
8788
config.initial_context = context;
8889
config.url_request_context_getter = context_getter_.get();

content/browser/speech/speech_recognition_engine.cc

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
namespace {
88
const int kDefaultConfigSampleRate = 8000;
99
const int kDefaultConfigBitsPerSample = 16;
10+
const uint32 kDefaultMaxHypotheses = 1;
1011
} // namespace
1112

1213
namespace speech {
1314

1415
SpeechRecognitionEngine::Config::Config()
1516
: filter_profanities(false),
17+
max_hypotheses(kDefaultMaxHypotheses),
1618
audio_sample_rate(kDefaultConfigSampleRate),
1719
audio_num_bits_per_sample(kDefaultConfigBitsPerSample) {
1820
}

content/browser/speech/speech_recognition_engine.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class SpeechRecognitionEngine {
5656
std::string language;
5757
content::SpeechRecognitionGrammarArray grammars;
5858
bool filter_profanities;
59+
uint32 max_hypotheses;
5960
std::string hardware_info;
6061
std::string origin_url;
6162
int audio_sample_rate;

content/browser/speech/speech_recognition_manager_impl.cc

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int SpeechRecognitionManagerImpl::CreateSession(
9898
remote_engine_config.audio_num_bits_per_sample =
9999
SpeechRecognizer::kNumBitsPerAudioSample;
100100
remote_engine_config.filter_profanities = config.filter_profanities;
101+
remote_engine_config.max_hypotheses = config.max_hypotheses;
101102
remote_engine_config.hardware_info = hardware_info;
102103
remote_engine_config.origin_url = can_report_metrics ? config.origin_url : "";
103104

content/common/speech_recognition_messages.h

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ IPC_STRUCT_BEGIN(SpeechRecognitionHostMsg_StartRequest_Params)
117117
IPC_STRUCT_MEMBER(std::string, origin_url)
118118
// One-shot/continuous recognition mode.
119119
IPC_STRUCT_MEMBER(bool, is_one_shot)
120+
// Maximum number of hypotheses allowed for each results.
121+
IPC_STRUCT_MEMBER(uint32, max_hypotheses)
120122
IPC_STRUCT_END()
121123

122124

content/public/browser/speech_recognition_session_config.cc

+5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
#include "content/public/browser/speech_recognition_session_config.h"
66

7+
namespace {
8+
const uint32 kDefaultMaxHypotheses = 1;
9+
}
10+
711
namespace content {
812

913
SpeechRecognitionSessionConfig::SpeechRecognitionSessionConfig()
1014
: is_one_shot(true),
1115
filter_profanities(false),
16+
max_hypotheses(kDefaultMaxHypotheses),
1217
event_listener(NULL) {
1318
}
1419

content/public/browser/speech_recognition_session_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct CONTENT_EXPORT SpeechRecognitionSessionConfig {
3030
SpeechRecognitionGrammarArray grammars;
3131
std::string origin_url;
3232
bool filter_profanities;
33+
uint32 max_hypotheses;
3334
SpeechRecognitionSessionContext initial_context;
3435
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter;
3536
SpeechRecognitionEventListener* event_listener;

content/renderer/speech_recognition_dispatcher.cc

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void SpeechRecognitionDispatcher::start(
7373
}
7474
msg_params.language = UTF16ToUTF8(params.language());
7575
msg_params.is_one_shot = !params.continuous();
76+
msg_params.max_hypotheses = static_cast<uint32>(params.maxAlternatives());
7677
msg_params.origin_url = params.origin().toString().utf8();
7778
msg_params.render_view_id = routing_id();
7879
msg_params.request_id = GetOrCreateIDForHandle(handle);

0 commit comments

Comments
 (0)