Recognizer class

ru.yandex.speechkit

public  class  Recognizer 

Class for single sessions of speech recognition.

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.

Before creating the first Recognizer instance, you must configure the library using SpeechKit.configure().

Note.

The Recognizer object can be created before performing initialization. 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().

Nested classes

Methods

voidcancel()

Cancels the recognition request.

Recognizercreate(String language, String model, RecognizerListener listener)

Creates a single-use object for requests to the speech recognition system.

Recognizercreate(String language, String model, RecognizerListener listener, boolean continuousMode)

Creates a single-use object for requests to the speech recognition system.

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.

voidmute()

Turns off recording.

voidsetVADEnabled(boolean on)

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

voidstart()

Starts the recognition process.

voidunmute()

Turns on recording that was paused.

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 object for requests to the speech recognition system.

Parameters:
language

The language in BCP 47 format. 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, an English speaker from the US is specified as "en-US", and a Russian speaker from Russia as "ru-RU". Possible values are listed in the Recognizer.Language class.

model

The language model to be used for speech recognition. This allows the server to better anticipate the type of phrases the user is likely to say and select an appropriate vocabulary. This improves the accuracy of speech recognition. The available models are listed in the Recognizer.Model class.

listener

Object that will receive notifications about the progress of recognition. It receives notifications when recording starts and finishes, speech starts, recognition results are received, and errors occur.

Returns:

Instance of the Recognizer class for recognition with the specified parameters.

create

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

Creates a single-use object for requests to the speech recognition system.

Use this method to explicitly set the Recognizer mode: in short query recognition mode, or dictation mode. Dictation mode supports long sessions.

Parameters:
language

The language in BCP 47 format. 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, an English speaker from the US is specified as "en-US", and a Russian speaker from Russia as "ru-RU". Possible values are listed in the Recognizer.Language class.

model

The language model to be used for speech recognition. This allows the server to better anticipate the type of phrases the user is likely to say and select an appropriate vocabulary. This improves the accuracy of speech recognition. The available models are listed in the Recognizer.Model class.

listener

Object that will receive notifications about the progress of recognition. It receives notifications when recording starts and finishes, speech starts, recognition results are received, and errors occur.

continuousMode

Recognition mode. There are two recognition modes: short query mode and dictation mode. In short query mode, sound recording stops after the first pause. In dictation mode, recognition continues until the user explicitly ends it. The value true corresponds to dictation mode, and false corresponds to short query mode.

Returns:

Instance of the Recognizer class for recognition with the specified parameters.

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 result is available, false if unavailable.

mute

public void mute ()

Turns off recording.

Temporarily pauses recording, without stopping the recognition session.

See also:

unmute()

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 this case, in order to stop recording and switch to recognition, call the finishRecording() method.VAD is enabled by default.

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.

unmute

public void unmute ()

Turns on recording that was paused.

Allows audio recording that was temporarily prohibited by calling mute().

See also:

mute()