public class KASRRecognizer
extends java.lang.Object
You typically initialize the engine at the app startup time by calling
initWithASRBundleAtPath(String, Context)
method, and
then use sharedInstance()
static method when you need to access the
recognizer.
Recognition results are provided via callbacks. To obtain results one of your
classes will need to adopt a KASRRecognizerListener
interface and implement some
of its methods.
Note: Only a single instance of the recognizer can exist at any given time.
Modifier and Type | Class and Description |
---|---|
static class |
KASRRecognizer.KASRRecognizerLogLevel
These constants indicate the log levels for the framework.
|
static class |
KASRRecognizer.KASRRecognizerState
These constants indicate different states recognizer can assume.
|
static class |
KASRRecognizer.KASRVadParameter
These constants correspond to different Voice Activity Detection parameters
that are used for endpointing during recognition.
|
Modifier and Type | Method and Description |
---|---|
void |
adaptToSpeakerWithName(java.lang.String speakerName)
Defines the name that will be used to uniquely identify speaker adaptation
profile.
|
void |
addListener(KASRRecognizerListener listener)
Adds listener.
|
void |
addTriggerPhraseListener(KASRRecognizerTriggerPhraseListener listener)
Adds trigger phrase listener.
|
protected android.content.Context |
getAppContext()
Returns application context that was used to initialized this instance of KASRRecognizer
|
java.lang.String |
getASRBundleName()
Obtains a name of the ASR Bundle used to initialize the SDK.
|
java.lang.String |
getAsrBundlePath()
Obtains a path to the directory where ASR Bundle used to initialize the SDK is stored
|
java.lang.Boolean |
getCreateAudioRecordings()
Provides ways to check if SDK is setup to store audio recordings in the filesystem.
|
java.lang.String |
getDecodingGraphName()
Returns name of the decoding graph that's used for recognition.
|
float |
getInputLevel()
The most recent signal input level in dB
|
java.lang.String |
getLastRecordingFilename()
Returns a full path to the last recorded audio file.
|
KASRRecognizer.KASRRecognizerState |
getRecognizerState()
Returns recognizer state, one of KASRRecognizerState values
|
KASRRecognizer.KASRRecognizerState |
GetRecognizerState()
Deprecated.
Use getRecognizerState instead
|
java.lang.String |
getRecordingsDir()
Returns a full path to the directory where audio recordings are being stored.
|
java.lang.Boolean |
getRescore()
Value of the rescoring flag
|
static boolean |
initWithASRBundleAtPath(java.lang.String pathToASRBundle,
android.content.Context context)
Initialize ASR engine with the ASR Bundle located at the provided path.
|
boolean |
isEchoCancellationAvailable() |
boolean |
performEchoCancellation(boolean value)
EXPERIMENTAL Specifies if echo cancellation should be performed.
|
boolean |
prepareForListeningWithCustomDecodingGraphAtPath(java.lang.String pathToDecodingGraphDirectory)
Prepare for recognition by loading custom decoding graph that was bundled
with the application.
|
boolean |
prepareForListeningWithCustomDecodingGraphWithName(java.lang.String dgName)
Prepare for recognition by loading custom decoding graph that was prepared
via
KASRDecodingGraph.createDecodingGraphFromSentences(String[], KASRRecognizer, String)
method or KASRDecodingGraph.createDecodingGraphFromSentencesWithTriggerPhrase(String[], String, KASRRecognizer, String)
method. |
boolean |
removeAllSpeakerAdaptationProfiles()
Remove all adaptation profiles for all speakers.
|
void |
removeListener(KASRRecognizerListener listener)
Removes listener.
|
boolean |
removeSpeakerAdaptationProfiles(java.lang.String speakerName)
Removes all adaptation profiles for the speaker with name speakerName.
|
void |
removeTriggerPhraseListener(KASRRecognizerTriggerPhraseListener listener)
Removes trigger phrase listener.
|
void |
resetSpeakerAdaptation()
Resets speaker adaptation profile in the current recognizer session.
|
void |
saveSpeakerAdaptation()
Saves speaker profile (used for adaptation) in the filesystem.
|
void |
setCreateAudioRecordings(java.lang.Boolean value)
Determines if the SDK should store the audio that it processes between start and stop
listening into an audio file.
|
static void |
setLogLevel(KASRRecognizer.KASRRecognizerLogLevel logLevel)
Set log level for the framework.
|
void |
setRescore(java.lang.Boolean value)
If set to true, recognizer will perform rescoring for the final result, using
rescoring language model provided in the custom decoding graph that's bundled
with the application.
|
void |
setVADParameter(KASRRecognizer.KASRVadParameter parameter,
float value)
Set any of
KASRRecognizer.KASRVadParameter Voice Activity Detection parameters. |
static KASRRecognizer |
sharedInstance() |
boolean |
startListening()
Start processing incoming audio.
|
void |
stopListening()
Stop the recognizer from processing incoming audio.
|
KASRResult |
stopListeningAndReturnFinalResult()
Stop the recognizer from processing incoming audio and return the final result.
|
java.lang.String |
version()
Version of the KeenASR framework.
|
public static KASRRecognizer sharedInstance()
public static boolean initWithASRBundleAtPath(java.lang.String pathToASRBundle, android.content.Context context)
pathToASRBundle
- full path to the ASR Bundlecontext
- application contextNote: When initializing the recognizer, make sure that the bundle directory contains all the necessary resources needed for the specific recognizer type. If your app is dynamically creating decoding graphs, ASR bundle directory needs to contain lang subdirectory with the relevant resources (lexicon, etc.).
public boolean prepareForListeningWithCustomDecodingGraphWithName(java.lang.String dgName)
KASRDecodingGraph.createDecodingGraphFromSentences(String[], KASRRecognizer, String)
method or KASRDecodingGraph.createDecodingGraphFromSentencesWithTriggerPhrase(String[], String, KASRRecognizer, String)
method. Calls to this method will be ignored if the recognizer is listening.
After calling this method, recognizer will load the decoding graph into memory and it will be ready to start listening via startListening method.
dgName
- name of the custom decoding graphpublic boolean prepareForListeningWithCustomDecodingGraphAtPath(java.lang.String pathToDecodingGraphDirectory)
After calling this method, recognizer will load the decoding graph into memory and it will be ready to start listening via startListening method.
pathToDecodingGraphDirectory
- absolute path to the custom decoding graph
directory which was created ahead of time and packaged with the app.Note: If custom decoding graph was built with rescoring capability, all the resources will be loaded regardless of how rescore paramater is set.
public void setRescore(java.lang.Boolean value)
Default is true.
Note: If the resources necessary for rescoring are not available in the custom decoding graph directory bundled with the app, and rescore is set to true, rescoring step will be skipped.
value
- boolean value that determines if rescoring is to be performedpublic java.lang.Boolean getRescore()
public boolean startListening()
After calling this method, recognizer will listen to and decode audio coming through the microphone using decoding graph you specified via one of the prepareForListening methods. For decoding graphs created without trigger phrase support listening process will stop either due to: a) an explicit call to stopListening or b) if one of the Voice Activity Detection rules are triggered (for example, max duration without speech, or end-silence, etc.). We recommend using VAD based end-pointing instead of explicitly calling stopListening
If decoding graph was created with the triggerPhrase support the SDK will listen continuously until the trigger phrase is recognized, then it will switch over to the standard mode with partial results being reported via onPartialResult callback.
When the recognizer stops listening due to VAD triggering, it will call
KASRRecognizerListener.onFinalResult(KASRRecognizer, KASRResult)
callback method.
When the recognizer stops listening due to audio interrupt, *no callback methods* will be triggered until audio interrupt is over.
VAD settings can be modified via setVADParameter(KASRVadParameter, float)
method.
prepareForListeningWithCustomDecodingGraphWithName(String)
or prepareForListeningWithCustomDecodingGraphAtPath(String)
before calling this method.
You will also need to make sure that user has granted audio recording permission
before calling this method; see android.support.v4.app.ActivityCompat#requestPermissions for details.public void stopListening()
Note: Calling this method will not trigger recognizerFinalResult delegate call.
public KASRResult stopListeningAndReturnFinalResult()
If your application is using Voice Activity Detection parameters, it possible that this method doesn't return the result if one of the Voice Activity Detection thresholds triggers. In that case, recognizerFinalResult delegate will be called.
Note: This method runs synchronously. For large decoding graphs there may be noticeable delay (few hundred ms) on lower-end devices.
public KASRRecognizer.KASRRecognizerState GetRecognizerState()
public KASRRecognizer.KASRRecognizerState getRecognizerState()
public java.lang.String getDecodingGraphName()
public void addListener(KASRRecognizerListener listener)
listener
- listener that should be addedpublic void removeListener(KASRRecognizerListener listener)
listener
- listener to be removedpublic void addTriggerPhraseListener(KASRRecognizerTriggerPhraseListener listener)
listener
- listener that should be addedpublic void removeTriggerPhraseListener(KASRRecognizerTriggerPhraseListener listener)
listener
- listener to be removedpublic java.lang.String getAsrBundlePath()
public java.lang.String getASRBundleName()
public void setCreateAudioRecordings(java.lang.Boolean value)
value
- Boolean value, TRUE if recordings should be created, FALSE otherwisefor the full path of the last recorded file
public java.lang.Boolean getCreateAudioRecordings()
public java.lang.String getRecordingsDir()
public java.lang.String getLastRecordingFilename()
public void adaptToSpeakerWithName(java.lang.String speakerName)
speakerName
- (pseduo)name of the speaker for which adaptation is to be
performed. Default value is 'default'.
The name used here does not have to correspond to the real name of user (thus we call it pseudo name). The exact value does not matter as long as you can match the value to the specific user in your app. For example, you could use 'user1', 'user2', etc..
Note: If you cannot match names to your users, it's recommended to not use this method, and to not save adaptation profiles between sessions. Adaptation will still be performed throughout the session, but each new session (activity after initialization of recognizer) will start from the baseline models.
In-memory speaker adaptation profile can always be reset by calling resetSpeakerAdaptation method.
If this method is called while recognizer is listening, it will only affect subsequent calls to startListening methods.
public void resetSpeakerAdaptation()
public void saveSpeakerAdaptation()
public boolean removeAllSpeakerAdaptationProfiles()
public boolean removeSpeakerAdaptationProfiles(java.lang.String speakerName)
speakerName
- name of the speaker whose profiles should be removedpublic static void setLogLevel(KASRRecognizer.KASRRecognizerLogLevel logLevel)
logLevel
- one of KIOSRecognizerLogLevel
Default value is KIOSRecognizerLogLevelWarning.
public void setVADParameter(KASRRecognizer.KASRVadParameter parameter, float value)
KASRRecognizer.KASRVadParameter
Voice Activity Detection parameters. These
parameters can be set at any time and they will go into effect immediately.parameter
- one of KASRVadParametervalue
- duration in seconds for the parameter
Note: Setting VAD rules in the config file within the ASR bundle will NOT have any effect. Values for these parameters are set to their defaults upon initialization of KASRRecognizer. They can only be changed programmatically, using this method.
public float getInputLevel()
public boolean isEchoCancellationAvailable()
public boolean performEchoCancellation(boolean value)
value
- set to YES to turn on echo cancellation processing, NO to turn it
off. Default is NO.public java.lang.String version()
protected android.content.Context getAppContext()