Class Recognizer
- java.lang.Object
-
- com.microsoft.cognitiveservices.speech.Recognizer
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ConversationTranscriber,IntentRecognizer,MeetingTranscriber,SpeechRecognizer,TranslationRecognizer
public class Recognizer extends Object implements AutoCloseable
Defines the base class Recognizer which mainly contains common event handlers. Note: close() must be called in order to release underlying resources held by the object.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandisposedInternal flag to indicate whether the object has been disposed.protected AtomicIntegereventCounterInternal event counter to track event registration status.EventHandlerImpl<SessionEventArgs>sessionStartedDefines event handler for session started event.EventHandlerImpl<SessionEventArgs>sessionStoppedDefines event handler for session stopped event.EventHandlerImpl<RecognitionEventArgs>speechEndDetectedDefines event handler for speech end detected event.EventHandlerImpl<RecognitionEventArgs>speechStartDetectedDefines event handler for speech start detected event.
-
Constructor Summary
Constructors Modifier Constructor Description protectedRecognizer(AudioConfig audioInput)Creates and initializes an instance of a Recognizer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longcanceledSetCallback(long recoHandle)Internal method to set canceled callback.voidclose()Dispose of associated resources.protected voiddispose(boolean disposing)This method performs cleanup of resources.protected voiddoAsyncRecognitionAction(Runnable recoImplAction)Internal method to run recognition operation.SafeHandlegetImpl()Returns the internal recognizer instanceprotected longgetPropertyBagFromRecognizerHandle(SafeHandle recoHandle, IntRef propertyHandle)Internal method to get the property bag from the recognizer handle.protected longrecognize()Internal method to start recognize once operation.protected longrecognizedSetCallback(long recoHandle)Internal method to set recognized callback.protected longrecognizingSetCallback(long recoHandle)Internal method to set recognizing callback.protected voidsessionStartedEventCallback(long eventArgs)Internal method to handle native session started event.protected longsessionStartedSetCallback(long recoHandle)Internal method to set session started callback.protected voidsessionStoppedEventCallback(long eventArgs)Internal method to handle native session stopped event.protected longsessionStoppedSetCallback(long recoHandle)Internal method to set session stopped callback.protected voidspeechEndDetectedEventCallback(long eventArgs)Internal method to handle native speech end detected event.protected longspeechEndDetectedSetCallback(long recoHandle)Internal method to set speech end detected callback.protected voidspeechStartDetectedEventCallback(long eventArgs)Internal method to handle native speech start detected event.protected longspeechStartDetectedSetCallback(long recoHandle)Internal method to set speech start detected callback.protected longstartContinuousRecognition(SafeHandle recoHandle)Internal method to start continuous recognition operation.protected longstartKeywordRecognition(SafeHandle recoHandle, SafeHandle keywordModelHandle)Internal method to start keyword recognition operation.protected longstopContinuousRecognition(SafeHandle recoHandle)Internal method to stop continuous recognition operation.protected longstopKeywordRecognition(SafeHandle recoHandle)Internal method to stop keyword recognition operation.
-
-
-
Field Detail
-
eventCounter
protected AtomicInteger eventCounter
Internal event counter to track event registration status.
-
sessionStarted
public final EventHandlerImpl<SessionEventArgs> sessionStarted
Defines event handler for session started event.
-
sessionStopped
public final EventHandlerImpl<SessionEventArgs> sessionStopped
Defines event handler for session stopped event.
-
speechStartDetected
public final EventHandlerImpl<RecognitionEventArgs> speechStartDetected
Defines event handler for speech start detected event.
-
speechEndDetected
public final EventHandlerImpl<RecognitionEventArgs> speechEndDetected
Defines event handler for speech end detected event.
-
disposed
protected boolean disposed
Internal flag to indicate whether the object has been disposed.
-
-
Constructor Detail
-
Recognizer
protected Recognizer(AudioConfig audioInput)
Creates and initializes an instance of a Recognizer- Parameters:
audioInput- An optional audio input configuration associated with the recognizer
-
-
Method Detail
-
close
public void close()
Dispose of associated resources. Note: close() must be called in order to release underlying resources held by the object.- Specified by:
closein interfaceAutoCloseable
-
getImpl
public SafeHandle getImpl()
Returns the internal recognizer instance- Returns:
- The internal recognizer instance
-
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.- Parameters:
disposing- Flag to request disposal.
-
doAsyncRecognitionAction
protected void doAsyncRecognitionAction(Runnable recoImplAction)
Internal method to run recognition operation.- Parameters:
recoImplAction- The runnable of the recognition operation.
-
recognize
protected long recognize()
Internal method to start recognize once operation.- Returns:
- The native result handle of the recognition.
-
sessionStartedEventCallback
protected void sessionStartedEventCallback(long eventArgs)
Internal method to handle native session started event.- Parameters:
eventArgs- The native event args.
-
sessionStoppedEventCallback
protected void sessionStoppedEventCallback(long eventArgs)
Internal method to handle native session stopped event.- Parameters:
eventArgs- The native event args.
-
speechStartDetectedEventCallback
protected void speechStartDetectedEventCallback(long eventArgs)
Internal method to handle native speech start detected event.- Parameters:
eventArgs- The native event args.
-
speechEndDetectedEventCallback
protected void speechEndDetectedEventCallback(long eventArgs)
Internal method to handle native speech end detected event.- Parameters:
eventArgs- The native event args.
-
startContinuousRecognition
protected final long startContinuousRecognition(SafeHandle recoHandle)
Internal method to start continuous recognition operation.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
stopContinuousRecognition
protected final long stopContinuousRecognition(SafeHandle recoHandle)
Internal method to stop continuous recognition operation.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
startKeywordRecognition
protected final long startKeywordRecognition(SafeHandle recoHandle, SafeHandle keywordModelHandle)
Internal method to start keyword recognition operation.- Parameters:
recoHandle- The native recognizer handle.keywordModelHandle- The native keyword model handle.- Returns:
- The native result handle of the operation.
-
stopKeywordRecognition
protected final long stopKeywordRecognition(SafeHandle recoHandle)
Internal method to stop keyword recognition operation.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
recognizingSetCallback
protected final long recognizingSetCallback(long recoHandle)
Internal method to set recognizing callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
recognizedSetCallback
protected final long recognizedSetCallback(long recoHandle)
Internal method to set recognized callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
canceledSetCallback
protected final long canceledSetCallback(long recoHandle)
Internal method to set canceled callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
sessionStartedSetCallback
protected final long sessionStartedSetCallback(long recoHandle)
Internal method to set session started callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
sessionStoppedSetCallback
protected final long sessionStoppedSetCallback(long recoHandle)
Internal method to set session stopped callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
speechStartDetectedSetCallback
protected final long speechStartDetectedSetCallback(long recoHandle)
Internal method to set speech start detected callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
speechEndDetectedSetCallback
protected final long speechEndDetectedSetCallback(long recoHandle)
Internal method to set speech end detected callback.- Parameters:
recoHandle- The native recognizer handle.- Returns:
- The native result handle of the operation.
-
getPropertyBagFromRecognizerHandle
protected final long getPropertyBagFromRecognizerHandle(SafeHandle recoHandle, IntRef propertyHandle)
Internal method to get the property bag from the recognizer handle.- Parameters:
recoHandle- The native recognizer handle.propertyHandle- The native property handle.- Returns:
- The native result handle of the operation.
-
-