From 4a750007d8258df14df7a24c06e1636d941f2301 Mon Sep 17 00:00:00 2001 From: "leandrogracia@chromium.org" Date: Fri, 18 Nov 2011 17:22:53 +0000 Subject: Adding static documentation to the speech input extension API. BUG=97388 TEST=none Review URL: http://codereview.chromium.org/8536022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110709 0039d316-1c4b-4281-b951-d872f2087c98 --- .../docs/static/experimental.speechInput.html | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 chrome/common/extensions/docs/static/experimental.speechInput.html (limited to 'chrome/common/extensions/docs/static/experimental.speechInput.html') diff --git a/chrome/common/extensions/docs/static/experimental.speechInput.html b/chrome/common/extensions/docs/static/experimental.speechInput.html new file mode 100644 index 0000000..b3c439c --- /dev/null +++ b/chrome/common/extensions/docs/static/experimental.speechInput.html @@ -0,0 +1,112 @@ +
Speech Input API
+ + +

+The chrome.experimental.speechInput module provides +one-shot speech recognition to Chrome extensions. +This module is still experimental. For information on how to use experimental +APIs, see the chrome.experimental.* APIs page. +

+ +

Manifest

+

You must declare the "experimental" permission in the extension manifest to use the speech input +API. +For example:

+
{
+  "name": "My extension",
+  ...
+  "permissions": [
+    "experimental"
+  ],
+  ...
+}
+ +

How to start speech recognition

+

To start recognizing speech an extension must call the start() +method. If provided, your callback will be called once recording has +successfully started. In case of error chrome.extension.lastError +will be set.

+ +

This API provides exclusive access to the default recording device to the +first extension requesting it. Consequently, any calls to start() +when the device is being used by another extension or web page will fail and set +chrome.extension.lastError. The message requestDenied +will be set if another extension in the same profile is making use of the API. +Otherwise noRecordingDeviceFound, recordingDeviceInUse +or unableToStart will be set depending on the situation.

+ +

To check whether recording is currently active, call the +isRecording() method. Please note that it only checks for audio +recording within Chrome.

+ + +

How to get speech recognition results

+

Listen to the onResult event to receive speech recognition +results.

+ +
+var callback = function(result) { ... };
+
+chrome.experimental.speechInput.onResult.addListener(callback);
+
+ +

The result object contains an array of +SpeechInputResultHypothesis +sorted by decreasing likelihood.

+ +

Recording automatically stops when results are received. It is safe to call +start() again from the results callback.

+ +

To handle errors during speech recognition listen for the +onError event.

+ +
+var callback = function(error) { ... };
+
+chrome.experimental.speechInput.onError.addListener(callback);
+
+ +

Recording will automatically stop in case of error. +It is safe to call start() again from the error callback.

+ + +

How to stop recording

+

To stop speech recognition call the stop() method. If provided, +the callback function will be called once recording has successfully stopped. +In case of error chrome.extension.lastError will be set. +

+ + +

Other features

+ + + +

Examples

+

The following example illustrates how to show a JavaScript alert with the +most likely recognition result.

+
+function checkStart() {
+  if (chrome.extension.lastError) {
+    alert("Couldn't start speech input: " + chrome.extension.lastError.message);
+  }
+}
+
+function recognitionFailed(error) {
+  alert("Speech input failed: " + error.code);
+}
+
+function recognitionSucceeded(result) {
+  alert("Recognized '" + result.hypotheses[0].utterance + "' with confidence " + result.hypotheses[0].confidence);
+}
+
+chrome.experimental.speechInput.onError.addListener(recognitionFailed);
+chrome.experimental.speechInput.onResult.addListener(recognitionSucceded);
+chrome.experimental.speechInput.start({ "language": "en" }, checkStart);
+
-- cgit v1.1