RecognizerListener interface

ru.yandex.speechkit

public  interface  RecognizerListener 

The interface defines callback methods that are called by the recognizer.

These callbacks are called during speech recognition for notification of events, such as when recording has started, a new portion of audio data has been recorded, the recognition process has finished (successfully or with an error), and other events.

Methods

voidonError(Recognizer recognizer, Error error)

Called when the recognition process completes with an error, or if the recognition request was canceled.

voidonPartialResults(Recognizer recognizer, Recognition results, boolean endOfUtterance)

Called when the received result is not final.

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).

voidonSpeechEnds(Recognizer recognizer)

Called when the user finished speaking.

Method descriptions

onError

public void onError (Recognizer recognizer, Error error)

Called when the recognition process completes with an error, or if the recognition request was canceled.

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.

onPartialResults

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

Called when the received result is not final.

This method is called when an intermediate recognition result is received. The method can be called multiple times after recognition begins. The method is passed a part of the recognition result and the endOfUtterance flag, which is set to false. If the end of the utterance is detected, the method is passed the final recognition result. In this case, the endOfUtterance value is set to true.

Note.

Speech is divided into utterances based on the length of pauses between words (this algorithm may be changed in future versions).

Note.

Use this method for getting results if recognition is in dictation mode (continuousMode is set to true).

Parameters:
results

Partial recognition result.

endOfUtterance

The parameter value is set to true if the end of the 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).

onRecognitionDone

public void onRecognitionDone (Recognizer recognizer, Recognition results)

Called when the recognition process completes successfully.

This is the mechanism that Recognizer uses for providing recognition results. The method is called only if speech was recognized successfully. Otherwise, onError() is called.

Note.

Speech recognition stops after this function is called. To restart it, a new Recognizer object must be created.

Note.

If recognition is in dictation mode (continuousMode is set to true), use the onPartialResults method for getting results.

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. The detector is disabled by default. Use the Recognizer.setVADEnabled method for enabling and disabling the VAD. The Recognizer.getVADEnabled method returns the state of the VAD.

onSpeechEnds

public void onSpeechEnds (Recognizer recognizer)

Called when the user finished speaking.

Note.

This method is only called if the Voice Activity Detector (VAD) is enabled. The detector is disabled by default. Use the Recognizer.setVADEnabled method for enabling and disabling the VAD. The Recognizer.getVADEnabled method returns the state of the VAD.