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

Side by Side 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: remove debug div but use console.log Created 7 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview The manager of speech recognition.
7 */
8
9 cr.define('speech', function() {
10 'use strict';
11
12 /**
13 * @constructor
14 */
15 function SpeechRecognitionManager(delegate) {
16 this.isActive = true;
17 this.delegate_ = delegate;
18
19 this.recognizer_ = new window.webkitSpeechRecognition();
20 this.recognizer_.continuous = true;
21 this.recognizer_.interimResults = true;
22 // TODO(mukai): should switch to the user's UI language.
23 this.recognizer_.lang = 'en_US';
24
25 this.recognizer_.onresult = this.onRecognizerResult_.bind(this);
26 }
27
28 /**
29 * Called when new speech recognition results arrive.
30 *
31 * @param {Event} speech_event The event to contain the recognition results.
32 * @private
33 */
34 SpeechRecognitionManager.prototype.onRecognizerResult_ = function(
35 speech_event) {
36 // Do not collect interim result for now.
37 var result = '';
38 var isFinal = false;
39 for (var i = 0; i < speech_event.results.length; i++) {
40 if (speech_event.results[i].isFinal)
41 isFinal = true;
42 result += speech_event.results[i][0].transcript;
43 }
44 if (this.delegate_)
45 this.delegate_.onSpeechRecognized(result, isFinal);
46 };
47
48 /**
49 * Starts the speech recognition through webkitSpeechRecognition.
50 */
51 SpeechRecognitionManager.prototype.start = function() {
52 if (this.delegate_) {
53 this.recognizer_.onstart =
54 this.delegate_.onSpeechRecognitionStarted.bind(this.delegate_);
55 this.recognizer_.onend =
56 this.delegate_.onSpeechRecognitionEnded.bind(this.delegate_);
57 this.recognizer_.onerror =
58 this.delegate_.onSpeechRecognitionError.bind(this.delegate_);
xiyuan 2013/10/29 18:10:07 nit: move these into constructor so that we have o
Jun Mukai 2013/10/30 01:01:32 Done.
59 }
60 this.recognizer_.start();
61 };
62
63 /**
64 * Stops the ongoing speech recognition.
65 */
66 SpeechRecognitionManager.prototype.stop = function() {
67 this.recognizer_.abort();
68 };
69
70 return {
71 SpeechRecognitionManager: SpeechRecognitionManager
72 };
73 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698