KeenASR Unity Plugin 2.1.3
Unity plugin for KeenASR offline speech recognition SDK (iOS & Android)
Loading...
Searching...
No Matches
KeenResearch.KeenASR Class Reference

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.
 

Detailed Description

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:

KeenASR.onInitializedReceived += OnInit;
KeenASR.Initialize("keenA1m-nnet3chain-en-us");
void OnInit(bool success) {
KeenASR.Instance.onFinalResponseReceived += OnResponse;
}
void OnResponse(ASRResponse response) {
Debug.Log(response.result.cleanText);
response.Dispose();
}
Wraps a single recognition response, providing access to the recognition result, audio quality metric...
Definition KeenASR.cs:227
void Dispose()
Releases the native handle associated with this response. This method is idempotent and safe to call ...
Definition KeenASR.cs:315
ASRResult result
The recognition result (text, words, phonemes, confidence).
Definition KeenASR.cs:233
string cleanText
Clean recognition result text with special words removed.
Definition KeenASR.cs:163
Main facade for the KeenASR speech recognition plugin.
Definition KeenASR.cs:365
bool StartListening()
Starts listening for speech. The recognizer must be in ReadyToListen state (i.e. PrepareForListeningW...
Definition KeenASR.cs:709
static KeenASR Instance
Gets the shared KeenASR instance. Returns null if the SDK has not been initialized.
Definition KeenASR.cs:440
static bool Initialize(string bundleName)
Initializes the ASR engine with the named ASR bundle from StreamingAssets.
Definition KeenASR.cs:461
bool PrepareForListeningWithDecodingGraph(string dgName, bool computeGoP=false)
Loads a previously created decoding graph and prepares the recognizer for listening....
Definition KeenASR.cs:639
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 uttera...
Definition KeenASR.cs:570
@ Debug
Verbose output including internal processing details.

Member Function Documentation

◆ AdaptToSpeakerWithName()

void KeenResearch.KeenASR.AdaptToSpeakerWithName ( string  speakerName)
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.

Parameters
speakerNameA name or pseudonym identifying the speaker.

◆ CreateContextualDecodingGraphFromPhrases()

bool KeenResearch.KeenASR.CreateContextualDecodingGraphFromPhrases ( string  dgName,
string  contextualPhrases[][],
SpeakingTask  task = SpeakingTask::Default,
WordPronunciation[]  alternativePronunciations = null,
float  spokenNoiseProbability = 0::5f 
)
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).

Parameters
dgNameName for the decoding graph (used to reference it later).
contextualPhrasesArray of phrase arrays, where each inner array is a context. The index of each inner array becomes its contextId.
taskSpeaking task type (affects language model optimization).
alternativePronunciationsOptional array of alternative pronunciations for words in the phrases. Pass null if not needed.
spokenNoiseProbabilityProbability of <SPOKEN_NOISE> appearing in results (0.0–1.0, default 0.5).
Returns
true if the decoding graph was created successfully, false otherwise.

◆ CreateDecodingGraphFromPhrases()

bool KeenResearch.KeenASR.CreateDecodingGraphFromPhrases ( string  dgName,
string[]  phrases,
SpeakingTask  task = SpeakingTask::Default,
WordPronunciation[]  alternativePronunciations = null,
float  spokenNoiseProbability = 0::5f 
)
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.

Parameters
dgNameName for the decoding graph (used to reference it later).
phrasesArray of phrases the user is likely to say.
taskSpeaking task type (affects language model optimization).
alternativePronunciationsOptional array of alternative pronunciations for words in the phrases. Pass null if not needed.
spokenNoiseProbabilityProbability of <SPOKEN_NOISE> appearing in results (0.0–1.0, default 0.5). Lower values reduce its frequency; higher values increase it.
Returns
true if the decoding graph was created successfully, false otherwise.

◆ DecodingGraphWithNameExists()

bool KeenResearch.KeenASR.DecodingGraphWithNameExists ( string  dgName)
inline

Checks whether a decoding graph with the given name exists on the device.

Parameters
dgNameName of the decoding graph.
Returns
true if the decoding graph exists, false otherwise.

◆ FinalASRResultHandler()

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.

Parameters
responseThe final recognition response. Caller must dispose.

