![]() |
KeenASR Unity Plugin 2.1.3
Unity plugin for KeenASR offline speech recognition SDK (iOS & Android)
|
Main facade for the KeenASR speech recognition plugin. More...
Public Member Functions | |
| delegate void | InitializedHandler (bool status) |
| Called when the ASR engine has finished initializing. | |
| delegate void | PartialASRResultHandler (string text) |
| Called during recognition with intermediate (non-final) text. | |
| delegate void | FinalASRResultHandler (ASRResponse response) |
| Called when recognition is complete with the final response. The caller receives ownership of the ASRResponse and must call Dispose() on it when done to release the native handle. | |
| delegate void | UnwindAppAudioBeforeAudioInterruptHandler () |
| Called immediately before KeenASR unwinds its audio stack due to an audio interrupt (e.g. the app going to background). Stop any app-controlled audio playback in this handler. Do not modify the audio session or interact with the recognizer. | |
| delegate void | RecognizerReadyToListenAfterInterruptHandler () |
| Called when the recognizer is ready to listen again after an audio interrupt (e.g. the app returning to foreground). Use this to re-enable UI elements. | |
Decoding Graphs | |
| bool | DecodingGraphWithNameExists (string dgName) |
| Checks whether a decoding graph with the given name exists on the device. | |
| bool | CreateDecodingGraphFromPhrases (string dgName, string[] phrases, SpeakingTask task=SpeakingTask.Default, WordPronunciation[] alternativePronunciations=null, float spokenNoiseProbability=0.5f) |
| Creates a decoding graph from the given list of phrases. The decoding graph defines the set of utterances the recognizer can detect. The graph is saved on the device and can be referenced later by name. | |
| bool | CreateContextualDecodingGraphFromPhrases (string dgName, string[][] contextualPhrases, SpeakingTask task=SpeakingTask.Default, WordPronunciation[] alternativePronunciations=null, float spokenNoiseProbability=0.5f) |
| Creates a contextual decoding graph from multiple groups of phrases. Each group represents a context that can be switched at runtime using PrepareForListeningWithContextualDecodingGraph. This is more efficient than creating separate decoding graphs when you have many contexts (e.g. pages in a book). | |
Listening | |
| bool | PrepareForListeningWithDecodingGraph (string dgName, bool computeGoP=false) |
| Loads a previously created decoding graph and prepares the recognizer for listening. After this call succeeds, the recognizer state transitions to ReadyToListen. | |
| bool | PrepareForListeningWithDecodingGraphAtPath (string path, bool computeGoP=false) |
| Loads a decoding graph from the specified filesystem path and prepares the recognizer for listening. After this call succeeds, the recognizer state transitions to ReadyToListen. | |
| bool | PrepareForListeningWithContextualDecodingGraph (string dgName, int contextId, bool computeGoP=false) |
| Loads a contextual decoding graph and prepares the recognizer for listening with the specified context. Use this with decoding graphs created via CreateContextualDecodingGraphFromPhrases. After this call succeeds, the recognizer state transitions to ReadyToListen. | |
| bool | PrepareForListeningWithContextualDecodingGraphAtPath (string path, int contextId, bool computeGoP=false) |
| Loads a contextual decoding graph from the specified filesystem path and prepares the recognizer for listening with the specified context. After this call succeeds, the recognizer state transitions to ReadyToListen. | |
| bool | StartListening () |
| Starts listening for speech. The recognizer must be in ReadyToListen state (i.e. PrepareForListeningWithDecodingGraph must have been called first). Recognition results are delivered via onPartialASRResultReceived and onFinalResponseReceived events. | |
| void | StopListening () |
| Stops the recognizer from processing incoming audio. Note that calling this method will NOT trigger the onFinalResponseReceived callback. If you need the final result, set VAD timeout thresholds (e.g. TimeoutEndSilenceForGoodMatch) to short values so that the recognizer stops naturally via VAD and delivers the result through the callback. | |
| RecognizerState | GetRecognizerState () |
| Returns the current state of the recognizer. | |
| float | InputLevel () |
| Returns the current input audio level in dB. Poll this method periodically to drive a UI element that gives the user visual feedback that the system is hearing them. Only meaningful while the recognizer is in Listening state. | |
Configuration | |
| bool | SetVADParameter (VadParameter vadParameter, float value) |
| Sets a Voice Activity Detection parameter. VAD parameters control when the recognizer automatically stops listening (e.g. after a period of silence or after reaching a maximum duration). | |
| bool | IsEchoCancellationAvaialable () |
| Checks whether the device supports echo cancellation. | |
| void | PerformEchoCancellation (bool value) |
| Enables or disables echo cancellation. When enabled, audio played by the app through the device speaker is removed from the microphone signal, allowing recognition to work during audio playback. | |
Speaker Adaptation | |
| void | AdaptToSpeakerWithName (string speakerName) |
| Starts speaker adaptation for the named user. If a saved adaptation profile exists for this user, it will be loaded. Use this when you know with high confidence which user will be speaking. In shared-device environments, it is better not to use adaptation. | |
| void | ResetSpeakerAdaptation () |
| Resets speaker adaptation to the baseline model, discarding any in-session adaptation data. Does not remove saved adaptation profiles. | |
| void | SaveSpeakerAdaptationProfile () |
| Persists the current speaker adaptation profile so it can be reused in future sessions when AdaptToSpeakerWithName is called with the same name. | |
| bool | RemoveAllSpeakerAdaptationProfiles () |
| Removes all saved speaker adaptation profiles from the device. | |
| bool | RemoveSpeakerAdaptationProfiles (string speakerName) |
| Removes the saved adaptation profile for the specified speaker. | |
Static Public Member Functions | |
Initialization | |
| static bool | Initialize (string bundleName) |
| Initializes the ASR engine with the named ASR bundle from StreamingAssets. | |
| static bool | InitializeWithASRBundleAtPath (string asrBundlePath) |
| Initializes the ASR engine with the ASR bundle at the given filesystem path. | |
| static bool | Teardown () |
| Tears down the recognizer and releases all associated resources. All audio playback should be stopped before calling this method. | |
| static void | SetLogLevel (LogLevel logLevel) |
| Sets the framework logging verbosity. Can be called before Initialize(). | |
Dashboard | |
| static bool | StartDataUploader (string appKey) |
| Starts a background uploader thread that uploads queued responses to Dashboard. Call this once during setup; responses are queued via ASRResponse.QueueForUpload(). | |
| static bool | ResumeUploader () |
| Resumes the data uploader after it has been paused. | |
| static void | PauseUploader () |
| Pauses the data uploader. Queued files are retained and will be uploaded when the uploader is resumed. | |
| static bool | StopUploader () |
| Stops the data uploader thread. After stopping, StartDataUploader() must be called again to resume uploads. | |
Properties | |
| static KeenASR | Instance [get] |
| Gets the shared KeenASR instance. Returns null if the SDK has not been initialized. | |
Events | |
| static InitializedHandler | onInitializedReceived |
| Raised when the ASR engine has finished initializing. Subscribe to this event before calling Initialize(). | |
Events | |
| PartialASRResultHandler | onPartialASRResultReceived |
| Raised during recognition with intermediate (non-final) text as it becomes available. | |
| FinalASRResultHandler | onFinalResponseReceived |
| Raised when recognition is complete with the final response. The handler receives an ASRResponse that it must dispose when done. | |
| UnwindAppAudioBeforeAudioInterruptHandler | onUnwindAppAudioBeforeAudioInterruptReceived |
| Raised immediately before KeenASR unwinds its audio stack due to an audio interrupt. See UnwindAppAudioBeforeAudioInterruptHandler for details. | |
| RecognizerReadyToListenAfterInterruptHandler | onRecognizerReadyToListenAfterInterruptReceived |
| Raised when the recognizer is ready to listen again after an audio interrupt. | |
Main facade for the KeenASR speech recognition plugin.
Provides a singleton interface for initializing the ASR engine, managing decoding graphs, controlling the recognizer lifecycle (listening, VAD, echo cancellation), and handling recognition results. Works on iOS and Android; uses a stub in the Unity Editor.
Typical usage:
|
inline |
Starts speaker adaptation for the named user. If a saved adaptation profile exists for this user, it will be loaded. Use this when you know with high confidence which user will be speaking. In shared-device environments, it is better not to use adaptation.
| speakerName | A name or pseudonym identifying the speaker. |
|
inline |
Creates a contextual decoding graph from multiple groups of phrases. Each group represents a context that can be switched at runtime using PrepareForListeningWithContextualDecodingGraph. This is more efficient than creating separate decoding graphs when you have many contexts (e.g. pages in a book).
| dgName | Name for the decoding graph (used to reference it later). |
| contextualPhrases | Array of phrase arrays, where each inner array is a context. The index of each inner array becomes its contextId. |
| task | Speaking task type (affects language model optimization). |
| alternativePronunciations | Optional array of alternative pronunciations for words in the phrases. Pass null if not needed. |
| spokenNoiseProbability | Probability of <SPOKEN_NOISE> appearing in results (0.0–1.0, default 0.5). |
|
inline |
Creates a decoding graph from the given list of phrases. The decoding graph defines the set of utterances the recognizer can detect. The graph is saved on the device and can be referenced later by name.
| dgName | Name for the decoding graph (used to reference it later). |
| phrases | Array of phrases the user is likely to say. |
| task | Speaking task type (affects language model optimization). |
| alternativePronunciations | Optional array of alternative pronunciations for words in the phrases. Pass null if not needed. |
| spokenNoiseProbability | Probability of <SPOKEN_NOISE> appearing in results (0.0–1.0, default 0.5). Lower values reduce its frequency; higher values increase it. |
|
inline |
Checks whether a decoding graph with the given name exists on the device.
| dgName | Name of the decoding graph. |
| delegate void KeenResearch.KeenASR.FinalASRResultHandler | ( | ASRResponse | response | ) |
Called when recognition is complete with the final response. The caller receives ownership of the ASRResponse and must call Dispose() on it when done to release the native handle.
| response | The final recognition response. Caller must dispose. |
|
inline |
Returns the current state of the recognizer.
|
inlinestatic |
Initializes the ASR engine with the named ASR bundle from StreamingAssets.
On Android this call runs asynchronously; on iOS it runs synchronously. On both platforms, the onInitializedReceived event is raised when initialization completes. Subscribe to this event before calling Initialize().
Calling this method when the SDK is already initialized returns false.
| bundleName | Name of the ASR bundle directory in StreamingAssets (e.g. "keenA1m-nnet3chain-en-us"). |
| delegate void KeenResearch.KeenASR.InitializedHandler | ( | bool | status | ) |
Called when the ASR engine has finished initializing.
| status | true if initialization succeeded, false otherwise. |
|
inlinestatic |
Initializes the ASR engine with the ASR bundle at the given filesystem path.
On Android this call runs asynchronously; on iOS it runs synchronously. On both platforms, the onInitializedReceived event is raised when initialization completes. Subscribe to this event before calling this method.
Calling this method when the SDK is already initialized returns false.
| asrBundlePath | Full filesystem path to the ASR bundle directory. |
|
inline |
Returns the current input audio level in dB. Poll this method periodically to drive a UI element that gives the user visual feedback that the system is hearing them. Only meaningful while the recognizer is in Listening state.
|
inline |
Checks whether the device supports echo cancellation.
| delegate void KeenResearch.KeenASR.PartialASRResultHandler | ( | string | text | ) |
Called during recognition with intermediate (non-final) text.
| text | The partial recognition text so far. |
|
inlinestatic |
Pauses the data uploader. Queued files are retained and will be uploaded when the uploader is resumed.
|
inline |
Enables or disables echo cancellation. When enabled, audio played by the app through the device speaker is removed from the microphone signal, allowing recognition to work during audio playback.
| value | true to enable echo cancellation, false to disable. |
|
inline |
Loads a contextual decoding graph and prepares the recognizer for listening with the specified context. Use this with decoding graphs created via CreateContextualDecodingGraphFromPhrases. After this call succeeds, the recognizer state transitions to ReadyToListen.
| dgName | Name of a contextual decoding graph. |
| contextId | Index of the context to use (corresponds to the index in the contextualPhrases array used during creation). |
| computeGoP | If true, compute goodness of pronunciation scores at the phoneme level in the final result. |
|
inline |
Loads a contextual decoding graph from the specified filesystem path and prepares the recognizer for listening with the specified context. After this call succeeds, the recognizer state transitions to ReadyToListen.
| path | Full filesystem path to the contextual decoding graph directory. |
| contextId | Index of the context to use. |
| computeGoP | If true, compute goodness of pronunciation scores at the phoneme level in the final result. |
|
inline |
Loads a previously created decoding graph and prepares the recognizer for listening. After this call succeeds, the recognizer state transitions to ReadyToListen.
| dgName | Name of a decoding graph created with CreateDecodingGraphFromPhrases. |
| computeGoP | If true, compute goodness of pronunciation scores at the phoneme level in the final result. |
|
inline |
Loads a decoding graph from the specified filesystem path and prepares the recognizer for listening. After this call succeeds, the recognizer state transitions to ReadyToListen.
| path | Full filesystem path to the decoding graph directory. |
| computeGoP | If true, compute goodness of pronunciation scores at the phoneme level in the final result. |
| delegate void KeenResearch.KeenASR.RecognizerReadyToListenAfterInterruptHandler | ( | ) |
Called when the recognizer is ready to listen again after an audio interrupt (e.g. the app returning to foreground). Use this to re-enable UI elements.
|
inline |
Removes all saved speaker adaptation profiles from the device.
|
inline |
Removes the saved adaptation profile for the specified speaker.
| speakerName | Name of the speaker whose profile should be removed. |
|
inline |
Resets speaker adaptation to the baseline model, discarding any in-session adaptation data. Does not remove saved adaptation profiles.
|
inlinestatic |
Resumes the data uploader after it has been paused.
|
inline |
Persists the current speaker adaptation profile so it can be reused in future sessions when AdaptToSpeakerWithName is called with the same name.
|
inlinestatic |
Sets the framework logging verbosity. Can be called before Initialize().
| logLevel | The desired log level. |
|
inline |
Sets a Voice Activity Detection parameter. VAD parameters control when the recognizer automatically stops listening (e.g. after a period of silence or after reaching a maximum duration).
| vadParameter | The VAD parameter to set. |
| value | Timeout value in seconds. |
|
inlinestatic |
Starts a background uploader thread that uploads queued responses to Dashboard. Call this once during setup; responses are queued via ASRResponse.QueueForUpload().
| appKey | The APP_KEY for your app as shown in Dashboard. |
|
inline |
Starts listening for speech. The recognizer must be in ReadyToListen state (i.e. PrepareForListeningWithDecodingGraph must have been called first). Recognition results are delivered via onPartialASRResultReceived and onFinalResponseReceived events.
|
inline |
Stops the recognizer from processing incoming audio. Note that calling this method will NOT trigger the onFinalResponseReceived callback. If you need the final result, set VAD timeout thresholds (e.g. TimeoutEndSilenceForGoodMatch) to short values so that the recognizer stops naturally via VAD and delivers the result through the callback.
|
inlinestatic |
Stops the data uploader thread. After stopping, StartDataUploader() must be called again to resume uploads.
|
inlinestatic |
Tears down the recognizer and releases all associated resources. All audio playback should be stopped before calling this method.
After teardown, Instance will return null. The SDK can be re-initialized by calling Initialize() again.
| delegate void KeenResearch.KeenASR.UnwindAppAudioBeforeAudioInterruptHandler | ( | ) |
Called immediately before KeenASR unwinds its audio stack due to an audio interrupt (e.g. the app going to background). Stop any app-controlled audio playback in this handler. Do not modify the audio session or interact with the recognizer.
This handler must return quickly, otherwise the audio stack may not unwind before the app is suspended.
|
staticget |
Gets the shared KeenASR instance. Returns null if the SDK has not been initialized.
| FinalASRResultHandler KeenResearch.KeenASR.onFinalResponseReceived |
Raised when recognition is complete with the final response. The handler receives an ASRResponse that it must dispose when done.
|
static |
Raised when the ASR engine has finished initializing. Subscribe to this event before calling Initialize().
| PartialASRResultHandler KeenResearch.KeenASR.onPartialASRResultReceived |
Raised during recognition with intermediate (non-final) text as it becomes available.
| RecognizerReadyToListenAfterInterruptHandler KeenResearch.KeenASR.onRecognizerReadyToListenAfterInterruptReceived |
Raised when the recognizer is ready to listen again after an audio interrupt.
| UnwindAppAudioBeforeAudioInterruptHandler KeenResearch.KeenASR.onUnwindAppAudioBeforeAudioInterruptReceived |
Raised immediately before KeenASR unwinds its audio stack due to an audio interrupt. See UnwindAppAudioBeforeAudioInterruptHandler for details.