IntentRecognizer Class
- java.
lang. Object - com.
microsoft. cognitiveservices. speech. Recognizer - com.
microsoft. cognitiveservices. speech. intent. IntentRecognizer
- com.
- com.
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
Modifier and Type | Field and Description |
---|---|
final
Event |
canceled
The event canceled signals that the intent recognition was canceled. |
final
Event |
recognized
The event recognized signals that a final recognition result is received. |
final
Event |
recognizing
The event recognizing signals that an intermediate recognition result is received. |
Constructor Summary
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
Modifier and Type | Method and Description |
---|---|
void |
addAllIntents(LanguageUnderstandingModel model)
Adds all intents from the specified Language Understanding Model. |
void |
addAllIntents(LanguageUnderstandingModel model, String intentId)
Adds all intents from the specified Language Understanding Model. |
void |
addIntent(LanguageUnderstandingModel model, String intentName)
Adds a single intent by name from the specified Language Understanding Model. |
void |
addIntent(LanguageUnderstandingModel model, String intentName, String intentId)
Adds a single intent by name from the specified Language Understanding Model. |
void |
addIntent(String simplePhrase)
Adds a simple phrase that may be spoken by the user, indicating a specific user intent. |
void |
addIntent(String simplePhrase, String intentId)
Adds a simple phrase that may be spoken by the user, indicating a specific user intent. |
boolean |
applyLanguageModels(Collection<LanguageUnderstandingModel> collection)
Takes a collection of language understanding models, makes a copy of them, and applies them to the recognizer. |
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. |
Property |
getProperties()
The collection of properties and their values defined for this Intent |
java.lang.String |
getSpeechRecognitionLanguage()
Gets the spoken language of recognition. |
java.util.concurrent.Future<Intent |
recognizeOnceAsync()
Starts intent recognition, and returns after a single utterance is recognized. |
java.util.concurrent.Future<Intent |
recognizeOnceAsync(String text)
Performs intent recognition, and generates a result from the text passed in. |
void |
setAuthorizationToken(String token)
Sets the authorization token used to communicate with the service. |
java.util.concurrent.Future<java.lang.Void> |
startContinuousRecognitionAsync()
Starts speech recognition on a continuous audio stream, until stop |
java.util.concurrent.Future<java.lang.Void> |
startKeywordRecognitionAsync(KeywordRecognitionModel model)
Configures the recognizer with the given keyword model. |
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. |
java.util.concurrent.Future<java.lang.Void> |
stopKeywordRecognitionAsync()
Ends the keyword initiated recognition. |
Methods inherited from Recognizer
Methods inherited from java.lang.Object
Field Details
canceled
public final EventHandlerImpl
The event canceled signals that the intent recognition was canceled.
recognized
public final EventHandlerImpl
The event recognized signals that a final recognition result is received.
recognizing
public final EventHandlerImpl
The event recognizing signals that an intermediate recognition result is received.
Constructor Details
IntentRecognizer
public IntentRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)
Creates a new instance of an intent recognizer with embedded speech configuration.
Parameters:
IntentRecognizer
public IntentRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)
Creates a new instance of an intent recognizer with embedded speech configuration.
Parameters:
IntentRecognizer
public IntentRecognizer(SpeechConfig speechConfig)
Creates a new instance of an intent recognizer.
Parameters:
IntentRecognizer
public IntentRecognizer(SpeechConfig speechConfig, AudioConfig audioConfig)
Creates a new instance of an intent recognizer.
Parameters:
Method Details
addAllIntents
public void addAllIntents(LanguageUnderstandingModel model)
Adds all intents from the specified Language Understanding Model.
Parameters:
addAllIntents
public void addAllIntents(LanguageUnderstandingModel model, String intentId)
Adds all intents from the specified Language Understanding Model.
Parameters:
addIntent
public void addIntent(LanguageUnderstandingModel model, String intentName)
Adds a single intent by name from the specified Language Understanding Model.
Parameters:
addIntent
public void addIntent(LanguageUnderstandingModel model, String intentName, String intentId)
Adds a single intent by name from the specified Language Understanding Model.
Parameters:
addIntent
public void addIntent(String simplePhrase)
Adds a simple phrase that may be spoken by the user, indicating a specific user intent.
Parameters:
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:
applyLanguageModels
public boolean applyLanguageModels(Collection
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:
Returns:
Throws:
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:
IntentRecognizer.dispose(boolean disposing)Parameters:
getAuthorizationToken
public String getAuthorizationToken()
Gets the authorization token used to communicate with the service.
Returns:
getProperties
public PropertyCollection getProperties()
The collection of properties and their values defined for this IntentRecognizer.
Returns:
getSpeechRecognitionLanguage
public String getSpeechRecognitionLanguage()
Gets the spoken language of recognition.
Returns:
recognizeOnceAsync
public Future
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:
IntentRecognitionResult
recognizeOnceAsync
public Future
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:
Returns:
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:
startContinuousRecognitionAsync
public Future
Starts speech recognition on a continuous audio stream, until stopContinuousRecognitionAsync() is called. User must subscribe to events to receive recognition results.
Returns:
startKeywordRecognitionAsync
public Future
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:
Returns:
stopContinuousRecognitionAsync
public Future
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:
stopKeywordRecognitionAsync
public Future
Ends the keyword initiated recognition.
Returns:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for