| Index: content/renderer/speech_recognition_dispatcher.cc
|
| ===================================================================
|
| --- content/renderer/speech_recognition_dispatcher.cc (revision 170700)
|
| +++ content/renderer/speech_recognition_dispatcher.cc (working copy)
|
| @@ -46,8 +46,7 @@
|
| IPC_MESSAGE_HANDLER(SpeechRecognitionMsg_AudioEnded, OnAudioEnded)
|
| IPC_MESSAGE_HANDLER(SpeechRecognitionMsg_ErrorOccurred, OnErrorOccurred)
|
| IPC_MESSAGE_HANDLER(SpeechRecognitionMsg_Ended, OnRecognitionEnded)
|
| - IPC_MESSAGE_HANDLER(SpeechRecognitionMsg_ResultRetrieved,
|
| - OnResultsRetrieved)
|
| + IPC_MESSAGE_HANDLER(SpeechRecognitionMsg_ResultRetrieved, OnResultRetrieved)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| return handled;
|
| @@ -156,53 +155,31 @@
|
| }
|
|
|
| void SpeechRecognitionDispatcher::OnRecognitionEnded(int request_id) {
|
| - // TODO(tommi): It is possible that the handle isn't found in the array if
|
| - // the user just refreshed the page. It seems that we then get a notification
|
| - // for the previously loaded instance of the page.
|
| - HandleMap::iterator iter = handle_map_.find(request_id);
|
| - if (iter == handle_map_.end()) {
|
| - DLOG(ERROR) << "OnRecognitionEnded called for a handle that doesn't exist";
|
| - } else {
|
| - WebSpeechRecognitionHandle handle = iter->second;
|
| - // Note: we need to erase the handle from the map *before* calling didEnd.
|
| - // didEnd may call back synchronously to start a new recognition session,
|
| - // and we don't want to delete the handle from the map after that happens.
|
| - handle_map_.erase(request_id);
|
| - recognizer_client_->didEnd(handle);
|
| - }
|
| + WebSpeechRecognitionHandle handle = GetHandleFromID(request_id);
|
| + // Note: we need to erase the handle from the map *before* calling didEnd.
|
| + // didEnd may call back synchronously to start a new recognition session,
|
| + // and we don't want to delete the handle from the map after that happens.
|
| + handle_map_.erase(request_id);
|
| + recognizer_client_->didEnd(handle);
|
| }
|
|
|
| -void SpeechRecognitionDispatcher::OnResultsRetrieved(
|
| - int request_id, const SpeechRecognitionResults& results) {
|
| - size_t provisional_count = 0;
|
| - SpeechRecognitionResults::const_iterator it = results.begin();
|
| - for (; it != results.end(); ++it) {
|
| - if (it->is_provisional)
|
| - ++provisional_count;
|
| +void SpeechRecognitionDispatcher::OnResultRetrieved(
|
| + int request_id, const SpeechRecognitionResult& result) {
|
| + const size_t num_hypotheses = result.hypotheses.size();
|
| + WebSpeechRecognitionResult webkit_result;
|
| + WebVector<WebString> transcripts(num_hypotheses);
|
| + WebVector<float> confidences(num_hypotheses);
|
| + for (size_t i = 0; i < num_hypotheses; ++i) {
|
| + transcripts[i] = result.hypotheses[i].utterance;
|
| + confidences[i] = static_cast<float>(result.hypotheses[i].confidence);
|
| }
|
| -
|
| - WebVector<WebSpeechRecognitionResult> provisional(provisional_count);
|
| - WebVector<WebSpeechRecognitionResult> final(
|
| - results.size() - provisional_count);
|
| -
|
| - int provisional_index = 0, final_index = 0;
|
| - for (it = results.begin(); it != results.end(); ++it) {
|
| - const SpeechRecognitionResult& result = (*it);
|
| - WebSpeechRecognitionResult* webkit_result = result.is_provisional ?
|
| - &provisional[provisional_index++] : &final[final_index++];
|
| -
|
| - const size_t num_hypotheses = result.hypotheses.size();
|
| - WebVector<WebString> transcripts(num_hypotheses);
|
| - WebVector<float> confidences(num_hypotheses);
|
| - for (size_t i = 0; i < num_hypotheses; ++i) {
|
| - transcripts[i] = result.hypotheses[i].utterance;
|
| - confidences[i] = static_cast<float>(result.hypotheses[i].confidence);
|
| - }
|
| - webkit_result->assign(transcripts, confidences, !result.is_provisional);
|
| - }
|
| -
|
| - recognizer_client_->didReceiveResults(
|
| - GetHandleFromID(request_id), final, provisional);
|
| + webkit_result.assign(transcripts, confidences, !result.is_provisional);
|
| + // TODO(primiano): Handle history, currently empty.
|
| + WebVector<WebSpeechRecognitionResult> empty_history;
|
| + recognizer_client_->didReceiveResult(GetHandleFromID(request_id),
|
| + webkit_result,
|
| + 0, // result_index
|
| + empty_history);
|
| }
|
|
|
|
|
|
|