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

Side by Side Diff: third_party/WebKit/Source/web/SpeechRecognitionClientProxy.cpp

Issue 2877303002: Move speech related files from web -> modules/(speech|exported). (Closed)
Patch Set: Created 3 years, 7 months 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "web/SpeechRecognitionClientProxy.h"
27
28 #include <memory>
29 #include "core/dom/ExecutionContext.h"
30 #include "modules/mediastream/MediaStreamTrack.h"
31 #include "modules/speech/SpeechGrammarList.h"
32 #include "modules/speech/SpeechRecognition.h"
33 #include "modules/speech/SpeechRecognitionError.h"
34 #include "modules/speech/SpeechRecognitionResult.h"
35 #include "modules/speech/SpeechRecognitionResultList.h"
36 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/weborigin/SecurityOrigin.h"
38 #include "platform/wtf/PassRefPtr.h"
39 #include "platform/wtf/PtrUtil.h"
40 #include "public/platform/WebMediaStreamTrack.h"
41 #include "public/platform/WebSecurityOrigin.h"
42 #include "public/web/WebSpeechGrammar.h"
43 #include "public/web/WebSpeechRecognitionHandle.h"
44 #include "public/web/WebSpeechRecognitionParams.h"
45 #include "public/web/WebSpeechRecognitionResult.h"
46 #include "public/web/WebSpeechRecognizer.h"
47
48 namespace blink {
49
50 SpeechRecognitionClientProxy::~SpeechRecognitionClientProxy() {}
51
52 std::unique_ptr<SpeechRecognitionClientProxy>
53 SpeechRecognitionClientProxy::Create(WebSpeechRecognizer* recognizer) {
54 return WTF::WrapUnique(new SpeechRecognitionClientProxy(recognizer));
55 }
56
57 void SpeechRecognitionClientProxy::Start(SpeechRecognition* recognition,
58 const SpeechGrammarList* grammar_list,
59 const String& lang,
60 bool continuous,
61 bool interim_results,
62 unsigned long max_alternatives,
63 MediaStreamTrack* audio_track) {
64 size_t length =
65 grammar_list ? static_cast<size_t>(grammar_list->length()) : 0U;
66 WebVector<WebSpeechGrammar> web_speech_grammars(length);
67 for (unsigned long i = 0; i < length; ++i)
68 web_speech_grammars[i] = grammar_list->item(i);
69
70 WebMediaStreamTrack track;
71 if (RuntimeEnabledFeatures::mediaStreamSpeechEnabled() && audio_track)
72 track.Assign(audio_track->Component());
73 WebSpeechRecognitionParams params(
74 web_speech_grammars, lang, continuous, interim_results, max_alternatives,
75 track,
76 WebSecurityOrigin(
77 recognition->GetExecutionContext()->GetSecurityOrigin()));
78 recognizer_->Start(recognition, params, this);
79 }
80
81 void SpeechRecognitionClientProxy::Stop(SpeechRecognition* recognition) {
82 recognizer_->Stop(recognition, this);
83 }
84
85 void SpeechRecognitionClientProxy::Abort(SpeechRecognition* recognition) {
86 recognizer_->Abort(recognition, this);
87 }
88
89 void SpeechRecognitionClientProxy::DidStartAudio(
90 const WebSpeechRecognitionHandle& handle) {
91 SpeechRecognition* recognition(handle);
92 recognition->DidStartAudio();
93 }
94
95 void SpeechRecognitionClientProxy::DidStartSound(
96 const WebSpeechRecognitionHandle& handle) {
97 SpeechRecognition* recognition(handle);
98 recognition->DidStartSound();
99 recognition->DidStartSpeech();
100 }
101
102 void SpeechRecognitionClientProxy::DidEndSound(
103 const WebSpeechRecognitionHandle& handle) {
104 SpeechRecognition* recognition(handle);
105 recognition->DidEndSpeech();
106 recognition->DidEndSound();
107 }
108
109 void SpeechRecognitionClientProxy::DidEndAudio(
110 const WebSpeechRecognitionHandle& handle) {
111 SpeechRecognition* recognition(handle);
112 recognition->DidEndAudio();
113 }
114
115 void SpeechRecognitionClientProxy::DidReceiveResults(
116 const WebSpeechRecognitionHandle& handle,
117 const WebVector<WebSpeechRecognitionResult>& new_final_results,
118 const WebVector<WebSpeechRecognitionResult>& current_interim_results) {
119 SpeechRecognition* recognition(handle);
120
121 HeapVector<Member<SpeechRecognitionResult>> final_results_vector(
122 new_final_results.size());
123 for (size_t i = 0; i < new_final_results.size(); ++i)
124 final_results_vector[i] =
125 Member<SpeechRecognitionResult>(new_final_results[i]);
126
127 HeapVector<Member<SpeechRecognitionResult>> interim_results_vector(
128 current_interim_results.size());
129 for (size_t i = 0; i < current_interim_results.size(); ++i)
130 interim_results_vector[i] =
131 Member<SpeechRecognitionResult>(current_interim_results[i]);
132
133 recognition->DidReceiveResults(final_results_vector, interim_results_vector);
134 }
135
136 void SpeechRecognitionClientProxy::DidReceiveNoMatch(
137 const WebSpeechRecognitionHandle& handle,
138 const WebSpeechRecognitionResult& result) {
139 SpeechRecognition* recognition(handle);
140 recognition->DidReceiveNoMatch(result);
141 }
142
143 void SpeechRecognitionClientProxy::DidReceiveError(
144 const WebSpeechRecognitionHandle& handle,
145 const WebString& message,
146 WebSpeechRecognizerClient::ErrorCode code) {
147 SpeechRecognition* recognition(handle);
148 SpeechRecognitionError::ErrorCode error_code =
149 static_cast<SpeechRecognitionError::ErrorCode>(code);
150 recognition->DidReceiveError(
151 SpeechRecognitionError::Create(error_code, message));
152 }
153
154 void SpeechRecognitionClientProxy::DidStart(
155 const WebSpeechRecognitionHandle& handle) {
156 SpeechRecognition* recognition(handle);
157 recognition->DidStart();
158 }
159
160 void SpeechRecognitionClientProxy::DidEnd(
161 const WebSpeechRecognitionHandle& handle) {
162 SpeechRecognition* recognition(handle);
163 recognition->DidEnd();
164 }
165
166 SpeechRecognitionClientProxy::SpeechRecognitionClientProxy(
167 WebSpeechRecognizer* recognizer)
168 : recognizer_(recognizer) {}
169
170 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/SpeechRecognitionClientProxy.h ('k') | third_party/WebKit/Source/web/WebSpeechGrammar.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698