From 4a750007d8258df14df7a24c06e1636d941f2301 Mon Sep 17 00:00:00 2001
From: "leandrogracia@chromium.org"
+The You must declare the "experimental" permission in the extension manifest to use the speech input
+API.
+For example: To start recognizing speech an extension must call the This API provides exclusive access to the default recording device to the
+first extension requesting it. Consequently, any calls to To check whether recording is currently active, call the
+ Listen to the The Recording automatically stops when results are received. It is safe to call
+ To handle errors during speech recognition listen for 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
+{
+ "name": "My extension",
+ ...
+ "permissions": [
+ "experimental"
+ ],
+ ...
+}
+
+How to start speech recognition
+start()
+method. If provided, your callback will be called once recording has
+successfully started. In case of error chrome.extension.lastError
+will be set.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.isRecording()
method. Please note that it only checks for audio
+recording within Chrome.How to get speech recognition results
+onResult
event to receive speech recognition
+results.
+var callback = function(result) { ... };
+
+chrome.experimental.speechInput.onResult.addListener(callback);
+
+
+result
object contains an array of
+SpeechInputResultHypothesis
+sorted by decreasing likelihood.start()
again from the results callback.onError
event.
+var callback = function(error) { ... };
+
+chrome.experimental.speechInput.onError.addListener(callback);
+
+
+
start()
again from the error callback.
+
+
+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.
+
onSoundStart
- Event generated when start of sound is detected
+(from previously being silent).
+onSoundEnd
- Event generated when end of sound is detected (a
+continued period of silence).
+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