◆ GetRecognizerState()

RecognizerState KeenResearch.KeenASR.GetRecognizerState ( )
inline

Returns the current state of the recognizer.

Returns
The current RecognizerState.

◆ Initialize()

static bool KeenResearch.KeenASR.Initialize ( string  bundleName)
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.

Parameters
bundleNameName of the ASR bundle directory in StreamingAssets (e.g. "keenA1m-nnet3chain-en-us").
Returns
true if initialization was started successfully, false if already initialized.

◆ InitializedHandler()

delegate void KeenResearch.KeenASR.InitializedHandler ( bool  status)

Called when the ASR engine has finished initializing.

Parameters
statustrue if initialization succeeded, false otherwise.

◆ InitializeWithASRBundleAtPath()

static bool KeenResearch.KeenASR.InitializeWithASRBundleAtPath ( string  asrBundlePath)
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.

Parameters
asrBundlePathFull filesystem path to the ASR bundle directory.
Returns
true if initialization was started successfully, false if already initialized.

◆ InputLevel()

float KeenResearch.KeenASR.InputLevel ( )
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.

Returns
Input signal level in decibels.

◆ IsEchoCancellationAvaialable()

bool KeenResearch.KeenASR.IsEchoCancellationAvaialable ( )
inline

Checks whether the device supports echo cancellation.

Returns
true if echo cancellation is available, false otherwise.

◆ PartialASRResultHandler()

delegate void KeenResearch.KeenASR.PartialASRResultHandler ( string  text)

Called during recognition with intermediate (non-final) text.

Parameters
textThe partial recognition text so far.

◆ PauseUploader()

static void KeenResearch.KeenASR.PauseUploader ( )
inlinestatic

Pauses the data uploader. Queued files are retained and will be uploaded when the uploader is resumed.

◆ PerformEchoCancellation()

void KeenResearch.KeenASR.PerformEchoCancellation ( bool  value)
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.

Parameters
valuetrue to enable echo cancellation, false to disable.

◆ PrepareForListeningWithContextualDecodingGraph()

bool KeenResearch.KeenASR.PrepareForListeningWithContextualDecodingGraph ( string  dgName,
int  contextId,
bool  computeGoP = false 
)
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.

Parameters
dgNameName of a contextual decoding graph.
contextIdIndex of the context to use (corresponds to the index in the contextualPhrases array used during creation).
computeGoPIf true, compute goodness of pronunciation scores at the phoneme level in the final result.
Returns
true if successful, false otherwise.

◆ PrepareForListeningWithContextualDecodingGraphAtPath()

bool KeenResearch.KeenASR.PrepareForListeningWithContextualDecodingGraphAtPath ( string  path,
int  contextId,
bool  computeGoP = false 
)
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.

Parameters
pathFull filesystem path to the contextual decoding graph directory.
contextIdIndex of the context to use.
computeGoPIf true, compute goodness of pronunciation scores at the phoneme level in the final result.
Returns
true if successful, false otherwise.

◆ PrepareForListeningWithDecodingGraph()

bool KeenResearch.KeenASR.PrepareForListeningWithDecodingGraph ( string  dgName,
bool  computeGoP = false 
)
inline

Loads a previously created decoding graph and prepares the recognizer for listening. After this call succeeds, the recognizer state transitions to ReadyToListen.

Parameters
dgNameName of a decoding graph created with CreateDecodingGraphFromPhrases.
computeGoPIf true, compute goodness of pronunciation scores at the phoneme level in the final result.
Returns
true if successful, false otherwise.

◆ PrepareForListeningWithDecodingGraphAtPath()

bool KeenResearch.KeenASR.PrepareForListeningWithDecodingGraphAtPath ( string  path,
bool  computeGoP = false 
)
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.

Parameters
pathFull filesystem path to the decoding graph directory.
computeGoPIf true, compute goodness of pronunciation scores at the phoneme level in the final result.
Returns
true if successful, false otherwise.

◆ RecognizerReadyToListenAfterInterruptHandler()

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.

◆ RemoveAllSpeakerAdaptationProfiles()

bool KeenResearch.KeenASR.RemoveAllSpeakerAdaptationProfiles ( )
inline

Removes all saved speaker adaptation profiles from the device.

