public class

SpeechRecognizer

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

Class Overview

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 createSpeechRecognizer(Context). This class's methods must be invoked only from the main application thread. Please note that the application must have RECORD_AUDIO permission to use this class.

Summary

Constants
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 Used to retrieve an ArrayList from the Bundle passed to the onResults(Bundle) and onPartialResults(Bundle) methods.
Public Methods
void cancel()
Cancels the speech recognition.
static SpeechRecognizer createSpeechRecognizer(Context context, ComponentName serviceComponent)
Factory method to create a new SpeechRecognizer.
static SpeechRecognizer createSpeechRecognizer(Context context)
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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int ERROR_AUDIO

Since: API Level 8

Audio recording error.

Constant Value: 3 (0x00000003)

public static final int ERROR_CLIENT

Since: API Level 8

Other client side errors.

Constant Value: 5 (0x00000005)

public static final int ERROR_INSUFFICIENT_PERMISSIONS

Since: API Level 8

Insufficient permissions

Constant Value: 9 (0x00000009)

public static final int ERROR_NETWORK

Since: API Level 8

Other network related errors.

Constant Value: 2 (0x00000002)

public static final int ERROR_NETWORK_TIMEOUT

Since: API Level 8

Network operation timed out.

Constant Value: 1 (0x00000001)

public static final int ERROR_NO_MATCH

Since: API Level 8

No recognition result matched.

Constant Value: 7 (0x00000007)

public static final int ERROR_RECOGNIZER_BUSY

Since: API Level 8

RecognitionService busy.

Constant Value: 8 (0x00000008)

public static final int ERROR_SERVER

Since: API Level 8

Server sends error status.

Constant Value: 4 (0x00000004)

public static final int ERROR_SPEECH_TIMEOUT

Since: API Level 8

No speech input

Constant Value: 6 (0x00000006)

public static final String RESULTS_RECOGNITION

Since: API Level 8

Used to retrieve an ArrayList from the Bundle passed to the onResults(Bundle) and 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

public void cancel ()

Since: API Level 8

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

public static SpeechRecognizer createSpeechRecognizer (Context context, ComponentName serviceComponent)

Since: API Level 8

Factory method to create a new SpeechRecognizer. Please note that setRecognitionListener(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(Context) instead to use the system default recognition service.

Parameters
context in which to create SpeechRecognizer
serviceComponent the ComponentName of a specific service to direct this SpeechRecognizer to
Returns
  • a new SpeechRecognizer

public static SpeechRecognizer createSpeechRecognizer (Context context)

Since: API Level 8

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

Parameters
context in which to create SpeechRecognizer
Returns
  • a new SpeechRecognizer

public void destroy ()

Since: API Level 8

Destroys the SpeechRecognizer object.

public static boolean isRecognitionAvailable (Context context)

Since: API Level 8

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

Parameters
context with which SpeechRecognizer will be created
Returns
  • true if recognition is available, false otherwise

public void setRecognitionListener (RecognitionListener listener)

Since: API Level 8

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 listener that will receive all the callbacks from the created SpeechRecognizer, this must not be null.

public void startListening (Intent recognizerIntent)

Since: API Level 8

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

Parameters
recognizerIntent 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.

public void stopListening ()

Since: API Level 8

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(RecognitionListener) should be called beforehand, otherwise no notifications will be received.