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

Side by Side Diff: chrome/browser/speech/speech_input_extension_manager.cc

Issue 11421103: Update the Speech Api to support array(s) of result items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sigh Created 8 years 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/speech/speech_input_extension_manager.h" 5 #include "chrome/browser/speech/speech_input_extension_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 extensions::ExtensionSystem::Get(profile_)->process_manager(); 256 extensions::ExtensionSystem::Get(profile_)->process_manager();
257 DCHECK(epm); 257 DCHECK(epm);
258 extensions::ExtensionHost* eh = 258 extensions::ExtensionHost* eh =
259 epm->GetBackgroundHostForExtension(extension_id); 259 epm->GetBackgroundHostForExtension(extension_id);
260 DCHECK(eh); 260 DCHECK(eh);
261 content::RenderProcessHost* rph = eh->render_process_host(); 261 content::RenderProcessHost* rph = eh->render_process_host();
262 DCHECK(rph); 262 DCHECK(rph);
263 return rph->GetID(); 263 return rph->GetID();
264 } 264 }
265 265
266 void SpeechInputExtensionManager::OnRecognitionResult( 266 void SpeechInputExtensionManager::OnRecognitionResults(
267 int session_id, 267 int session_id,
268 const content::SpeechRecognitionResult& result) { 268 const content::SpeechRecognitionResults& results) {
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
270 DCHECK_EQ(session_id, speech_recognition_session_id_); 270 DCHECK_EQ(session_id, speech_recognition_session_id_);
271 271
272 // Stopping will start the disassociation with the extension. 272 // Stopping will start the disassociation with the extension.
273 // Make a copy to report the results to the proper one. 273 // Make a copy to report the results to the proper one.
274 std::string extension_id = extension_id_in_use_; 274 std::string extension_id = extension_id_in_use_;
275 ForceStopOnIOThread(); 275 ForceStopOnIOThread();
276 276
277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
278 base::Bind(&SpeechInputExtensionManager::SetRecognitionResultOnUIThread, 278 base::Bind(&SpeechInputExtensionManager::SetRecognitionResultsOnUIThread,
279 this, result, extension_id)); 279 this, results, extension_id));
280 } 280 }
281 281
282 void SpeechInputExtensionManager::SetRecognitionResultOnUIThread( 282 void SpeechInputExtensionManager::SetRecognitionResultsOnUIThread(
283 const content::SpeechRecognitionResult& result, 283 const content::SpeechRecognitionResults& results,
284 const std::string& extension_id) { 284 const std::string& extension_id) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
286 286
287 scoped_ptr<ListValue> args(new ListValue()); 287 content::SpeechRecognitionResults::const_iterator it = results.begin();
288 DictionaryValue* js_event = new DictionaryValue(); 288 for (; it != results.end(); ++it) {
289 args->Append(js_event); 289 const content::SpeechRecognitionResult& result = (*it);
290 290
291 ListValue* js_hypothesis_array = new ListValue(); 291 scoped_ptr<ListValue> args(new ListValue());
292 js_event->Set(kHypothesesKey, js_hypothesis_array); 292 DictionaryValue* js_event = new DictionaryValue();
293 args->Append(js_event);
293 294
294 for (size_t i = 0; i < result.hypotheses.size(); ++i) { 295 ListValue* js_hypothesis_array = new ListValue();
295 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i]; 296 js_event->Set(kHypothesesKey, js_hypothesis_array);
296 297
297 DictionaryValue* js_hypothesis_object = new DictionaryValue(); 298 for (size_t i = 0; i < result.hypotheses.size(); ++i) {
298 js_hypothesis_array->Append(js_hypothesis_object); 299 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i];
299 300
300 js_hypothesis_object->SetString(kUtteranceKey, 301 DictionaryValue* js_hypothesis_object = new DictionaryValue();
301 UTF16ToUTF8(hypothesis.utterance)); 302 js_hypothesis_array->Append(js_hypothesis_object);
302 js_hypothesis_object->SetDouble(kConfidenceKey, 303
303 hypothesis.confidence); 304 js_hypothesis_object->SetString(kUtteranceKey,
305 UTF16ToUTF8(hypothesis.utterance));
306 js_hypothesis_object->SetDouble(kConfidenceKey,
307 hypothesis.confidence);
308 }
309
310 DispatchEventToExtension(extension_id, kOnResultEvent, args.Pass());
304 } 311 }
305
306 DispatchEventToExtension(extension_id, kOnResultEvent, args.Pass());
307 } 312 }
308 313
309 void SpeechInputExtensionManager::OnRecognitionStart(int session_id) { 314 void SpeechInputExtensionManager::OnRecognitionStart(int session_id) {
310 DCHECK_EQ(session_id, speech_recognition_session_id_); 315 DCHECK_EQ(session_id, speech_recognition_session_id_);
311 } 316 }
312 317
313 void SpeechInputExtensionManager::OnAudioStart(int session_id) { 318 void SpeechInputExtensionManager::OnAudioStart(int session_id) {
314 VLOG(1) << "OnAudioStart"; 319 VLOG(1) << "OnAudioStart";
315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
316 DCHECK_EQ(session_id, speech_recognition_session_id_); 321 DCHECK_EQ(session_id, speech_recognition_session_id_);
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 content::NotificationService::current()->Notify( 755 content::NotificationService::current()->Notify(
751 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STOPPED, 756 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STOPPED,
752 // Guarded by the state_ == kShutdown check. 757 // Guarded by the state_ == kShutdown check.
753 content::Source<Profile>(profile_), 758 content::Source<Profile>(profile_),
754 content::Details<std::string>(&extension_id)); 759 content::Details<std::string>(&extension_id));
755 } 760 }
756 761
757 void SpeechInputExtensionManager::OnAudioLevelsChange(int session_id, 762 void SpeechInputExtensionManager::OnAudioLevelsChange(int session_id,
758 float volume, 763 float volume,
759 float noise_volume) {} 764 float noise_volume) {}
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_input_extension_manager.h ('k') | content/browser/speech/google_one_shot_remote_engine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698