TranslationRecognizer Class

public final class TranslationRecognizer
extends Recognizer

Performs translation on the speech input. Note: close() must be called in order to release underlying resources held by the object.

Field Summary

Modifier and Type Field and Description
final EventHandlerImpl<TranslationRecognitionCanceledEventArgs> canceled

The event canceled signals that the recognition/translation was canceled.

final EventHandlerImpl<TranslationRecognitionEventArgs> recognized

The event recognized signals that a final recognition result is received.

final EventHandlerImpl<TranslationRecognitionEventArgs> recognizing

The event recognizing signals that an intermediate recognition result is received.

final EventHandlerImpl<TranslationSynthesisEventArgs> synthesizing

The event synthesizing signals that a translation synthesis result is received.

Constructor Summary

Constructor Description
TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

TranslationRecognizer(HybridSpeechConfig hybridSpeechConfig)

Constructs an instance of a translation recognizer for hybrid speech translation.

TranslationRecognizer(HybridSpeechConfig hybridSpeechConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for hybrid speech translation.

TranslationRecognizer(SpeechTranslationConfig stc)

Constructs an instance of a translation recognizer.

TranslationRecognizer(SpeechTranslationConfig stc, AudioConfig audioConfig)

Constructs an instance of a translation recognizer.

Method Summary

Modifier and Type Method and Description
void addTargetLanguage(String value)

Adds a target language for translation.

protected void dispose(boolean disposing)

This method performs cleanup of resources.

java.lang.String getAuthorizationToken()

Gets the authorization token used to communicate with the service.

PropertyCollection getProperties()

The collection of properties and their values defined for this TranslationRecognizer.

java.lang.String getSpeechRecognitionLanguage()

Gets the spoken language of recognition.

java.util.ArrayList<java.lang.String> getTargetLanguages()

Gets all target languages that have been configured for translation.

java.lang.String getVoiceName()

Gets the name of output voice.

java.util.concurrent.Future<TranslationRecognitionResult> recognizeOnceAsync()

Starts recognition and translation, and stops after the first utterance is recognized.

void removeTargetLanguage(String value)

Removes a target language for translation.

void setAuthorizationToken(String token)

Sets the authorization token used to communicate with the service.

java.util.concurrent.Future<java.lang.Void> startContinuousRecognitionAsync()

Starts recognition and translation on a continuous audio stream, until StopContinuousRecognitionAsync() is called.

java.util.concurrent.Future<java.lang.Void> stopContinuousRecognitionAsync()

Stops a running recognition operation as soon as possible and immediately requests a result based on the the input that has been processed so far.

Methods inherited from Recognizer

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

canceled

public final EventHandlerImpl canceled

The event canceled signals that the recognition/translation was canceled.

recognized

public final EventHandlerImpl recognized

The event recognized signals that a final recognition result is received.

recognizing

public final EventHandlerImpl recognizing

The event recognizing signals that an intermediate recognition result is received.

synthesizing

public final EventHandlerImpl synthesizing

The event synthesizing signals that a translation synthesis result is received.

Constructor Details

TranslationRecognizer

public TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

Parameters:

embeddedSpeechConfig - embedded speech config.

TranslationRecognizer

public TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

Parameters:

embeddedSpeechConfig - embedded speech config.
autoDetectSourceLangConfig - auto detection source language config.

TranslationRecognizer

public TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

Parameters:

embeddedSpeechConfig - embedded speech config.
autoDetectSourceLangConfig - auto detection source language config.
audioConfig - audio config.

TranslationRecognizer

public TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for embedded speech translation.

Parameters:

embeddedSpeechConfig - embedded speech config.
audioConfig - audio config.

TranslationRecognizer

public TranslationRecognizer(HybridSpeechConfig hybridSpeechConfig)

Constructs an instance of a translation recognizer for hybrid speech translation.

Parameters:

hybridSpeechConfig - hybrid speech config.

TranslationRecognizer

public TranslationRecognizer(HybridSpeechConfig hybridSpeechConfig, AudioConfig audioConfig)

Constructs an instance of a translation recognizer for hybrid speech translation.

Parameters:

hybridSpeechConfig - hybrid speech config.
audioConfig - audio config.

TranslationRecognizer

public TranslationRecognizer(SpeechTranslationConfig stc)

Constructs an instance of a translation recognizer.

Parameters:

stc - speech translation config.

TranslationRecognizer

public TranslationRecognizer(SpeechTranslationConfig stc, AudioConfig audioConfig)

Constructs an instance of a translation recognizer.

Parameters:

stc - speech translation config.
audioConfig - audio config.

Method Details

addTargetLanguage

public void addTargetLanguage(String value)

Adds a target language for translation. Added in version 1.7.0.

Parameters:

value - the language identifier in BCP-47 format.

dispose

protected void dispose(boolean disposing)

This method performs cleanup of resources. The Boolean parameter disposing indicates whether the method is called from Dispose (if disposing is true) or from the finalizer (if disposing is false). Derived classes should override this method to dispose resource if needed.

Overrides:

TranslationRecognizer.dispose(boolean disposing)

Parameters:

disposing

getAuthorizationToken

public String getAuthorizationToken()

Gets the authorization token used to communicate with the service.

Returns:

Authorization token.

getProperties

public PropertyCollection getProperties()

The collection of properties and their values defined for this TranslationRecognizer.

Returns:

The collection of properties and their values defined for this TranslationRecognizer.

getSpeechRecognitionLanguage

public String getSpeechRecognitionLanguage()

Gets the spoken language of recognition.

Returns:

The spoken language of recognition.

getTargetLanguages

public ArrayList getTargetLanguages()

Gets all target languages that have been configured for translation.

Returns:

the list of target languages.

getVoiceName

public String getVoiceName()

Gets the name of output voice.

Returns:

the name of output voice.

recognizeOnceAsync

public Future recognizeOnceAsync()

Starts recognition and translation, and stops after the first utterance is recognized. The task returns the translation text as result. Note: RecognizeOnceAsync() returns when the first utterance has been recognized, so it is suitableonly for single shot recognition like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.

Returns:

A task representing the recognition operation. The task returns a value of TranslationRecognitionResult.

removeTargetLanguage

public void removeTargetLanguage(String value)

Removes a target language for translation. Added in version 1.7.0.

Parameters:

value - the language identifier in BCP-47 format.

setAuthorizationToken

public void setAuthorizationToken(String token)

Sets the authorization token used to communicate with the service. Note: The caller needs to ensure that the authorization token is valid. Before the authorization token expires, the caller needs to refresh it by calling this setter with a new valid token. Otherwise, the recognizer will encounter errors during recognition.

Parameters:

token - Authorization token.

startContinuousRecognitionAsync

public Future startContinuousRecognitionAsync()

Starts recognition and translation on a continuous audio stream, until StopContinuousRecognitionAsync() is called. User must subscribe to events to receive translation results.

Returns:

A task representing the asynchronous operation that starts the recognition.

stopContinuousRecognitionAsync

public Future stopContinuousRecognitionAsync()

Stops a running recognition operation as soon as possible and immediately requests a result based on the the input that has been processed so far. This works for all recognition operations, not just continuous ones, and facilitates the use of push-to-talk or "finish now" buttons for manual audio endpointing.

Returns:

A future that will complete when input processing has been stopped. Result generation, if applicable for the input provided, may happen after this task completes and should be handled with the appropriate event.

Applies to