Added in API level 8

RecognitionListener

public interface RecognitionListener

android.speech.RecognitionListener


Used for receiving notifications from the SpeechRecognizer when the recognition related events occur. All the callbacks are executed on the Application main thread.

Summary

Public methods

abstract void onBeginningOfSpeech()

The user has started to speak.

abstract void onBufferReceived(byte[] buffer)

More sound has been received.

default void onEndOfSegmentedSession()

Called at the end of a segmented recognition request.

abstract void onEndOfSpeech()

Called after the user stops speaking.

abstract void onError(int error)

A network or recognition error occurred.

abstract void onEvent(int eventType, Bundle params)

Reserved for adding future events.

default void onLanguageDetection(Bundle results)

Called when the language detection (and switching) results are available.

abstract void onPartialResults(Bundle partialResults)

Called when partial recognition results are available.

abstract void onReadyForSpeech(Bundle params)

Called when the endpointer is ready for the user to start speaking.

abstract void onResults(Bundle results)

Called when recognition results are ready.

abstract void onRmsChanged(float rmsdB)

The sound level in the audio stream has changed.

default void onSegmentResults(Bundle segmentResults)

Called for each ready segment of a recognition request.

Public methods

onBeginningOfSpeech

Added in API level 8
public abstract void onBeginningOfSpeech ()

The user has started to speak.

onBufferReceived

Added in API level 8
public abstract void onBufferReceived (byte[] buffer)

More sound has been received. The purpose of this function is to allow giving feedback to the user regarding the captured audio. There is no guarantee that this method will be called.

Parameters
buffer byte: a buffer containing a sequence of big-endian 16-bit integers representing a single channel audio stream. The sample rate is implementation dependent.

onEndOfSegmentedSession

Added in API level 33
public void onEndOfSegmentedSession ()

Called at the end of a segmented recognition request. To request segmented speech results use RecognizerIntent#EXTRA_SEGMENTED_SESSION.

onEndOfSpeech

Added in API level 8
public abstract void onEndOfSpeech ()

Called after the user stops speaking.

onError

Added in API level 8
public abstract void onError (int error)

A network or recognition error occurred.

Parameters
error int: code is defined in SpeechRecognizer. Implementations need to handle any integer error constant to be passed here beyond constants prefixed with ERROR_. Value is SpeechRecognizer.ERROR_NETWORK_TIMEOUT, SpeechRecognizer.ERROR_NETWORK, SpeechRecognizer.ERROR_AUDIO, SpeechRecognizer.ERROR_SERVER, SpeechRecognizer.ERROR_CLIENT, SpeechRecognizer.ERROR_SPEECH_TIMEOUT, SpeechRecognizer.ERROR_NO_MATCH, SpeechRecognizer.ERROR_RECOGNIZER_BUSY, SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS, SpeechRecognizer.ERROR_TOO_MANY_REQUESTS, SpeechRecognizer.ERROR_SERVER_DISCONNECTED, SpeechRecognizer.ERROR_LANGUAGE_NOT_SUPPORTED, SpeechRecognizer.ERROR_LANGUAGE_UNAVAILABLE, SpeechRecognizer.ERROR_CANNOT_CHECK_SUPPORT, or SpeechRecognizer.ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS

onEvent

Added in API level 8
public abstract void onEvent (int eventType, 
                Bundle params)

Reserved for adding future events.

Parameters
eventType int: the type of the occurred event

params Bundle: a Bundle containing the passed parameters

onLanguageDetection

Added in API level 34
public void onLanguageDetection (Bundle results)

Called when the language detection (and switching) results are available. This callback can be invoked on any number of occasions at any time between onBeginningOfSpeech() and onEndOfSpeech(), depending on the speech recognition service implementation.

To request language detection, use RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION.

To request automatic language switching, use RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH.

Parameters
results Bundle: the returned language detection (and switching) results.

To retrieve the most confidently detected language IETF tag (as defined by BCP 47, e.g., "en-US", "de-DE"), use Bundle#getString(String) with SpeechRecognizer#DETECTED_LANGUAGE as the parameter.

To retrieve the language detection confidence level represented by a value prefixed by LANGUAGE_DETECTION_CONFIDENCE_LEVEL_ and defined in SpeechRecognizer, use Bundle#getInt(String) with SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL as the parameter.

To retrieve the alternative locales for the same language retrieved by the key SpeechRecognizer#DETECTED_LANGUAGE, use Bundle#getStringArrayList(String) with SpeechRecognizer#TOP_LOCALE_ALTERNATIVES as the parameter.

To retrieve the language switching results represented by a value prefixed by LANGUAGE_SWITCH_RESULT_ and defined in SpeechRecognizer, use Bundle#getInt(String) with SpeechRecognizer#LANGUAGE_SWITCH_RESULT as the parameter. This value cannot be null.

onPartialResults

Added in API level 8
public abstract void onPartialResults (Bundle partialResults)

Called when partial recognition results are available. The callback might be called at any time between onBeginningOfSpeech() and onResults(android.os.Bundle) when partial results are ready. This method may be called zero, one or multiple times for each call to SpeechRecognizer#startListening(Intent), depending on the speech recognition service implementation. To request partial results, use RecognizerIntent#EXTRA_PARTIAL_RESULTS

Parameters
partialResults Bundle: the returned results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter

onReadyForSpeech

Added in API level 8
public abstract void onReadyForSpeech (Bundle params)

Called when the endpointer is ready for the user to start speaking.

Parameters
params Bundle: parameters set by the recognition service. Reserved for future use.

onResults

Added in API level 8
public abstract void onResults (Bundle results)

Called when recognition results are ready.

Called with the results for the full speech since onReadyForSpeech(android.os.Bundle). To get recognition results in segments rather than for the full session see RecognizerIntent#EXTRA_SEGMENTED_SESSION.

Parameters
results Bundle: the recognition results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter. A float array of confidence values might also be given in SpeechRecognizer#CONFIDENCE_SCORES.

onRmsChanged

Added in API level 8
public abstract void onRmsChanged (float rmsdB)

The sound level in the audio stream has changed. There is no guarantee that this method will be called.

Parameters
rmsdB float: the new RMS dB value

onSegmentResults

Added in API level 33
public void onSegmentResults (Bundle segmentResults)

Called for each ready segment of a recognition request. To request segmented speech results use RecognizerIntent#EXTRA_SEGMENTED_SESSION. The callback might be called any number of times between onReadyForSpeech(android.os.Bundle) and onEndOfSegmentedSession().

Parameters
segmentResults Bundle: the returned results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter This value cannot be null.