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

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: fix 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 if (this.delegate_) {
27 this.recognizer_.onstart =
28 this.delegate_.onSpeechRecognitionStarted.bind(this.delegate_);
29 this.recognizer_.onend =
30 this.delegate_.onSpeechRecognitionEnded.bind(this.delegate_);
31 this.recognizer_.onerror =
32 this.delegate_.onSpeechRecognitionError.bind(this.delegate_);
33 }
34 }
35
36 /**
37 * Called when new speech recognition results arrive.
38 *
39 * @param {Event} speechEvent The event to contain the recognition results.
40 * @private
41 */
42 SpeechRecognitionManager.prototype.onRecognizerResult_ = function(
43 speechEvent) {
44 // Do not collect interim result for now.
45 var result = '';
46 var isFinal = false;
47 for (var i = 0; i < speechEvent.results.length; i++) {
48 if (speechEvent.results[i].isFinal)
49 isFinal = true;
50 result += speechEvent.results[i][0].transcript;
51 }
52 if (this.delegate_)
53 this.delegate_.onSpeechRecognized(result, isFinal);
54 };
55
56 /**
57 * Starts the speech recognition through webkitSpeechRecognition.
58 */
59 SpeechRecognitionManager.prototype.start = function() {
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
« 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