SpeechRecognizer Class
- java.
lang. Object - com.
microsoft. cognitiveservices. speech. Recognizer - com.
microsoft. cognitiveservices. speech. SpeechRecognizer
- com.
- com.
public final class SpeechRecognizer
extends Recognizer
Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result. 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 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
Method Summary
Modifier and Type | Method and Description |
---|---|
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. |
java.lang.String |
getEndpointId()
Gets the endpoint ID of a customized speech model that is used for speech recognition. |
Output |
getOutputFormat()
Gets the output format of recognition. |
Property |
getProperties()
The collection of properties and their values defined for this Speech |
java.lang.String |
getSpeechRecognitionLanguage()
Gets the spoken language of recognition. |
java.util.concurrent.Future<Speech |
recognizeOnceAsync()
Starts speech recognition, and returns after a single utterance is recognized. |
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 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
SpeechRecognizer
public SpeechRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig)
Initializes a new instance of Speech Recognizer for embedded speech recognition. Added in version 1.19.0
Parameters:
SpeechRecognizer
public SpeechRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig)
Initializes a new instance of Speech Recognizer for embedded speech recognition. Added in version 1.20.0
Parameters:
SpeechRecognizer
public SpeechRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer for embedded speech recognition. Added in version 1.20.0
Parameters:
SpeechRecognizer
public SpeechRecognizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer for embedded speech recognition. Added in version 1.19.0
Parameters:
SpeechRecognizer
public SpeechRecognizer(HybridSpeechConfig hybridSpeechConfig)
Initializes a new instance of Speech Recognizer for hybrid speech recognition.
Parameters:
SpeechRecognizer
public SpeechRecognizer(HybridSpeechConfig hybridSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig)
Initializes a new instance of Speech Recognizer for hybrid speech recognition.
Parameters:
SpeechRecognizer
public SpeechRecognizer(HybridSpeechConfig hybridSpeechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer for hybrid speech recognition.
Parameters:
SpeechRecognizer
public SpeechRecognizer(HybridSpeechConfig hybridSpeechConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer for hybrid speech recognition.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, SourceLanguageConfig sourceLanguageConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, SourceLanguageConfig sourceLanguageConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, String sourceLanguage)
Initializes a new instance of Speech Recognizer.
Parameters:
SpeechRecognizer
public SpeechRecognizer(SpeechConfig speechConfig, String sourceLanguage, AudioConfig audioConfig)
Initializes a new instance of Speech Recognizer.
Parameters:
Method Details
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:
SpeechRecognizer.dispose(boolean disposing)Parameters:
getAuthorizationToken
public String getAuthorizationToken()
Gets the authorization token used to communicate with the service.
Returns:
getEndpointId
public String getEndpointId()
Gets the endpoint ID of a customized speech model that is used for speech recognition.
Returns:
getOutputFormat
public OutputFormat getOutputFormat()
Gets the output format of recognition.
Returns:
getProperties
public PropertyCollection getProperties()
The collection of properties and their values defined for this SpeechRecognizer.
Returns:
getSpeechRecognitionLanguage
public String getSpeechRecognitionLanguage()
Gets the spoken language of recognition.
Returns:
recognizeOnceAsync
public Future
Starts speech 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:
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