public class KASRDecodingGraph
extends java.lang.Object
For ASR tasks in which domain and vocabulary are defined ahead of time and not dependent on information available only during the runtime, it is recommended that decoding graph is created offline and packaged in the ASR bundle directory.
If user specific information is necessary to create decoding graphs, you can use
various KASRDecodingGraph class methods to dynamically create decoding graphs,
which will be saved in the filesystem on the device. Typically, you will
provide a list of sentences/phrases to createDecodingGraphFromSentences(String[], KASRRecognizer, String)
method, which will then create a custom decoding graph. Later on, you can refer
to the custom decoding graph by its name. Alternatively, instead of list of
sentences/phrases you can provide an ARPA language model (bundled with your app),
which will be used to build a custom decoding graph.
If your app needs to support continuous listening with trigger phrase support you will need to
build the decoding graph using createDecodingGraphFromSentencesWithTriggerPhrase(String[], String, KASRRecognizer, String)
method.
Decoding graphs can only be built dynamically if the lang/ subdirectory in the ASR bundle exists.
Note: When dynamically creating decoding graphs, any words that do not have phonetic representation in the lexicon (ASRBUNDLE/lang/lexicon.txt) will be assigned one algorithmically. For English language algorithmic representation is imperfect, thus you should aim to manually augment the lexicon text file with pronunciations for as many additional words that are likely to be encountered in your app. For example, if your app is dealing with ASR of names you would augment the lexicon with additional names and their proper pronunciation before releasing your app.In the current version of the framework, creating of decoding graph can take on the order of 10-30sec for medium size vocabulary task (more than thousand words). For larger language models we recommend you create decoding graph ahead of time and bundle it with your app.
Constructor and Description |
---|
KASRDecodingGraph() |
Modifier and Type | Method and Description |
---|---|
static boolean |
createDecodingGraphFromSentences(java.lang.String[] sentences,
KASRRecognizer recognizer,
java.lang.String dgName)
Create custom decoding graph from an array of sentences/phrases and save it
in the filesystem under for later use.
|
static boolean |
createDecodingGraphFromSentencesWithTriggerPhrase(java.lang.String[] sentences,
java.lang.String triggerPhrase,
KASRRecognizer recognizer,
java.lang.String dgName)
Create custom decoding graph from an array of sentences/phrases, using specified triggerPhase,
and save it in the filesystem under for later use.
|
static boolean |
decodingGraphExistsAtPath(java.lang.String dgPath)
Returns TRUE if a valid decoding graph exists at the given absolute filepath.
|
static boolean |
decodingGraphWithNameExists(java.lang.String dgName,
KASRRecognizer recognizer)
Returns TRUE if valid custom decoding graph with the given name exists in
the filesystem
|
static java.util.Date |
getDecodingGraphCreationDate(java.lang.String dgName,
KASRRecognizer recognizer)
Returns date when custom decoding graph was created.
|
public static boolean createDecodingGraphFromSentences(java.lang.String[] sentences, KASRRecognizer recognizer, java.lang.String dgName)
sentences
- an array of String objects that specify sentences/phrases
recognizer should listen for. These sentences are used to create an ngram
language model, from which decoding graph is created. Text in sentences should
be normalized (e.g. numbers and dates should be represented by words, so
'two hundred dollars' not $200)recognizer
- KASRRecognizer
object that will be used to perform recognition
with this decoding graph. Note that decoding graph is persisted in the filesystem
and can be resued at the later time with a different KASRRecognizer object as
long as such recognizer uses the same ASR bundle as the KASRRecognizer object
used to create the decoding graph.dgName
- a name of the custom decoding graph. All graph
resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME
in context.getApplicationInfo().dataDir + " + dgName + "-" + asrBundleNamepublic static boolean createDecodingGraphFromSentencesWithTriggerPhrase(java.lang.String[] sentences, java.lang.String triggerPhrase, KASRRecognizer recognizer, java.lang.String dgName)
sentences
- an array of String objects that specify sentences/phrases recognizer
should listen for. These sentences are used to create an ngram language
model, from which decoding graph is created. Text in sentences should be
normalized (e.g. numbers and dates should be represented by words, so
'two hundred dollars' not $200)triggerPhrase
- a String representing a trigger phrase used to initiate recognition
when using this decoding graph, for example "Hey computer". When using
decoding graph with trigger phrase, recognizer will continuously listen
until it hears the trigger phrase. No partial callback results will be
provided until trigger phrase is recognized.recognizer
- KASRRecognizer
object that will be used to perform recognition
with this decoding graph. Note that decoding graph
is persisted in the filesystem and can be reused
at the later time with a different KASRRecognizer
object as long as such recognizer uses the same
ASR bundle as the KASRRecognizer object used to
create the decoding graph.dgName
- a name of the custom decoding graph. All graph resources will be stored in a
directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in
context.getApplicationInfo().dataDir + dgName + "-" + asrBundleNamepublic static boolean decodingGraphWithNameExists(java.lang.String dgName, KASRRecognizer recognizer)
dgName
- name of the custom decoding graphrecognizer
- KASRRecognizer object equivalent to the KASRRecognizer object
that was used to create the decoding graph.public static boolean decodingGraphExistsAtPath(java.lang.String dgPath)
dgPath
- absolute path to the decoding graph directory.public static java.util.Date getDecodingGraphCreationDate(java.lang.String dgName, KASRRecognizer recognizer)
dgName
- name of the decodingGraphrecognizer
- KIOSRecognizer object equivalent to the KIOSRecognizer object
that was used to create the decoding graph (initialized with the same ASR Bundle).