OLD | NEW |
---|---|
(Empty) | |
1 <div id="pageData-name" class="pageData">Speech Input API</div> | |
2 | |
3 <!-- BEGIN AUTHORED CONTENT --> | |
4 <p id="classSummary"> | |
5 The <code>chrome.experimental.speechInput</code> module provides | |
6 one-shot speech recognition to Chrome extensions. | |
7 This module is still experimental. For information on how to use experimental | |
8 APIs, see the <a href="experimental.html">chrome.experimental.* APIs</a> page. | |
9 </p> | |
10 | |
11 <h2 id="manifest">Manifest</h2> | |
12 <p>You must declare the "experimental" permission in the <a | |
13 href="manifest.html">extension manifest</a> to use the speechInput | |
14 API. | |
15 For example:</p> | |
16 <pre>{ | |
17 "name": "My extension", | |
18 ... | |
19 <b>"permissions": [ | |
20 "experimental" | |
21 ]</b>, | |
22 ... | |
23 }</pre> | |
24 | |
25 <h2 id="howToStart">How to start speech recognition</h2> | |
26 <p>To start recognizing speech an extension must call the <code>start</code> | |
27 method. If provided, <code>callback</code> will be called once recording has | |
28 successfully started. In case of error <code>chrome.extension.lastError</code> | |
29 will be set.</p> | |
30 | |
31 <p>This API provides exclusive access to the default recording device to the | |
32 first extension requesting it. Consequently, any calls to <code>start</code> | |
33 when the device is being used by another extension or web page will fail and set | |
34 <code>chrome.extension.lastError</code>. The message <code>requestDenied</code> | |
35 will be set if another extension in the same profile is making use of the API, | |
36 otherwise <code>noRecordingDeviceFound</code>, <code>recordingDeviceInUse</code> | |
37 or <code>unableToStart</code> will be set depending on the situation.</p> | |
38 | |
39 <p>To check if recording is currently active call the <code>isRecording</code> | |
40 method. Please note that it only checks for audio recording within Chrome.</p> | |
41 | |
42 | |
43 <h2 id="howToGetResults">How to get speech recognition results</h2> | |
44 <p>Listen to the <code>onResult</code> event to receive speech recognition | |
45 results.</p> | |
46 | |
47 <pre> | |
48 var callback = function(result) { ... }; | |
49 | |
50 chrome.experimental.speechInput.onResult.addListener(callback); | |
51 </pre> | |
52 | |
53 <p>The <code>result</code> object contains an array of recognition hypotheses | |
54 sorted by decreasing likelihood. Each of these hypotheses is composed of a | |
Satish
2011/11/14 11:33:37
It would be clearer if these two properties were l
Leandro GraciĆ” Gil
2011/11/14 12:04:54
I've added a link to the autogenerated documentati
| |
55 string with the recognized utterance and a confidence value ranged from 0 | |
56 (lowest) to 1 (highest).</p> | |
57 | |
58 <p>Recording automatically stops when results are received. It is safe to call | |
59 <code>start</code> again from the results callback.</p> | |
60 | |
61 <p>To handle errors during speech recognition listen for the | |
62 <code>onError</code> event.</p> | |
63 | |
64 <pre> | |
65 var callback = function(error) { ... }; | |
66 | |
67 chrome.experimental.speechInput.onError.addListener(callback); | |
68 </pre> | |
69 | |
70 </p>Recording will automatically stop in case on error. | |
71 It is safe to call <code>start</code> again from the error callback.</p> | |
72 | |
73 | |
74 <h2 id="howToStop">How to stop recording</h2> | |
75 <p>To stop speech recognition call the <code>stop</code> method. If provided, | |
76 <code>callback</code> will be called once recording has successfully | |
77 stopped. In case of error <code>chrome.extension.lastError</code> will be set. | |
78 </p> | |
79 | |
80 | |
81 <h2 id="otherFeatures">Other features</h2> | |
82 <ul><li> | |
83 <code>onSoundStart</code> - Event generated when start of sound is detected | |
84 (from previously being silent). | |
85 </li><li> | |
86 <code>onSoundEnd</code> - Event generated when end of sound is detected (a | |
87 continued period of silence). | |
88 </li></ul> | |
89 | |
90 | |
91 <h2 id="examples">Examples</h2> | |
92 <p>The following example illustrates how to show a javascript alert with the | |
93 most likely recognition result.</p> | |
94 <pre> | |
95 function checkStart() { | |
96 if (chrome.extension.lastError) { | |
97 alert("Couldn't start speech input: " + chrome.extension.lastError.message); | |
98 } | |
99 } | |
100 | |
101 function recognitionFailed(error) { | |
102 alert("Speech input failed: " + error.code); | |
103 } | |
104 | |
105 function recognitionSucceeded(result) { | |
106 alert("Recognized '" + result.hypotheses[0].utterance + "' with confidence " + result.hypotheses[0].confidence); | |
107 } | |
108 | |
109 chrome.experimental.speechInput.onError.addListener(recognitionFailed); | |
110 chrome.experimental.speechInput.onResult.addListener(recognitionSucceded); | |
111 chrome.experimental.speechInput.start({ "language": "en" }, checkStart); | |
112 </pre> | |
OLD | NEW |