Recognizer class

ru.yandex.speechkit

public class Recognizer 

Interface to a single-use recognizer

The recognizer manages the entire recognition process, including recording audio, detecting voice activity, communicating with the server, and so on.

Recognizer uses the RecognizerListener interface for notification of significant events in the recognition process.

The Recognizer object is intended for single sessions of speech recognition and cannot be reused. Each subsequent recognition requires instantiating a new Recognizer object.

Note.

SpeechKit must be initialized using SpeechKit.configure() before creating the first instance of Recognizer.

Note.

The Recognizer object can be created before performing initialization (Initializer). In this case, it launches the initialization process itself before the actual start of recognition.

Note.

Recognizer initializes and uses shared resources, so two instances of this class may not exist simultaneously. A new instance can be created only after the current one has finished working and called either RecognizerListener.onRecognitionDone() or RecognizerListener.onError().

Methods

voidcancel()

Cancels the recognition request.

Recognizercreate(String language, String model, RecognizerListener listener)

Creates a single-use recognizer.

voidfinalize()
voidfinishRecording()

Force finish audio recording and send the request out.

StringgetLanguage()

Returns the language specified when creating the instance of the class.

StringgetModel()

Returns the model specified when creating the instance of the class.

booleangetVADEnabled()

Returns the state of the Voice Activity Detector (VAD).

booleanisRecognitionAvailable()

Checks whether the recognition is currently available.

voidsetVADEnabled(boolean on)

Allows to enable or disable the Voice Activity Detector (VAD).

voidstart()

Starts the recognition process.

Method descriptions

cancel

public void cancel ()

Cancels the recognition request.

This method cancels the recognition request at any stage of the operation. Audio stops being recorded, and the network connection is ended if necessary.
Note.

This method cancels the request asynchronously. This means that recognition does not end immediately after calling the method, and listener callbacks still might be called.

Note.

The method does not unlock the Recognizer object. The object will be destroyed automatically after calling either RecognizerListener.onRecognitionDone() or RecognizerListener.onError().

create

public static Recognizer create (String language, String model, RecognizerListener listener)

Creates a single-use recognizer.

To start the recognition operation, call the start() method.
Parameters:
language

The recognition language in BCP 47 format: http://en.wikipedia.org/wiki/IETF_language_tag. In BCP 47 format, the language is indicated using the language code in ISO 639 format, followed by a dash (-), followed by the country code in ISO 3166-1 format. For example, American English would be written as "en-US".

model

The language model to be used for speech recognition. Allows the server to better anticipate the type of phrases that the user will most likely utter and enable the appropriate dictionary, thereby improving the recognition accuracy.

listener

Listener for notification about the progress of speech recognition. It receives notifications when recording starts and finishes, speech starts, recognition results are received, and errors occur.

Returns:

An instance of the Recognizer class for performing recognition with the specified parameters.

finalize

protected void finalize ()

finishRecording

public void finishRecording ()

Force finish audio recording and send the request out.

In most cases, this method does not need to be called, since the Voice Activity Detector (VAD) automatically detects the end of speech. However, the method may be useful when the VAD is disabled or incorrectly detects the end of speech.

getLanguage

public String getLanguage ()

Returns the language specified when creating the instance of the class.

Returns:

The language specified when creating the instance

getModel

public String getModel ()

Returns the model specified when creating the instance of the class.

Returns:

The model specified when creating the instance

getVADEnabled

public boolean getVADEnabled ()

Returns the state of the Voice Activity Detector (VAD).

Returns:

true if VAD is enabled, false otherwise.

isRecognitionAvailable

public static boolean isRecognitionAvailable ()

Checks whether the recognition is currently available.

Note.

If initialization has not been completed, the function always returns true.

Returns:

true if the recognition is available, false otherwise.

setVADEnabled

public void setVADEnabled (boolean on)

Allows to enable or disable the Voice Activity Detector (VAD).

If the VAD is disabled, SpeechKit does not detect the end of speech automatically. In such cases, call the finishRecording() function to end recording and switch to recognition.

start

public void start ()

Starts the recognition process.

Note.

It takes the library some time to initialize the audio device, establish a connection with the server, and execute the initialization process. For this reason, recording never starts immediately after invoking the function. The RecognizerListener.onRecordingBegin() callback is invoked when recording starts.