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

Unified Diff: chrome/browser/resources/app_list/speech_recognition_manager.js

Issue 29763004: Embeds offline voice recognizer plugin and its manager to app-list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/app_list/speech_recognition_manager.js
diff --git a/chrome/browser/resources/app_list/speech_recognition_manager.js b/chrome/browser/resources/app_list/speech_recognition_manager.js
new file mode 100644
index 0000000000000000000000000000000000000000..ed781acbcdc632e16f9e329720ae7bc4cd6462a5
--- /dev/null
+++ b/chrome/browser/resources/app_list/speech_recognition_manager.js
@@ -0,0 +1,73 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview The manager of speech recognition.
+ */
+
+cr.define('speech', function() {
+ 'use strict';
+
+ /**
+ * @constructor
+ */
+ function SpeechRecognitionManager(delegate) {
+ this.isActive = true;
+ this.delegate_ = delegate;
+
+ this.recognizer_ = new window.webkitSpeechRecognition();
+ this.recognizer_.continuous = true;
+ this.recognizer_.interimResults = true;
+ // TODO(mukai): should switch to the user's UI language.
+ this.recognizer_.lang = 'en_US';
+
+ this.recognizer_.onresult = this.onRecognizerResult_.bind(this);
+ if (this.delegate_) {
+ this.recognizer_.onstart =
+ this.delegate_.onSpeechRecognitionStarted.bind(this.delegate_);
+ this.recognizer_.onend =
+ this.delegate_.onSpeechRecognitionEnded.bind(this.delegate_);
+ this.recognizer_.onerror =
+ this.delegate_.onSpeechRecognitionError.bind(this.delegate_);
+ }
+ }
+
+ /**
+ * Called when new speech recognition results arrive.
+ *
+ * @param {Event} speechEvent The event to contain the recognition results.
+ * @private
+ */
+ SpeechRecognitionManager.prototype.onRecognizerResult_ = function(
+ speechEvent) {
+ // Do not collect interim result for now.
+ var result = '';
+ var isFinal = false;
+ for (var i = 0; i < speechEvent.results.length; i++) {
+ if (speechEvent.results[i].isFinal)
+ isFinal = true;
+ result += speechEvent.results[i][0].transcript;
+ }
+ if (this.delegate_)
+ this.delegate_.onSpeechRecognized(result, isFinal);
+ };
+
+ /**
+ * Starts the speech recognition through webkitSpeechRecognition.
+ */
+ SpeechRecognitionManager.prototype.start = function() {
+ this.recognizer_.start();
+ };
+
+ /**
+ * Stops the ongoing speech recognition.
+ */
+ SpeechRecognitionManager.prototype.stop = function() {
+ this.recognizer_.abort();
+ };
+
+ return {
+ SpeechRecognitionManager: SpeechRecognitionManager
+ };
+});
« no previous file with comments | « chrome/browser/resources/app_list/speech_manager.js ('k') | chrome/browser/resources/app_list/start_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698