OLD | NEW |
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 Loading... |
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; | |
440 for (int i = 0; i < ws_event.result_size(); ++i) { | 439 for (int i = 0; i < ws_event.result_size(); ++i) { |
441 const proto::SpeechRecognitionResult& ws_result = ws_event.result(i); | 440 const proto::SpeechRecognitionResult& ws_result = ws_event.result(i); |
442 results.push_back(SpeechRecognitionResult()); | 441 SpeechRecognitionResult result; |
443 SpeechRecognitionResult& result = results.back(); | |
444 result.is_provisional = !(ws_result.has_final() && ws_result.final()); | 442 result.is_provisional = !(ws_result.has_final() && ws_result.final()); |
445 | 443 |
446 if (!result.is_provisional) | 444 if (!result.is_provisional) |
447 got_last_definitive_result_ = true; | 445 got_last_definitive_result_ = true; |
448 | 446 |
449 for (int j = 0; j < ws_result.alternative_size(); ++j) { | 447 for (int j = 0; j < ws_result.alternative_size(); ++j) { |
450 const proto::SpeechRecognitionAlternative& ws_alternative = | 448 const proto::SpeechRecognitionAlternative& ws_alternative = |
451 ws_result.alternative(j); | 449 ws_result.alternative(j); |
452 SpeechRecognitionHypothesis hypothesis; | 450 SpeechRecognitionHypothesis hypothesis; |
453 if (ws_alternative.has_confidence()) | 451 if (ws_alternative.has_confidence()) |
454 hypothesis.confidence = ws_alternative.confidence(); | 452 hypothesis.confidence = ws_alternative.confidence(); |
455 else if (ws_result.has_stability()) | 453 else if (ws_result.has_stability()) |
456 hypothesis.confidence = ws_result.stability(); | 454 hypothesis.confidence = ws_result.stability(); |
457 DCHECK(ws_alternative.has_transcript()); | 455 DCHECK(ws_alternative.has_transcript()); |
458 // TODO(hans): Perhaps the transcript should be required in the proto? | 456 // TODO(hans): Perhaps the transcript should be required in the proto? |
459 if (ws_alternative.has_transcript()) | 457 if (ws_alternative.has_transcript()) |
460 hypothesis.utterance = UTF8ToUTF16(ws_alternative.transcript()); | 458 hypothesis.utterance = UTF8ToUTF16(ws_alternative.transcript()); |
461 | 459 |
462 result.hypotheses.push_back(hypothesis); | 460 result.hypotheses.push_back(hypothesis); |
463 } | 461 } |
| 462 |
| 463 delegate()->OnSpeechRecognitionEngineResult(result); |
464 } | 464 } |
465 | 465 |
466 delegate()->OnSpeechRecognitionEngineResults(results); | |
467 | |
468 return state_; | 466 return state_; |
469 } | 467 } |
470 | 468 |
471 GoogleStreamingRemoteEngine::FSMState | 469 GoogleStreamingRemoteEngine::FSMState |
472 GoogleStreamingRemoteEngine::RaiseNoMatchErrorIfGotNoResults( | 470 GoogleStreamingRemoteEngine::RaiseNoMatchErrorIfGotNoResults( |
473 const FSMEventArgs& event_args) { | 471 const FSMEventArgs& event_args) { |
474 if (!got_last_definitive_result_) { | 472 if (!got_last_definitive_result_) { |
475 // Provide an empty result to notify that recognition is ended with no | 473 // Provide an empty result to notify that recognition is ended with no |
476 // errors, yet neither any further results. | 474 // errors, yet neither any further results. |
477 delegate()->OnSpeechRecognitionEngineResults(SpeechRecognitionResults()); | 475 delegate()->OnSpeechRecognitionEngineResult(SpeechRecognitionResult()); |
478 } | 476 } |
479 return AbortSilently(event_args); | 477 return AbortSilently(event_args); |
480 } | 478 } |
481 | 479 |
482 GoogleStreamingRemoteEngine::FSMState | 480 GoogleStreamingRemoteEngine::FSMState |
483 GoogleStreamingRemoteEngine::CloseUpstreamAndWaitForResults( | 481 GoogleStreamingRemoteEngine::CloseUpstreamAndWaitForResults( |
484 const FSMEventArgs&) { | 482 const FSMEventArgs&) { |
485 DCHECK(upstream_fetcher_.get()); | 483 DCHECK(upstream_fetcher_.get()); |
486 DCHECK(encoder_.get()); | 484 DCHECK(encoder_.get()); |
487 | 485 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 586 } |
589 | 587 |
590 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 588 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
591 : event(event_value) { | 589 : event(event_value) { |
592 } | 590 } |
593 | 591 |
594 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { | 592 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { |
595 } | 593 } |
596 | 594 |
597 } // namespace content | 595 } // namespace content |
OLD | NEW |