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

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

Issue 11421103: Update the Speech Api to support array(s) of result items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix issue with page reloads and add a TODO. Created 8 years 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) 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_streaming_remote_engine.h" 5 #include "content/browser/speech/google_streaming_remote_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // TODO(hans): We need a better error code for this. 429 // TODO(hans): We need a better error code for this.
430 return Abort(SPEECH_RECOGNITION_ERROR_ABORTED); 430 return Abort(SPEECH_RECOGNITION_ERROR_ABORTED);
431 case proto::SpeechRecognitionEvent::STATUS_BAD_GRAMMAR: 431 case proto::SpeechRecognitionEvent::STATUS_BAD_GRAMMAR:
432 return Abort(SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR); 432 return Abort(SPEECH_RECOGNITION_ERROR_BAD_GRAMMAR);
433 case proto::SpeechRecognitionEvent::STATUS_LANGUAGE_NOT_SUPPORTED: 433 case proto::SpeechRecognitionEvent::STATUS_LANGUAGE_NOT_SUPPORTED:
434 // TODO(hans): We need a better error code for this. 434 // TODO(hans): We need a better error code for this.
435 return Abort(SPEECH_RECOGNITION_ERROR_ABORTED); 435 return Abort(SPEECH_RECOGNITION_ERROR_ABORTED);
436 } 436 }
437 } 437 }
438 438
439 SpeechRecognitionResults results;
439 for (int i = 0; i < ws_event.result_size(); ++i) { 440 for (int i = 0; i < ws_event.result_size(); ++i) {
440 const proto::SpeechRecognitionResult& ws_result = ws_event.result(i); 441 const proto::SpeechRecognitionResult& ws_result = ws_event.result(i);
441 SpeechRecognitionResult result; 442 results.push_back(SpeechRecognitionResult());
443 SpeechRecognitionResult& result = results.back();
442 result.is_provisional = !(ws_result.has_final() && ws_result.final()); 444 result.is_provisional = !(ws_result.has_final() && ws_result.final());
443 445
444 if (!result.is_provisional) 446 if (!result.is_provisional)
445 got_last_definitive_result_ = true; 447 got_last_definitive_result_ = true;
446 448
447 for (int j = 0; j < ws_result.alternative_size(); ++j) { 449 for (int j = 0; j < ws_result.alternative_size(); ++j) {
448 const proto::SpeechRecognitionAlternative& ws_alternative = 450 const proto::SpeechRecognitionAlternative& ws_alternative =
449 ws_result.alternative(j); 451 ws_result.alternative(j);
450 SpeechRecognitionHypothesis hypothesis; 452 SpeechRecognitionHypothesis hypothesis;
451 if (ws_alternative.has_confidence()) 453 if (ws_alternative.has_confidence())
452 hypothesis.confidence = ws_alternative.confidence(); 454 hypothesis.confidence = ws_alternative.confidence();
453 else if (ws_result.has_stability()) 455 else if (ws_result.has_stability())
454 hypothesis.confidence = ws_result.stability(); 456 hypothesis.confidence = ws_result.stability();
455 DCHECK(ws_alternative.has_transcript()); 457 DCHECK(ws_alternative.has_transcript());
456 // TODO(hans): Perhaps the transcript should be required in the proto? 458 // TODO(hans): Perhaps the transcript should be required in the proto?
457 if (ws_alternative.has_transcript()) 459 if (ws_alternative.has_transcript())
458 hypothesis.utterance = UTF8ToUTF16(ws_alternative.transcript()); 460 hypothesis.utterance = UTF8ToUTF16(ws_alternative.transcript());
459 461
460 result.hypotheses.push_back(hypothesis); 462 result.hypotheses.push_back(hypothesis);
461 } 463 }
464 }
462 465
463 delegate()->OnSpeechRecognitionEngineResult(result); 466 delegate()->OnSpeechRecognitionEngineResults(results);
464 }
465 467
466 return state_; 468 return state_;
467 } 469 }
468 470
469 GoogleStreamingRemoteEngine::FSMState 471 GoogleStreamingRemoteEngine::FSMState
470 GoogleStreamingRemoteEngine::RaiseNoMatchErrorIfGotNoResults( 472 GoogleStreamingRemoteEngine::RaiseNoMatchErrorIfGotNoResults(
471 const FSMEventArgs& event_args) { 473 const FSMEventArgs& event_args) {
472 if (!got_last_definitive_result_) { 474 if (!got_last_definitive_result_) {
473 // Provide an empty result to notify that recognition is ended with no 475 // Provide an empty result to notify that recognition is ended with no
474 // errors, yet neither any further results. 476 // errors, yet neither any further results.
475 delegate()->OnSpeechRecognitionEngineResult(SpeechRecognitionResult()); 477 delegate()->OnSpeechRecognitionEngineResults(SpeechRecognitionResults());
476 } 478 }
477 return AbortSilently(event_args); 479 return AbortSilently(event_args);
478 } 480 }
479 481
480 GoogleStreamingRemoteEngine::FSMState 482 GoogleStreamingRemoteEngine::FSMState
481 GoogleStreamingRemoteEngine::CloseUpstreamAndWaitForResults( 483 GoogleStreamingRemoteEngine::CloseUpstreamAndWaitForResults(
482 const FSMEventArgs&) { 484 const FSMEventArgs&) {
483 DCHECK(upstream_fetcher_.get()); 485 DCHECK(upstream_fetcher_.get());
484 DCHECK(encoder_.get()); 486 DCHECK(encoder_.get());
485 487
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 588 }
587 589
588 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 590 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
589 : event(event_value) { 591 : event(event_value) {
590 } 592 }
591 593
592 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { 594 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() {
593 } 595 }
594 596
595 } // namespace content 597 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698