Class IntentRecognizer
- java.lang.Object
-
- com.microsoft.cognitiveservices.speech.Recognizer
-
- com.microsoft.cognitiveservices.speech.intent.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.
-
-
Field Summary
Fields Modifier and Type Field Description EventHandlerImpl<IntentRecognitionCanceledEventArgs>canceledThe event canceled signals that the intent recognition was canceled.EventHandlerImpl<IntentRecognitionEventArgs>recognizedThe event recognized signals that a final recognition result is received.EventHandlerImpl<IntentRecognitionEventArgs>recognizingThe event recognizing signals that an intermediate recognition result is received.-
Fields inherited from class com.microsoft.cognitiveservices.speech.Recognizer
disposed, eventCounter, sessionStarted, sessionStopped, speechEndDetected, speechStartDetected
-
-
Constructor Summary
Constructors Constructor Description IntentRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)Creates a new instance of an intent recognizer with embedded speech configuration.IntentRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)Creates a new instance of an intent recognizer with embedded speech configuration.IntentRecognizer(SpeechConfig speechConfig)Creates a new instance of an intent recognizer.IntentRecognizer(SpeechConfig speechConfig, AudioConfig audioConfig)Creates a new instance of an intent recognizer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllIntents(LanguageUnderstandingModel model)Adds all intents from the specified Language Understanding Model.voidaddAllIntents(LanguageUnderstandingModel model, String intentId)Adds all intents from the specified Language Understanding Model.voidaddIntent(LanguageUnderstandingModel model, String intentName)Adds a single intent by name from the specified Language Understanding Model.voidaddIntent(LanguageUnderstandingModel model, String intentName, String intentId)Adds a single intent by name from the specified Language Understanding Model.voidaddIntent(String simplePhrase)Adds a simple phrase that may be spoken by the user, indicating a specific user intent.voidaddIntent(String simplePhrase, String intentId)Adds a simple phrase that may be spoken by the user, indicating a specific user intent.booleanapplyLanguageModels(Collection<LanguageUnderstandingModel> collection)Takes a collection of language understanding models, makes a copy of them, and applies them to the recognizer.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 IntentRecognizer.StringgetSpeechRecognitionLanguage()Gets the spoken language of recognition.Future<IntentRecognitionResult>recognizeOnceAsync()Starts intent recognition, and returns after a single utterance is recognized.Future<IntentRecognitionResult>recognizeOnceAsync(String text)Performs intent recognition, and generates a result from the text passed in.voidsetAuthorizationToken(String token)Sets the authorization token used to communicate with the service.Future<Void>startContinuousRecognitionAsync()Starts speech recognition on a continuous audio stream, until stopContinuousRecognitionAsync() is called.Future<Void>startKeywordRecognitionAsync(KeywordRecognitionModel model)Configures the recognizer with the given keyword model.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.Future<Void>stopKeywordRecognitionAsync()Ends the keyword initiated recognition.-
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<IntentRecognitionEventArgs> recognizing
The event recognizing signals that an intermediate recognition result is received.
-
recognized
public final EventHandlerImpl<IntentRecognitionEventArgs> recognized
The event recognized signals that a final recognition result is received.
-
canceled
public final EventHandlerImpl<IntentRecognitionCanceledEventArgs> canceled
The event canceled signals that the intent recognition was canceled.
-
-
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: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.
-
-