Class OnlineRecognizer.Builder

ru.yandex.speechkit

public  class  OnlineRecognizer.Builder 

Class for creating and configuring the OnlineRecognizer object.

Methods

Builder(@NonNull final Language language, @NonNull final OnlineModel onlineModel, @NonNull final RecognizerListener recognizerListener)

Creates an object of the OnlineRecognizer.Builder class with mandatory settings.

Builder(@NonNull final Language language, @NonNull final String grammar, @NonNull final RecognizerListener recognizerListener)

Creates an object of the OnlineRecognizer.Builder class with mandatory settings.

OnlineRecognizerbuild()

Creates an object of the OnlineRecognizer class.

BuildersetAudioSource(@NonNull final AudioSource audioSource)

Sets the audio source (AudioSource).

BuildersetDisableAntimat(final boolean disableAntimat)

Sets the flag of skipping obscene words.

BuildersetEnableManualPunctuation(final boolean value)

Sets the flag of replacing punctuation words with marks.

BuildersetEnableMusicRecognition(final boolean enableMusicRecognition)

Enables music recognition.

BuildersetEnablePunctuation(final boolean enablePunctuation)

Sets the punctuation flag.

BuildersetEncodingBitrate(final int encodingBitrate)

Sets the bitrate of the selected audio codec (bps).

BuildersetEncodingComplexity(final int encodingComplexity)

Sets the complexity of the compression algorithm.

BuildersetFinishAfterFirstUtterance(final boolean finishAfterFirstUtterance)

Sets the flag of ending recognition after receiving the endOfUtterance parameter value in the onPartialResults(Recognizer,Recognition, boolean) method.

