You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files.
paramName
( optional enumerated Type array of paramType )
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Parameters
  1. Properties
    1. propertyName
  2. Methods
    1. methodName
  3. Events
    1. eventName
  4. Types
    1. id

Google Chrome Extensions (Labs)

Speech Input API

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

  • 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).

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);

API reference: chrome.experimental.speechInput

Methods

isRecording

void chrome.experimental.speechInput.isRecording(, function callback)

Determine if audio recording is currently in process in Chrome, not limited to this API.

Parameters

callback
( optional Type array of function )
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

Callback function

The callback parameter should specify a function that looks like this:

If you specify the callback parameter, it should specify a function that looks like this:

function(boolean result) {...};
result
( Type array of boolean )
Flag set to true if recording is in process in Chrome, false otherwise.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

start

void chrome.experimental.speechInput.start(, SpeechInputStartOptions options, function callback)

Request to start recording as a new speech recognition session.

Parameters

options
( optional SpeechInputStartOptions array of paramType )
Options used for this speech recognition session.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
callback
( optional Type array of function )
Called when the speech recognition session has successfully started recording.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

Callback function

The callback parameter should specify a function that looks like this:

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

stop

void chrome.experimental.speechInput.stop(, function callback)

Request to stop an ongoing speech recognition session.

Parameters

callback
( optional Type array of function )
Called when the audio recording has stopped and any pending recognition results have been completed.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

Callback function

The callback parameter should specify a function that looks like this:

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Events

onError

chrome.experimental.speechInput.onError.addListener(function(SpeechInputError error) {...});

Called in case of an error in speech recognition.

Listener parameters

error
( SpeechInputError array of paramType )
Error being reported.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Extra parameters to addListener

Listener returns

onResult

chrome.experimental.speechInput.onResult.addListener(function(SpeechInputResultEvent event) {...});

Called when speech recognition results are available.

Listener parameters

event
( SpeechInputResultEvent array of paramType )
Object containing the speech recognition results.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Extra parameters to addListener

Listener returns

onSoundEnd

chrome.experimental.speechInput.onSoundEnd.addListener(function() {...});

Called when the system detects enough silence to consider the ongoing speech has ended.

Listener parameters

Extra parameters to addListener

Listener returns

onSoundStart

chrome.experimental.speechInput.onSoundStart.addListener(function() {...});

Called when the system starts detecting sound in the input data.

Listener parameters

Extra parameters to addListener

Listener returns

Types

SpeechInputStartOptions

paramName
( Type array of object )
Object describing the options used for speech recognition.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
language
( optional Type array of string )
BCP-47 language code of the language to recognize. When set to 'auto' or not defined defaults to user's most preferred content language. Will use 'en-US' if not supported or invalid.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
grammar
( optional Type array of string )
Name of the grammar to use. Defaults to 'builtin:dictation'.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
filterProfanities
( optional Type array of boolean )
Enable or disable profanity filtering. Will use the default Chrome filtering settings if not set.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

SpeechInputError

paramName
( Type array of object )
Object describing a speech input error.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
code
( enumerated Type array of string ["noSpeechHeard", "noResults", "captureError", "networkError"] )
Code identifying the error case.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

SpeechInputResultHypothesis

paramName
( Type array of object )
Object describing a speech recognition hypothesis.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
utterance
( Type array of string )
Text of this hypothesis.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
confidence
( Type array of number )
Confidence of the hypothesis. Rated from 0 (lowest) to 1 (highest).
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

SpeechInputResultEvent

paramName
( Type array of object )
Object containing the recognition results.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
hypotheses
( optional Type array of SpeechInputResultHypothesis array of paramType paramType )
Array of zero or more objects describing the stable candidate hypotheses sorted by decreasing likelihood.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.