Class 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.
    • 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: Recognizer
        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:
        dispose in class Recognizer
        Parameters:
        disposing - Flag to request disposal.