BuildersetInactiveTimeout(final long inactiveTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the time to wait for speech, in seconds, after starting the OnlineRecognizer class object.

BuildersetNewEnergyWeight(float newEnergyWeight)

The weight of each new chunk of audio data when calculating the speech power.

BuildersetReachabilityTimeout(final long reachabilityTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the network connection timeout.

BuildersetRecordingTimeout(final long recordingTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the maximum length of a voice query record in seconds.

BuildersetRequestBiometry(final boolean value)

Sets the flag indicating a request for the user's estimated biometrics (for example, age, gender, or age group).

BuildersetSilenceBetweenUtterances(final long silenceBetweenUtterances, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the minimum silence time between utterances.

BuildersetSoundFormat(@NonNull final SoundFormat soundFormat)

Specifies the audio format.

BuildersetUniProxySession(final UniProxySession session)

Sets an object of the UniProxySession class that will be used for a network connection.

BuildersetUsePlatformRecognizer(final boolean value)

Enables the use of platform recognition (android.speech.SpeechRecognizer).

BuildersetVadEnabled(final boolean vadEnabled)

Sets the flag indicating whether the VAD is enabled.

BuildersetWaitForConnection(final boolean waitForConnection)

Sets the flag indicating that audio recording starts after a network connection is established.

BuildersetWaitForResultTimeout(final long value, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the server response timeout after sending the last fragment.

StringtoString()

Method Detail

Builder

public Builder (@NonNull final Language language, @NonNull final OnlineModel onlineModel, @NonNull final RecognizerListener recognizerListener)

Creates an object of the OnlineRecognizer.Builder class with mandatory settings.

Parameters:
language

Voice query language.

onlineModel

The model that is used for recognition.

recognizerListener

Interface for recognition event notification.

Builder

public Builder (@NonNull final Language language, @NonNull final String grammar, @NonNull final RecognizerListener recognizerListener)

Creates an object of the OnlineRecognizer.Builder class with mandatory settings.

Parameters:
language

Voice query language.

grammar

Grammar for the "on-the-fly" model. Don't use numbers, "upper case".

recognizerListener

Interface for recognition event notification.

build

public OnlineRecognizer build ()

Creates an object of the OnlineRecognizer class.

Returns:

An object of the OnlineRecognizer class.

setAudioSource

public Builder setAudioSource (@NonNull final AudioSource audioSource)

Sets the audio source (AudioSource).

Parameters:
audioSource

Source that passes an audio for recognition to an object of the OnlineRecognizer class. Default value: AutoStartStopAudioSource.

setDisableAntimat

public Builder setDisableAntimat (final boolean disableAntimat)

Sets the flag of skipping obscene words.

Parameters:
disableAntimat
Flag of skipping obscene words. Default value: false. Acceptable values:
  • true - the ASR server will not skip obscene words.

  • false - the ASR server will skip obscene words.

setEnableManualPunctuation

public Builder setEnableManualPunctuation (final boolean value)

Sets the flag of replacing punctuation words with marks.

For example, the utterance "Hello comma how are you question mark" can be recognized as "Hello, how are you?".
Parameters:
value
Flag of replacing punctuation words with marks. Default value: false. Acceptable values:
  • true - the ASR server will replace punctuation words with marks;

  • false - the ASR server will not replace punctuation words with marks.

setEnableMusicRecognition

public Builder setEnableMusicRecognition (final boolean enableMusicRecognition)

Enables music recognition.

We recommend setting the following parameters for correct music recognition: setFinishAfterFirstUtterance(boolean) - disable it, otherwise a request can be aborted after words are recognized; setInactiveTimeout (long, TimeUnit) - disable it, otherwise the VAD can stop audio recording.
Parameters:
enableMusicRecognition

Flag indicating that the ASR server will send music recognition results. Default value: false. If this parameter is set to true, the onMusicResults (Recognizer, Track) method is called during recognition. In this case, a request will return either the onRecognitionDone(Recognizer) or the onRecognizerError(Recognizer, Error) method notifying of the request execution status.

setEnablePunctuation

public Builder setEnablePunctuation (final boolean enablePunctuation)

Sets the punctuation flag.

Parameters:
enablePunctuation
Punctuation flag. Default value: true. Acceptable values:
  • true - the ASR server will place punctuation marks in the text;

  • false - the ASR server will not place punctuation marks in the text.

setEncodingBitrate

public Builder setEncodingBitrate (final int encodingBitrate)

Sets the bitrate of the selected audio codec (bps).

The bitrate determines the approximate number of bits one second of compressed audio will take. This parameter affects the quality of sound and, hence, the quality of recognition. The recommended range for OPUS is from 12000 to 64000 bps if the encodingComplexity parameter (the setEncodingComplexity(int) method) is set to 10.
Note.

When the PCM format is selected, this parameter is not used.

Parameters:
encodingBitrate

Bitrate of the selected audio codec (bps). The default value at which the optimal size/quality ratio is achieved is 24000.

setEncodingComplexity

public Builder setEncodingComplexity (final int encodingComplexity)

Sets the complexity of the compression algorithm.

The complexity of the algorithm affects the quality of audio and, hence, the quality of recognition. An increase in the complexity at the fixed bitrate allows achieving better audio quality, but also increases the processor load and encoding time. However, the dependency is nonlinear, and with a bitrate of 24000 bps a high recognition quality is achieved with any complexity value, while with a bitrate of 12000 bps a good quality can only be achieved if the complexity value is set to 10.
Note.

When the PCM format is selected, this parameter is not used.

Parameters:
encodingComplexity

Complexity of the compression algorithm. Default value: 0.

setFinishAfterFirstUtterance

public Builder setFinishAfterFirstUtterance (final boolean finishAfterFirstUtterance)

Sets the flag of ending recognition after receiving the endOfUtterance parameter value in the onPartialResults(Recognizer,Recognition, boolean) method.

Parameters:
finishAfterFirstUtterance
Flag of ending recognition. Default value: true. Acceptable values:

setInactiveTimeout

public Builder setInactiveTimeout (final long inactiveTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the time to wait for speech, in seconds, after starting the OnlineRecognizer class object.

If the OnlineRecognizer class object detects no speech during this timeout, it returns the ERROR_NO_SPEECH_DETECTED error in the onRecognizerError (Recognizer, Error) method.
Parameters:
inactiveTimeout

Time to wait for speech after starting the OnlineRecognizer class object. Default value: 5 seconds.

timeUnit

Specifies the inactiveTimeout units.

setNewEnergyWeight

public Builder setNewEnergyWeight (float newEnergyWeight)

The weight of each new chunk of audio data when calculating the speech power.

The speech power value can be obtained in the onPowerUpdated(Recognizer, float) method.
Parameters:
newEnergyWeight

The weight of each new chunk of audio data when calculating the speech power. Default value: 0,9.

setReachabilityTimeout

public Builder setReachabilityTimeout (final long reachabilityTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the network connection timeout.

Parameters:
reachabilityTimeout

Network connection timeout. Default value: 5 seconds.

timeUnit

Specifies the reachabilityTimeout units.

Returns:

An object of the Builder class.

setRecordingTimeout

public Builder setRecordingTimeout (final long recordingTimeout, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the maximum length of a voice query record in seconds.

Parameters:
recordingTimeout

Maximum length of a voice query record in seconds. Default value: 20 seconds.

timeUnit

Specifies the recordingTimeout units.

setRequestBiometry

public Builder setRequestBiometry (final boolean value)

Sets the flag indicating a request for the user's estimated biometrics (for example, age, gender, or age group).

Parameters:
value
Flag indicating a request for the user's estimated biometrics (for example, age, gender, or age group). Default value: false. Acceptable values:
  • true - request estimated biometrics;

  • false - do not request estimated biometrics.

setSilenceBetweenUtterances

public Builder setSilenceBetweenUtterances (final long silenceBetweenUtterances, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the minimum silence time between utterances.

If the silence between words exceeds the specified value, the recognition system will interpret it as the end of the utterance. When set to zero, the default server value is used.
Parameters:
silenceBetweenUtterances

Minimum silence time between utterances. Default value: 0 seconds.

timeUnit

Specifies the silenceBetweenUtterances units.

Returns:

An object of the Builder class.

setSoundFormat

public Builder setSoundFormat (@NonNull final SoundFormat soundFormat)

Specifies the audio format.

Parameters:
soundFormat

Audio format. Default value: OPUS.

setUniProxySession

public Builder setUniProxySession (final UniProxySession session)

Sets an object of the UniProxySession class that will be used for a network connection.

Parameters:
session

An object of the UniProxySession class that will be used for a network connection. Default value: null.

setUsePlatformRecognizer

public Builder setUsePlatformRecognizer (final boolean value)

Enables the use of platform recognition (android.speech.SpeechRecognizer).

Parameters:
value

Flag of using platform recognition (android.speech.SpeechRecognizer). Default value: false.

setVadEnabled

public Builder setVadEnabled (final boolean vadEnabled)

Sets the flag indicating whether the VAD is enabled.

If the VAD is disabled, the OnlineRecognizer class object does not detect the end of speech automatically. In this case, call the stopRecording() method to stop recording and switch to recognition.
Parameters:
vadEnabled

Flag indicating whether the VAD is enabled. Default value: true.

setWaitForConnection

public Builder setWaitForConnection (final boolean waitForConnection)

Sets the flag indicating that audio recording starts after a network connection is established.

Parameters:
waitForConnection
Flag indicating that audio recording starts after a network connection is established. Default value: false. Acceptable values:
  • true - an object of the OnlineRecognizer class will start recording immediately after a network connection is established.

  • false - an object of the OnlineRecognizer class will start recording immediately after launch and will cache data until the network connection is established.

setWaitForResultTimeout

public Builder setWaitForResultTimeout (final long value, @NonNull final java.util.concurrent.TimeUnit timeUnit)

Sets the server response timeout after sending the last fragment.

If no response with endOfUtterance = true (the onPartialResults(Recognizer, Recognition, boolean) method) is received from the server during this timeout, the OnlineRecognizer class object returns the ERROR_SERVER error in the onRecognizerError (Recognizer, Error) method.
Parameters:
value

Server response timeout after sending the last fragment. Default value: 10 seconds.

timeUnit

Specifies the value units.

toString

public String toString ()