Class TranslationRecognizer
- java.lang.Object
-
- com.microsoft.cognitiveservices.speech.Recognizer
-
- com.microsoft.cognitiveservices.speech.translation.TranslationRecognizer
-
- All Implemented Interfaces:
AutoCloseable
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
Fields Modifier and Type Field Description EventHandlerImpl<TranslationRecognitionCanceledEventArgs>canceledThe event canceled signals that the recognition/translation was canceled.EventHandlerImpl<TranslationRecognitionEventArgs>recognizedThe event recognized signals that a final recognition result is received.EventHandlerImpl<TranslationRecognitionEventArgs>recognizingThe event recognizing signals that an intermediate recognition result is received.EventHandlerImpl<TranslationSynthesisEventArgs>synthesizingThe event synthesizing signals that a translation synthesis result is received.-
Fields inherited from class com.microsoft.cognitiveservices.speech.Recognizer
disposed, eventCounter, sessionStarted, sessionStopped, speechEndDetected, speechStartDetected
-
-
Constructor Summary
Constructors Constructor Description TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTargetLanguage(String value)Adds a target language for translation.protected voiddispose(boolean disposing)This method performs cleanup of resources.StringgetAuthorizationToken()Gets the authorization token used to communicate with the service.PropertyCollectiongetProperties()The collection of properties and their values defined for this TranslationRecognizer.StringgetSpeechRecognitionLanguage()Gets the spoken language of recognition.ArrayList<String>getTargetLanguages()Gets all target languages that have been configured for translation.StringgetVoiceName()Gets the name of output voice.Future<TranslationRecognitionResult>recognizeOnceAsync()Starts recognition and translation, and stops after the first utterance is recognized.voidremoveTargetLanguage(String value)Removes a target language for translation.voidsetAuthorizationToken(String token)Sets the authorization token used to communicate with the service.Future<Void>startContinuousRecognitionAsync()Starts recognition and translation on a continuous audio stream, until StopContinuousRecognitionAsync() is called.Future<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 class com.microsoft.cognitiveservices.speech.Recognizer
canceledSetCallback, close, doAsyncRecognitionAction, getImpl, getPropertyBagFromRecognizerHandle, recognize, recognizedSetCallback, recognizingSetCallback, sessionStartedEventCallback, sessionStartedSetCallback, sessionStoppedEventCallback, sessionStoppedSetCallback, speechEndDetectedEventCallback, speechEndDetectedSetCallback, speechStartDetectedEventCallback, speechStartDetectedSetCallback, startContinuousRecognition, startKeywordRecognition, stopContinuousRecognition, stopKeywordRecognition
-
-
-
-
Field Detail
-
recognizing
public final EventHandlerImpl<TranslationRecognitionEventArgs> recognizing
The event recognizing signals that an intermediate recognition result is received.
-
recognized
public final EventHandlerImpl<TranslationRecognitionEventArgs> recognized
The event recognized signals that a final recognition result is received.
-
canceled
public final EventHandlerImpl<TranslationRecognitionCanceledEventArgs> canceled
The event canceled signals that the recognition/translation was canceled.
-
synthesizing
public final EventHandlerImpl<TranslationSynthesisEventArgs> synthesizing
The event synthesizing signals that a translation synthesis result is received.
-
-
Constructor Detail
-
TranslationRecognizer
public TranslationRecognizer(SpeechTranslationConfig stc)
Constructs an instance of a translation recognizer.- Parameters:
stc- speech translation config.
-
TranslationRecognizer
public TranslationRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)
Constructs an instance of a translation recognizer for embedded speech translation.- Parameters:
embeddedSpeechConfig- embedded speech 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(SpeechTranslationConfig stc, AudioConfig audioConfig)
Constructs an instance of a translation recognizer.- Parameters:
stc- speech translation 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, AudioConfig audioConfig)
Constructs an instance of a translation recognizer for hybrid speech translation.- Parameters:
hybridSpeechConfig- hybrid speech config.audioConfig- audio config.
-
-
Method Detail
-
getSpeechRecognitionLanguage
public String getSpeechRecognitionLanguage()
Gets the spoken language of recognition.- Returns:
- The spoken language of recognition.
-
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.
-
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.
-
getTargetLanguages
public ArrayList<String> 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.
-
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.
-
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.
-
recognizeOnceAsync
public Future<TranslationRecognitionResult> 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.
-
startContinuousRecognitionAsync
public Future<Void> 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<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. 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.
-
dispose
protected void dispose(boolean disposing)
Description copied from class:RecognizerThis 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:
disposein classRecognizer- Parameters:
disposing- Flag to request disposal.
-
-