Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_recognizer_impl.h" | 5 #include "content/browser/speech/speech_recognizer_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // |input_bus_| should only be provide once. | 166 // |input_bus_| should only be provide once. |
| 167 waiting_for_input_ = false; | 167 waiting_for_input_ = false; |
| 168 return 1; | 168 return 1; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // SpeechRecognizerImpl implementation | 171 // SpeechRecognizerImpl implementation |
| 172 | 172 |
| 173 SpeechRecognizerImpl::SpeechRecognizerImpl( | 173 SpeechRecognizerImpl::SpeechRecognizerImpl( |
| 174 SpeechRecognitionEventListener* listener, | 174 SpeechRecognitionEventListener* listener, |
| 175 int session_id, | 175 int session_id, |
| 176 bool is_single_shot, | 176 bool continuous, |
| 177 bool provisional_results, | |
| 177 SpeechRecognitionEngine* engine) | 178 SpeechRecognitionEngine* engine) |
| 178 : SpeechRecognizer(listener, session_id), | 179 : SpeechRecognizer(listener, session_id), |
| 179 recognition_engine_(engine), | 180 recognition_engine_(engine), |
| 180 endpointer_(kAudioSampleRate), | 181 endpointer_(kAudioSampleRate), |
| 181 is_dispatching_event_(false), | 182 is_dispatching_event_(false), |
| 182 is_single_shot_(is_single_shot), | 183 provisional_results_(provisional_results), |
| 183 state_(STATE_IDLE) { | 184 state_(STATE_IDLE) { |
| 184 DCHECK(recognition_engine_ != NULL); | 185 DCHECK(recognition_engine_ != NULL); |
| 185 if (is_single_shot) { | 186 if (!continuous) { |
| 186 // In single shot recognition, the session is automatically ended after: | 187 // In single shot (non-continous) recognition, |
| 188 // the session is automatically ended after: | |
| 187 // - 0.5 seconds of silence if time < 3 seconds | 189 // - 0.5 seconds of silence if time < 3 seconds |
| 188 // - 1 seconds of silence if time >= 3 seconds | 190 // - 1 seconds of silence if time >= 3 seconds |
| 189 endpointer_.set_speech_input_complete_silence_length( | 191 endpointer_.set_speech_input_complete_silence_length( |
| 190 base::Time::kMicrosecondsPerSecond / 2); | 192 base::Time::kMicrosecondsPerSecond / 2); |
| 191 endpointer_.set_long_speech_input_complete_silence_length( | 193 endpointer_.set_long_speech_input_complete_silence_length( |
| 192 base::Time::kMicrosecondsPerSecond); | 194 base::Time::kMicrosecondsPerSecond); |
| 193 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond); | 195 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond); |
| 194 } else { | 196 } else { |
| 195 // In continuous recognition, the session is automatically ended after 15 | 197 // In continuous recognition, the session is automatically ended after 15 |
| 196 // seconds of silence. | 198 // seconds of silence. |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 if (error.code != SPEECH_RECOGNITION_ERROR_NONE) | 680 if (error.code != SPEECH_RECOGNITION_ERROR_NONE) |
| 679 listener()->OnRecognitionError(session_id(), error); | 681 listener()->OnRecognitionError(session_id(), error); |
| 680 | 682 |
| 681 listener()->OnRecognitionEnd(session_id()); | 683 listener()->OnRecognitionEnd(session_id()); |
| 682 | 684 |
| 683 return STATE_ENDED; | 685 return STATE_ENDED; |
| 684 } | 686 } |
| 685 | 687 |
| 686 SpeechRecognizerImpl::FSMState SpeechRecognizerImpl::ProcessIntermediateResult( | 688 SpeechRecognizerImpl::FSMState SpeechRecognizerImpl::ProcessIntermediateResult( |
| 687 const FSMEventArgs& event_args) { | 689 const FSMEventArgs& event_args) { |
| 688 // Provisional results can occur only during continuous (non one-shot) mode. | 690 // Provisional results can occur only if explicitly enabled in the JS API. |
| 689 // If this check is reached it means that a continuous speech recognition | 691 DCHECK_EQ(true, provisional_results_); |
|
tommi (sloooow) - chröme
2014/01/15 15:42:07
DCHECK(provisional_results_);
Tommy Widenflycht
2014/01/15 15:50:15
Done.
| |
| 690 // engine is being used for a one shot recognition. | |
| 691 DCHECK_EQ(false, is_single_shot_); | |
| 692 | 692 |
| 693 // In continuous recognition, intermediate results can occur even when we are | 693 // In continuous recognition, intermediate results can occur even when we are |
| 694 // in the ESTIMATING_ENVIRONMENT or WAITING_FOR_SPEECH states (if the | 694 // in the ESTIMATING_ENVIRONMENT or WAITING_FOR_SPEECH states (if the |
| 695 // recognition engine is "faster" than our endpointer). In these cases we | 695 // recognition engine is "faster" than our endpointer). In these cases we |
| 696 // skip the endpointer and fast-forward to the RECOGNIZING state, with respect | 696 // skip the endpointer and fast-forward to the RECOGNIZING state, with respect |
| 697 // of the events triggering order. | 697 // of the events triggering order. |
| 698 if (state_ == STATE_ESTIMATING_ENVIRONMENT) { | 698 if (state_ == STATE_ESTIMATING_ENVIRONMENT) { |
| 699 DCHECK(endpointer_.IsEstimatingEnvironment()); | 699 DCHECK(endpointer_.IsEstimatingEnvironment()); |
| 700 endpointer_.SetUserInputMode(); | 700 endpointer_.SetUserInputMode(); |
| 701 listener()->OnEnvironmentEstimationComplete(session_id()); | 701 listener()->OnEnvironmentEstimationComplete(session_id()); |
| 702 } else if (state_ == STATE_WAITING_FOR_SPEECH) { | 702 } else if (state_ == STATE_WAITING_FOR_SPEECH) { |
| 703 listener()->OnSoundStart(session_id()); | 703 listener()->OnSoundStart(session_id()); |
| 704 } else { | 704 } else { |
| 705 DCHECK_EQ(STATE_RECOGNIZING, state_); | 705 DCHECK_EQ(STATE_RECOGNIZING, state_); |
| 706 } | 706 } |
| 707 | 707 |
| 708 listener()->OnRecognitionResults(session_id(), event_args.engine_results); | 708 listener()->OnRecognitionResults(session_id(), event_args.engine_results); |
| 709 return STATE_RECOGNIZING; | 709 return STATE_RECOGNIZING; |
| 710 } | 710 } |
| 711 | 711 |
| 712 SpeechRecognizerImpl::FSMState | 712 SpeechRecognizerImpl::FSMState |
| 713 SpeechRecognizerImpl::ProcessFinalResult(const FSMEventArgs& event_args) { | 713 SpeechRecognizerImpl::ProcessFinalResult(const FSMEventArgs& event_args) { |
| 714 const SpeechRecognitionResults& results = event_args.engine_results; | 714 const SpeechRecognitionResults& results = event_args.engine_results; |
| 715 SpeechRecognitionResults::const_iterator i = results.begin(); | 715 SpeechRecognitionResults::const_iterator i = results.begin(); |
| 716 bool provisional_results_pending = false; | 716 bool provisional_results_pending = false; |
| 717 bool results_are_empty = true; | 717 bool results_are_empty = true; |
| 718 for (; i != results.end(); ++i) { | 718 for (; i != results.end(); ++i) { |
| 719 const SpeechRecognitionResult& result = *i; | 719 const SpeechRecognitionResult& result = *i; |
| 720 if (result.is_provisional) { | 720 if (result.is_provisional) { |
| 721 DCHECK_EQ(true, provisional_results_); | |
|
tommi (sloooow) - chröme
2014/01/15 15:42:07
DCHECK(provisional_results_);
Tommy Widenflycht
2014/01/15 15:50:15
Done.
| |
| 721 provisional_results_pending = true; | 722 provisional_results_pending = true; |
| 722 DCHECK(!is_single_shot_); | |
| 723 } else if (results_are_empty) { | 723 } else if (results_are_empty) { |
| 724 results_are_empty = result.hypotheses.empty(); | 724 results_are_empty = result.hypotheses.empty(); |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 | 727 |
| 728 if (provisional_results_pending) { | 728 if (provisional_results_pending) { |
| 729 listener()->OnRecognitionResults(session_id(), results); | 729 listener()->OnRecognitionResults(session_id(), results); |
| 730 // We don't end the recognition if a provisional result is received in | 730 // We don't end the recognition if a provisional result is received in |
| 731 // STATE_WAITING_FINAL_RESULT. A definitive result will come next and will | 731 // STATE_WAITING_FINAL_RESULT. A definitive result will come next and will |
| 732 // end the recognition. | 732 // end the recognition. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 810 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 811 : event(event_value), | 811 : event(event_value), |
| 812 audio_data(NULL), | 812 audio_data(NULL), |
| 813 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { | 813 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { |
| 814 } | 814 } |
| 815 | 815 |
| 816 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { | 816 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { |
| 817 } | 817 } |
| 818 | 818 |
| 819 } // namespace content | 819 } // namespace content |
| OLD | NEW |