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 is designed for simplifying integration of speech recognition functionality into an app. The class returns the string uttered by the user and resolves any issues that occur along the way.

RecognizerActivity manages the entire recognition process including the user interface for speech recognition, managing the underlying 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 finished, the resulting Intent is sent to the calling one with one of the results RecognizerActivity.RESULT_OK or RecognizerActivity.RESULT_ERROR. Depending on the result, either RecognizerActivity.EXTRA_RESULT contains a string with the result, or RecognizerActivity.EXTRA_ERROR contains information about the 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 (Error).

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 the recognizer began recording sound.

voidonRecordingDone(Recognizer recognizer)

Called when the recognizer finished recording sound.

voidonSoundDataRecorded(Recognizer recognizer, byte[] data)

Called when a chunk of audio data has been recorded.

voidonSpeechDetected(Recognizer recognizer)

Called when the user started speaking.

voidonStart()
voidonStop()

Fields

final StringEXTRA_ERROR

Name of the field in the resulting Intent for specifying an error.

final StringEXTRA_LANGUAGE

Name of the field in the calling Intent for specifying the language.

final StringEXTRA_MODEL

Name of the field in the calling Intent for specifying 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 (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), cancellation of the request by the user, and so on. The reason for the error is passed by the function parameter. The method is called only if recognition failed with an error. Otherwise, onRecognitionDone() is called.
Parameters:
error

Error during speech recognition.

onPowerUpdated

public void onPowerUpdated (Recognizer recognizer, float power)

Called for updating the power of the speech signal.

The function is called on every new chunk of audio data and should be used to update the voice 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 the recognizer to provide recognition results. The method is called only if speech was recognized successfully. Otherwise, onError() is called.
Parameters:
results

the result of recognition.

onRecordingBegin

public void onRecordingBegin (Recognizer recognizer)

Called when the recognizer began recording sound.

onRecordingDone

public void onRecordingDone (Recognizer recognizer)

Called when the recognizer finished recording sound.

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 started speaking.

Note.

This method is only called when the voice activity detector (VAD) is enabled at the moment when speech was detected.

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 for specifying an error.

EXTRA_LANGUAGE

public static final String EXTRA_LANGUAGE ()

Name of the field in the calling Intent for specifying the language.

EXTRA_MODEL

public static final String EXTRA_MODEL ()

Name of the field in the calling Intent for specifying 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.