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