# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Constants | Methods | Inherited Methods

# SpeechRecognizer

`public class SpeechRecognizer`
`extends Object` ``

java.lang.Object
↳ | android.speech.SpeechRecognizer

This class provides access to the speech recognition service. This service allows access to the speech recognizer. Do not instantiate this class directly, instead, call `SpeechRecognizer#createSpeechRecognizer(Context)`. This class's methods must be invoked only from the main application thread.

The implementation of this API is likely to stream audio to remote servers to perform speech recognition. As such this API is not intended to be used for continuous recognition, which would consume a significant amount of battery and bandwidth.

Please note that the application must have `Manifest.permission.RECORD_AUDIO` permission to use this class.

## Summary

### Constants
`String` | `CONFIDENCE_SCORES` Key used to retrieve a float array from the `Bundle` passed to the `RecognitionListener#onResults(Bundle)` and `RecognitionListener#onPartialResults(Bundle)` methods.
`int` | `ERROR_AUDIO` Audio recording error.
`int` | `ERROR_CLIENT` Other client side errors.
`int` | `ERROR_INSUFFICIENT_PERMISSIONS` Insufficient permissions
`int` | `ERROR_NETWORK` Other network related errors.
`int` | `ERROR_NETWORK_TIMEOUT` Network operation timed out.
`int` | `ERROR_NO_MATCH` No recognition result matched.
`int` | `ERROR_RECOGNIZER_BUSY` RecognitionService busy.
`int` | `ERROR_SERVER` Server sends error status.
`int` | `ERROR_SPEECH_TIMEOUT` No speech input
`String` | `RESULTS_RECOGNITION` Key used to retrieve an `ArrayList<String>` from the `Bundle` passed to the `RecognitionListener#onResults(Bundle)` and `RecognitionListener#onPartialResults(Bundle)` methods.

### Public methods
`void` | `cancel()` Cancels the speech recognition.
`static SpeechRecognizer` | `createSpeechRecognizer(Context context)` Factory method to create a new `SpeechRecognizer`.
`static SpeechRecognizer` | `createSpeechRecognizer(Context context, ComponentName serviceComponent)` Factory method to create a new `SpeechRecognizer`.
`void` | `destroy()` Destroys the `SpeechRecognizer` object.
`static boolean` | `isRecognitionAvailable(Context context)` Checks whether a speech recognition service is available on the system.
`void` | `setRecognitionListener(RecognitionListener listener)` Sets the listener that will receive all the callbacks.
`void` | `startListening(Intent recognizerIntent)` Starts listening for speech.
`void` | `stopListening()` Stops listening for speech.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Constants

### CONFIDENCE_SCORES

    public static final String CONFIDENCE_SCORES

Key used to retrieve a float array from the `Bundle` passed to the `RecognitionListener#onResults(Bundle)` and `RecognitionListener#onPartialResults(Bundle)` methods. The array should be the same size as the ArrayList provided in `RESULTS_RECOGNITION`, and should contain values ranging from 0.0 to 1.0, or -1 to represent an unavailable confidence score.

Confidence values close to 1.0 indicate high confidence (the speech recognizer is confident that the recognition result is correct), while values close to 0.0 indicate low confidence.

This value is optional and might not be provided.

Constant Value: "confidence_scores"

### ERROR_AUDIO

    public static final int ERROR_AUDIO

Audio recording error.

Constant Value: 3 (0x00000003)

### ERROR_CLIENT

    public static final int ERROR_CLIENT

Other client side errors.

Constant Value: 5 (0x00000005)

### ERROR_INSUFFICIENT_PERMISSIONS

    public static final int ERROR_INSUFFICIENT_PERMISSIONS

Insufficient permissions

Constant Value: 9 (0x00000009)

### ERROR_NETWORK

    public static final int ERROR_NETWORK

Other network related errors.

Constant Value: 2 (0x00000002)

### ERROR_NETWORK_TIMEOUT

    public static final int ERROR_NETWORK_TIMEOUT

Network operation timed out.

Constant Value: 1 (0x00000001)

### ERROR_NO_MATCH

    public static final int ERROR_NO_MATCH

No recognition result matched.

