OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/test/mock_google_streaming_server.h" | 5 #include "content/test/mock_google_streaming_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/safe_numerics.h" | 8 #include "base/safe_numerics.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 const SpeechRecognitionResult& result) { | 86 const SpeechRecognitionResult& result) { |
87 proto::SpeechRecognitionEvent proto_event; | 87 proto::SpeechRecognitionEvent proto_event; |
88 proto_event.set_status(proto::SpeechRecognitionEvent::STATUS_SUCCESS); | 88 proto_event.set_status(proto::SpeechRecognitionEvent::STATUS_SUCCESS); |
89 proto::SpeechRecognitionResult* proto_result = proto_event.add_result(); | 89 proto::SpeechRecognitionResult* proto_result = proto_event.add_result(); |
90 proto_result->set_final(!result.is_provisional); | 90 proto_result->set_final(!result.is_provisional); |
91 for (size_t i = 0; i < result.hypotheses.size(); ++i) { | 91 for (size_t i = 0; i < result.hypotheses.size(); ++i) { |
92 proto::SpeechRecognitionAlternative* proto_alternative = | 92 proto::SpeechRecognitionAlternative* proto_alternative = |
93 proto_result->add_alternative(); | 93 proto_result->add_alternative(); |
94 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i]; | 94 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i]; |
95 proto_alternative->set_confidence(hypothesis.confidence); | 95 proto_alternative->set_confidence(hypothesis.confidence); |
96 proto_alternative->set_transcript(UTF16ToUTF8(hypothesis.utterance)); | 96 proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance)); |
97 } | 97 } |
98 | 98 |
99 std::string msg_string; | 99 std::string msg_string; |
100 proto_event.SerializeToString(&msg_string); | 100 proto_event.SerializeToString(&msg_string); |
101 | 101 |
102 // Prepend 4 byte prefix length indication to the protobuf message as | 102 // Prepend 4 byte prefix length indication to the protobuf message as |
103 // envisaged by the google streaming recognition webservice protocol. | 103 // envisaged by the google streaming recognition webservice protocol. |
104 uint32 prefix = HostToNet32(checked_numeric_cast<uint32>(msg_string.size())); | 104 uint32 prefix = HostToNet32(checked_numeric_cast<uint32>(msg_string.size())); |
105 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); | 105 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); |
106 | 106 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 // Can return NULL if the SpeechRecognizer has not requested the connection yet. | 141 // Can return NULL if the SpeechRecognizer has not requested the connection yet. |
142 net::TestURLFetcher* MockGoogleStreamingServer::GetURLFetcher( | 142 net::TestURLFetcher* MockGoogleStreamingServer::GetURLFetcher( |
143 bool downstream) const { | 143 bool downstream) const { |
144 return url_fetcher_factory_.GetFetcherByID( | 144 return url_fetcher_factory_.GetFetcherByID( |
145 downstream ? kDownstreamUrlFetcherId : kUpstreamUrlFetcherId); | 145 downstream ? kDownstreamUrlFetcherId : kUpstreamUrlFetcherId); |
146 } | 146 } |
147 | 147 |
148 } // namespace content | 148 } // namespace content |
OLD | NEW |