RecognizerActivity class

ru.yandex.speechkit.gui

java.lang.Object ⇽ android.content.Context ⇽ android.content.ContextWrapper ⇽ android.view.ContextThemeWrapper ⇽ android.app.Activity ⇽ RecognizerActivity

public  class  RecognizerActivity  extends android.app.Activity implements RecognizerListener

Implements the interfaces:
android.view.KeyEvent.Callback, android.view.Window.Callback, android.content.ComponentCallbacks, android.content.ComponentCallbacks2, android.view.LayoutInflater.Factory, android.view.LayoutInflater.Factory2, android.view.View.OnCreateContextMenuListener, RecognizerListener

Activity for simple speech recognition integration.

RecognizerActivity makes it easier to embed speech recognition in an app. The class returns the string uttered by the user and resolves any problems that occur along the way. RecognizerActivity manages the entire recognition process, including the user interface for speech recognition, management of the Recognizer and Initializer objects, and so on. RecognizerActivity is activated by passing speech recognition parameters (RecognizerActivity.EXTRA_LANGUAGE and RecognizerActivity.EXTRA_MODEL) via a firing Intent.

When recognition is complete, the resulting Intent returns RecognizerActivity.RESULT_OK or RecognizerActivity.RESULT_ERROR. The string with the result is contained in RecognizerActivity.EXTRA_RESULT, and an error message is contained in RecognizerActivity.EXTRA_ERROR.

Note.

You must use SpeechKit.configure() to initialize SpeechKit before instantiating the first recognizer.

Methods

voidonConfigurationChanged(android.content.res.Configuration newConfig)
voidonCreate(android.os.Bundle savedInstanceState)
voidonError(Recognizer recognizer, Error error)

Called when the recognition process failed with an error.

voidonPartialResults(Recognizer recognizer, Recognition results, boolean endOfUtterance)

Called when a partial result is received.

voidonPowerUpdated(Recognizer recognizer, float power)

Called for updating the power of the speech signal.

voidonRecognitionDone(Recognizer recognizer, Recognition results)

Called when the recognition process completes successfully.

voidonRecordingBegin(Recognizer recognizer)

Called when Recognizer has started recording audio.

voidonRecordingDone(Recognizer recognizer)

Called when Recognizer has finished recording audio.

voidonSoundDataRecorded(Recognizer recognizer, byte[] data)

Called when a chunk of audio data has been recorded.

voidonSpeechDetected(Recognizer recognizer)

Called when the user has started speaking (when speech was detected in the audio stream).

voidonStart()
voidonStop()

Fields

final StringEXTRA_ERROR

Name of the field (in the resulting Intent) that indicates an error.

final StringEXTRA_LANGUAGE

Name of the field (in the firing Intent) that indicates the language.

final StringEXTRA_MODEL

Name of the field (in the firing Intent) that indicates the model.

final StringEXTRA_RESULT

Name of the field (in the resulting Intent) for returning the result.

final intRESULT_ERROR

Indicates that the recognition process failed with an error.

final intRESULT_OK

Indicates that the recognition process completed successfully.

Method descriptions

onConfigurationChanged

public void onConfigurationChanged (android.content.res.Configuration newConfig)

onCreate

protected void onCreate (android.os.Bundle savedInstanceState)

onError

public void onError (Recognizer recognizer, Error error)

Called when the recognition process failed with an error.

Errors can occur for a number of reasons: an error opening the audio device, an error communicating with the server, an invalid parameter value passed during initialization (for example, the language code or authentication data), the user canceling the request, and so on.
Parameters:
error

Error during speech recognition.

Note.

This method is called only if speech recognition failed with an error.

onPartialResults

public void onPartialResults (Recognizer recognizer, Recognition results, boolean endOfUtterance)

Called when a partial result is received.

This method is called when a partial recognition result is received. It can be called any number of times after recognition has started and before it finishes. In addition to the result itself, this method is passed a flag that is set to true when the end of the "utterance" is detected. Speech is divided into utterances based on the length of pauses between words (this algorithm may be changed in future versions).
Parameters:
results

Partial recognition result.

endOfUtterance

Set to true if the end of an utterance was detected.

onPowerUpdated

public void onPowerUpdated (Recognizer recognizer, float power)

Called for updating the power of the speech signal.

This method is called each time after recording a chunk of audio data, and is used for updating the speech power indicator in the user interface.
Parameters:
power

A fractional number between 0 and 1 indicating the power of the signal (0 means no signal, and 1 is the maximum signal).

Note.

The function is called even if the power has not changed.

onRecognitionDone

public void onRecognitionDone (Recognizer recognizer, Recognition results)

Called when the recognition process completes successfully.

This is the mechanism used by Recognizer to provide recognition results. The method is called only if speech was recognized successfully. Otherwise, onError() is called.
Parameters:
results

Recognition result.

onRecordingBegin

public void onRecordingBegin (Recognizer recognizer)

Called when Recognizer has started recording audio.

onRecordingDone

public void onRecordingDone (Recognizer recognizer)

Called when Recognizer has finished recording audio.

onSoundDataRecorded

public void onSoundDataRecorded (Recognizer recognizer, byte[] data)

Called when a chunk of audio data has been recorded.

Parameters:
data

Raw audio data recorded from the audio device.

Note.

The sample width and rate are unspecified and may change.

onSpeechDetected

public void onSpeechDetected (Recognizer recognizer)

Called when the user has started speaking (when speech was detected in the audio stream).

Note.

This method is only called if the Voice Activity Detector (VAD) is enabled.

onStart

protected void onStart ()

onStop

protected void onStop ()

Field descriptions

EXTRA_ERROR

public static final String EXTRA_ERROR ()

Name of the field (in the resulting Intent) that indicates an error.

EXTRA_LANGUAGE

public static final String EXTRA_LANGUAGE ()

Name of the field (in the firing Intent) that indicates the language.

EXTRA_MODEL

public static final String EXTRA_MODEL ()

Name of the field (in the firing Intent) that indicates the model.

EXTRA_RESULT

public static final String EXTRA_RESULT ()

Name of the field (in the resulting Intent) for returning the result.

RESULT_ERROR

public static final int RESULT_ERROR ()

Indicates that the recognition process failed with an error.

RESULT_OK

public static final int RESULT_OK ()

Indicates that the recognition process completed successfully.