Returns
true if all profiles were removed, false otherwise.

◆ RemoveSpeakerAdaptationProfiles()

bool KeenResearch.KeenASR.RemoveSpeakerAdaptationProfiles ( string  speakerName)
inline

Removes the saved adaptation profile for the specified speaker.

Parameters
speakerNameName of the speaker whose profile should be removed.
Returns
true if the profile was removed, false otherwise.

◆ ResetSpeakerAdaptation()

void KeenResearch.KeenASR.ResetSpeakerAdaptation ( )
inline

Resets speaker adaptation to the baseline model, discarding any in-session adaptation data. Does not remove saved adaptation profiles.

◆ ResumeUploader()

static bool KeenResearch.KeenASR.ResumeUploader ( )
inlinestatic

Resumes the data uploader after it has been paused.

Returns
true if the uploader was resumed successfully, false otherwise.

◆ SaveSpeakerAdaptationProfile()

void KeenResearch.KeenASR.SaveSpeakerAdaptationProfile ( )
inline

Persists the current speaker adaptation profile so it can be reused in future sessions when AdaptToSpeakerWithName is called with the same name.

◆ SetLogLevel()

static void KeenResearch.KeenASR.SetLogLevel ( LogLevel  logLevel)
inlinestatic

Sets the framework logging verbosity. Can be called before Initialize().

Parameters
logLevelThe desired log level.

◆ SetVADParameter()

bool KeenResearch.KeenASR.SetVADParameter ( VadParameter  vadParameter,
float  value 
)
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).

Parameters
vadParameterThe VAD parameter to set.
valueTimeout value in seconds.
Returns
true if the parameter was set successfully, false otherwise.

◆ StartDataUploader()

static bool KeenResearch.KeenASR.StartDataUploader ( string  appKey)
inlinestatic

Starts a background uploader thread that uploads queued responses to Dashboard. Call this once during setup; responses are queued via ASRResponse.QueueForUpload().

Parameters
appKeyThe APP_KEY for your app as shown in Dashboard.
Returns
true if the uploader was started successfully, false otherwise.

◆ StartListening()

bool KeenResearch.KeenASR.StartListening ( )
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.

Returns
true if listening was started successfully, false otherwise.

◆ StopListening()

void KeenResearch.KeenASR.StopListening ( )
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.

◆ StopUploader()

static bool KeenResearch.KeenASR.StopUploader ( )
inlinestatic

Stops the data uploader thread. After stopping, StartDataUploader() must be called again to resume uploads.

Returns
true if the uploader was stopped successfully, false otherwise.

◆ Teardown()

static bool KeenResearch.KeenASR.Teardown ( )
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.

Returns
true if teardown succeeded, false if the SDK was not initialized.

◆ UnwindAppAudioBeforeAudioInterruptHandler()

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.

Property Documentation

◆ Instance

KeenASR KeenResearch.KeenASR.Instance
staticget

Gets the shared KeenASR instance. Returns null if the SDK has not been initialized.

Event Documentation

◆ onFinalResponseReceived

FinalASRResultHandler KeenResearch.KeenASR.onFinalResponseReceived

Raised when recognition is complete with the final response. The handler receives an ASRResponse that it must dispose when done.

◆ onInitializedReceived

InitializedHandler KeenResearch.KeenASR.onInitializedReceived
static

Raised when the ASR engine has finished initializing. Subscribe to this event before calling Initialize().

◆ onPartialASRResultReceived

PartialASRResultHandler KeenResearch.KeenASR.onPartialASRResultReceived

Raised during recognition with intermediate (non-final) text as it becomes available.

◆ onRecognizerReadyToListenAfterInterruptReceived

RecognizerReadyToListenAfterInterruptHandler KeenResearch.KeenASR.onRecognizerReadyToListenAfterInterruptReceived

Raised when the recognizer is ready to listen again after an audio interrupt.

◆ onUnwindAppAudioBeforeAudioInterruptReceived

UnwindAppAudioBeforeAudioInterruptHandler KeenResearch.KeenASR.onUnwindAppAudioBeforeAudioInterruptReceived

Raised immediately before KeenASR unwinds its audio stack due to an audio interrupt. See UnwindAppAudioBeforeAudioInterruptHandler for details.