Chromium Code Reviews| 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 | |
|
kathyw
2011/11/15 00:04:10
speechInput -> speech input
(since we're not list
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 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> | |
|
kathyw
2011/11/15 00:04:10
Add () after method names:
<code>start()</code>
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 27 method. If provided, <code>callback</code> will be called once recording has | |
|
kathyw
2011/11/15 00:04:10
<code>callback</code>
->
your callback
(or someth
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 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, | |
|
kathyw
2011/11/15 00:04:10
API, otherwise -> API. Otherwise
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 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> | |
|
kathyw
2011/11/15 00:04:10
Slight tweaks (if -> whether, add comma, add ()):
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 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 | |
| 54 <a href="#type-SpeechInputResultHypothesis">SpeechInputResultHypothesis</a> | |
| 55 sorted by decreasing likelihood.</p> | |
| 56 | |
| 57 <p>Recording automatically stops when results are received. It is safe to call | |
| 58 <code>start</code> again from the results callback.</p> | |
| 59 | |
| 60 <p>To handle errors during speech recognition listen for the | |
| 61 <code>onError</code> event.</p> | |
| 62 | |
| 63 <pre> | |
| 64 var callback = function(error) { ... }; | |
| 65 | |
| 66 chrome.experimental.speechInput.onError.addListener(callback); | |
| 67 </pre> | |
| 68 | |
| 69 </p>Recording will automatically stop in case on error. | |
|
kathyw
2011/11/15 00:04:10
on error -> of error
(or "of an error")
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 70 It is safe to call <code>start</code> again from the error callback.</p> | |
|
kathyw
2011/11/15 00:04:10
start -> start()
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 71 | |
| 72 | |
| 73 <h2 id="howToStop">How to stop recording</h2> | |
| 74 <p>To stop speech recognition call the <code>stop</code> method. If provided, | |
|
kathyw
2011/11/15 00:04:10
stop -> stop()
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 75 <code>callback</code> will be called once recording has successfully | |
|
kathyw
2011/11/15 00:04:10
<code>callback</code>
->
the callback function
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 76 stopped. In case of error <code>chrome.extension.lastError</code> will be set. | |
| 77 </p> | |
| 78 | |
| 79 | |
| 80 <h2 id="otherFeatures">Other features</h2> | |
| 81 <ul><li> | |
| 82 <code>onSoundStart</code> - Event generated when start of sound is detected | |
| 83 (from previously being silent). | |
| 84 </li><li> | |
| 85 <code>onSoundEnd</code> - Event generated when end of sound is detected (a | |
| 86 continued period of silence). | |
| 87 </li></ul> | |
| 88 | |
| 89 | |
| 90 <h2 id="examples">Examples</h2> | |
| 91 <p>The following example illustrates how to show a javascript alert with the | |
|
kathyw
2011/11/15 00:04:10
javascript -> JavaScript
Leandro Graciá Gil
2011/11/15 12:10:12
Done.
| |
| 92 most likely recognition result.</p> | |
| 93 <pre> | |
| 94 function checkStart() { | |
| 95 if (chrome.extension.lastError) { | |
| 96 alert("Couldn't start speech input: " + chrome.extension.lastError.message); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 function recognitionFailed(error) { | |
| 101 alert("Speech input failed: " + error.code); | |
| 102 } | |
| 103 | |
| 104 function recognitionSucceeded(result) { | |
| 105 alert("Recognized '" + result.hypotheses[0].utterance + "' with confidence " + result.hypotheses[0].confidence); | |
| 106 } | |
| 107 | |
| 108 chrome.experimental.speechInput.onError.addListener(recognitionFailed); | |
| 109 chrome.experimental.speechInput.onResult.addListener(recognitionSucceded); | |
| 110 chrome.experimental.speechInput.start({ "language": "en" }, checkStart); | |
| 111 </pre> | |
|
kathyw
2011/11/15 00:04:10
We should add examples under docs/examples/<someth
Leandro Graciá Gil
2011/11/15 12:10:12
The example I have is basically the same simple ca
| |
| OLD | NEW |