Class IntentRecognizer

  • All Implemented Interfaces:
    AutoCloseable

    public final class IntentRecognizer
    extends Recognizer
    Performs intent recognition on the speech input. It returns both recognized text and recognized intent. Note: close() must be called in order to release underlying resources held by the object.
    • Constructor Detail

      • IntentRecognizer

        public IntentRecognizer​(SpeechConfig speechConfig)
        Creates a new instance of an intent recognizer.
        Parameters:
        speechConfig - speech configuration.
      • IntentRecognizer

        public IntentRecognizer​(EmbeddedSpeechConfig embeddedSpeechConfig)
        Creates a new instance of an intent recognizer with embedded speech configuration.
        Parameters:
        embeddedSpeechConfig - embedded speech configuration.
      • IntentRecognizer

        public IntentRecognizer​(SpeechConfig speechConfig,
                                AudioConfig audioConfig)
        Creates a new instance of an intent recognizer.
        Parameters:
        speechConfig - speech configuration.
        audioConfig - audio configuration.
      • IntentRecognizer

        public IntentRecognizer​(EmbeddedSpeechConfig embeddedSpeechConfig,
                                AudioConfig audioConfig)
        Creates a new instance of an intent recognizer with embedded speech configuration.
        Parameters:
        embeddedSpeechConfig - embedded speech configuration.
        audioConfig - audio configuration.
    • Method Detail

      • getSpeechRecognitionLanguage

        public String getSpeechRecognitionLanguage()
        Gets the spoken language of recognition.
        Returns:
        the spoken language of recognition.
      • 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 IntentRecognizer.
        Returns:
        The collection of properties and their values defined for this IntentRecognizer.
      • recognizeOnceAsync

        public Future<IntentRecognitionResult> recognizeOnceAsync()
        Starts intent recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result. Note: Since recognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use startContinuousRecognitionAsync() instead.
        Returns:
        A task representing the recognition operation. The task returns a value of IntentRecognitionResult
      • recognizeOnceAsync

        public Future<IntentRecognitionResult> recognizeOnceAsync​(String text)
        Performs intent recognition, and generates a result from the text passed in. This is useful for testing and other times when the speech input is not tied to the IntentRecognizer. Note: The Intent Service does not currently support this so it is only valid for offline pattern matching or exact matching intents.
        Parameters:
        text - The text to be recognized for intent.
        Returns:
        A task representing the recognition operation. The task returns a value of IntentRecognitionResult.
      • startContinuousRecognitionAsync

        public Future<Void> startContinuousRecognitionAsync()
        Starts speech recognition on a continuous audio stream, until stopContinuousRecognitionAsync() is called. User must subscribe to events to receive recognition 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.
      • addIntent

        public void addIntent​(String simplePhrase)
        Adds a simple phrase that may be spoken by the user, indicating a specific user intent.
        Parameters:
        simplePhrase - The phrase corresponding to the intent.
      • addIntent

        public void addIntent​(String simplePhrase,
                              String intentId)
        Adds a simple phrase that may be spoken by the user, indicating a specific user intent.
        Parameters:
        simplePhrase - The phrase corresponding to the intent.
        intentId - A custom id String to be returned in the IntentRecognitionResult's getIntentId() method.
      • addIntent

        public void addIntent​(LanguageUnderstandingModel model,
                              String intentName)
        Adds a single intent by name from the specified Language Understanding Model.
        Parameters:
        model - The language understanding model containing the intent.
        intentName - The name of the single intent to be included from the language understanding model.
      • addIntent

        public void addIntent​(LanguageUnderstandingModel model,
                              String intentName,
                              String intentId)
        Adds a single intent by name from the specified Language Understanding Model.
        Parameters:
        model - The language understanding model containing the intent.
        intentName - The name of the single intent to be included from the language understanding model.
        intentId - A custom id String to be returned in the IntentRecognitionResult's getIntentId() method.
      • addAllIntents

        public void addAllIntents​(LanguageUnderstandingModel model,
                                  String intentId)
        Adds all intents from the specified Language Understanding Model.
        Parameters:
        model - The language understanding model containing the intents.
        intentId - A custom id String to be returned in the IntentRecognitionResult's getIntentId() method.
      • addAllIntents

        public void addAllIntents​(LanguageUnderstandingModel model)
        Adds all intents from the specified Language Understanding Model.
        Parameters:
        model - The language understanding model containing the intents.
      • startKeywordRecognitionAsync

        public Future<Void> startKeywordRecognitionAsync​(KeywordRecognitionModel model)
        Configures the recognizer with the given keyword model. After calling this method, the recognizer is listening for the keyword to start the recognition. Call stopKeywordRecognitionAsync() to end the keyword initiated recognition. User must subscribe to events to receive recognition results.
        Parameters:
        model - The keyword recognition model that specifies the keyword to be recognized.
        Returns:
        A task representing the asynchronous operation that starts the recognition.
      • stopKeywordRecognitionAsync

        public Future<Void> stopKeywordRecognitionAsync()
        Ends the keyword initiated recognition.
        Returns:
        A task representing the asynchronous operation that stops the recognition.
      • applyLanguageModels

        public boolean applyLanguageModels​(Collection<LanguageUnderstandingModel> collection)
                                    throws NullPointerException
        Takes a collection of language understanding models, makes a copy of them, and applies them to the recognizer. This application takes effect at different times depending on the LanguageUnderstandingModel type. PatternMatchingModels will become active immediately whereas LanguageUnderstandingModels utilizing the LUIS service will become active immediately unless the recognizer is in the middle of intent recognition in which case it will take effect after the next Recognized event. This replaces any previously applied models.
        Parameters:
        collection - A collection of shared pointers to LanguageUnderstandingModels.
        Returns:
        True if the application of the models takes effect immediately. Otherwise false.
        Throws:
        NullPointerException - If the collection passed is null.
      • 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.