Constant Value: 7 (0x00000007)

### ERROR_RECOGNIZER_BUSY

    public static final int ERROR_RECOGNIZER_BUSY

RecognitionService busy.

Constant Value: 8 (0x00000008)

### ERROR_SERVER

    public static final int ERROR_SERVER

Server sends error status.

Constant Value: 4 (0x00000004)

### ERROR_SPEECH_TIMEOUT

    public static final int ERROR_SPEECH_TIMEOUT

No speech input

Constant Value: 6 (0x00000006)

### RESULTS_RECOGNITION

    public static final String RESULTS_RECOGNITION

Key used to retrieve an `ArrayList<String>` from the `Bundle` passed to the `RecognitionListener#onResults(Bundle)` and `RecognitionListener#onPartialResults(Bundle)` methods. These strings are the possible recognition results, where the first element is the most likely candidate.

Constant Value: "results_recognition"

## Public methods

### cancel

    public void cancel ()

Cancels the speech recognition. Please note that `setRecognitionListener(android.speech.RecognitionListener)` should be called beforehand, otherwise no notifications will be received.

### createSpeechRecognizer

    public static SpeechRecognizer createSpeechRecognizer (Context context)

Factory method to create a new `SpeechRecognizer`. Please note that `setRecognitionListener(android.speech.RecognitionListener)` should be called before dispatching any command to the created `SpeechRecognizer`, otherwise no notifications will be received.

Parameters
`context` | `Context`: in which to create `SpeechRecognizer`

Returns
`SpeechRecognizer` | a new `SpeechRecognizer`

### createSpeechRecognizer

    public static SpeechRecognizer createSpeechRecognizer (Context context,
                    ComponentName serviceComponent)

Factory method to create a new `SpeechRecognizer`. Please note that `setRecognitionListener(android.speech.RecognitionListener)` should be called before dispatching any command to the created `SpeechRecognizer`, otherwise no notifications will be received. Use this version of the method to specify a specific service to direct this `SpeechRecognizer` to. Normally you would not use this; use `createSpeechRecognizer(android.content.Context)` instead to use the system default recognition service.

Parameters
`context` | `Context`: in which to create `SpeechRecognizer`
`serviceComponent` | `ComponentName`: the `ComponentName` of a specific service to direct this `SpeechRecognizer` to

Returns
`SpeechRecognizer` | a new `SpeechRecognizer`

### destroy

    public void destroy ()

Destroys the `SpeechRecognizer` object.

### isRecognitionAvailable

    public static boolean isRecognitionAvailable (Context context)

Checks whether a speech recognition service is available on the system. If this method returns `false`, `SpeechRecognizer#createSpeechRecognizer(Context)` will fail.

Parameters
`context` | `Context`: with which `SpeechRecognizer` will be created

Returns
`boolean` | `true` if recognition is available, `false` otherwise

### setRecognitionListener

    public void setRecognitionListener (RecognitionListener listener)

Sets the listener that will receive all the callbacks. The previous unfinished commands will be executed with the old listener, while any following command will be executed with the new listener.

Parameters
`listener` | `RecognitionListener`: listener that will receive all the callbacks from the created `SpeechRecognizer`, this must not be null.

### startListening

    public void startListening (Intent recognizerIntent)

Starts listening for speech. Please note that `setRecognitionListener(android.speech.RecognitionListener)` should be called beforehand, otherwise no notifications will be received.

Parameters
`recognizerIntent` | `Intent`: contains parameters for the recognition to be performed. The intent may also contain optional extras, see `RecognizerIntent`. If these values are not set explicitly, default values will be used by the recognizer.

### stopListening

    public void stopListening ()

Stops listening for speech. Speech captured so far will be recognized as if the user had stopped speaking at this point. Note that in the default case, this does not need to be called, as the speech endpointer will automatically stop the recognizer listening when it determines speech has completed. However, you can manipulate endpointer parameters directly using the intent extras defined in `RecognizerIntent`, in which case you may sometimes want to manually call this method to stop listening sooner. Please note that `setRecognitionListener(android.speech.RecognitionListener)` should be called beforehand, otherwise no notifications will be received.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*