Aracılığıyla paylaş


IntentRecognizer Class

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 EventHandlerImpl<IntentRecognitionCanceledEventArgs> canceled

The event canceled signals that the intent recognition was canceled.

final EventHandlerImpl<IntentRecognitionEventArgs> recognized

The event recognized signals that a final recognition result is received.

final EventHandlerImpl<IntentRecognitionEventArgs> 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.

PropertyCollection getProperties()

The collection of properties and their values defined for this IntentRecognizer.

java.lang.String getSpeechRecognitionLanguage()

Gets the spoken language of recognition.

java.util.concurrent.Future<IntentRecognitionResult> recognizeOnceAsync()

Starts intent recognition, and returns after a single utterance is recognized.

java.util.concurrent.Future<IntentRecognitionResult> 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 stopContinuousRecognitionAsync() is called.

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

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

canceled

public final EventHandlerImpl canceled

The event canceled signals that the intent recognition was canceled.

recognized

public final EventHandlerImpl recognized

The event recognized signals that a final recognition result is received.

recognizing

public final EventHandlerImpl recognizing

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:

embeddedSpeechConfig - embedded speech 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.

IntentRecognizer

public IntentRecognizer(SpeechConfig speechConfig)

Creates a new instance of an intent recognizer.

Parameters:

speechConfig - speech configuration.

IntentRecognizer

public IntentRecognizer(SpeechConfig speechConfig, AudioConfig audioConfig)

Creates a new instance of an intent recognizer.

Parameters:

speechConfig - speech configuration.
audioConfig - audio configuration.

Method Details

addAllIntents

public void addAllIntents(LanguageUnderstandingModel model)

Adds all intents from the specified Language Understanding Model.

Parameters:

model - The language understanding model containing the intents.

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.

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.

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.

applyLanguageModels

public boolean applyLanguageModels(Collection 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:

collection - A collection of shared pointers to LanguageUnderstandingModels.

Returns:

True if the application of the models takes effect immediately. Otherwise false.

Throws:

java.lang.NullPointerException - If the collection passed is null.

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:

disposing

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.

getSpeechRecognitionLanguage

public String getSpeechRecognitionLanguage()

Gets the spoken language of recognition.

Returns:

the spoken language of recognition.

recognizeOnceAsync

public Future 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 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.

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.

startContinuousRecognitionAsync

public Future 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.

startKeywordRecognitionAsync

public Future 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.

stopContinuousRecognitionAsync

public Future 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.

stopKeywordRecognitionAsync

public Future stopKeywordRecognitionAsync()

Ends the keyword initiated recognition.

Returns:

A task representing the asynchronous operation that stops the recognition.

Applies to