KeenASR Framework v2.1 (8b72cc4)
Keen Research
Loading...
Searching...
No Matches
KIOSDecodingGraph Class Reference

#include <KIOSDecodingGraph.h>

Class Methods

Regular Decoding Graphs
(BOOL) + createDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:
(BOOL) + createDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:withSpokenNoiseProbability:andSaveWithName:
Contextual Decoding Graphs
(BOOL) + createContextualDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:
(BOOL) + createContextualDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:withSpokenNoiseProbability:andSaveWithName:
(BOOL) + createDecodingGraphFromPhrases:withTriggerPhrase:forRecognizer:andSaveWithName:
Helper methods
(BOOL) + decodingGraphWithNameExists:forRecognizer:
(BOOL) + decodingGraphAtPathExists:
(BOOL) + decodingGraphExistsAtPath:
(nullable NSDate *) + decodingGraphCreationDate:forRecognizer:
(nullable NSURL *) + getDecodingGraphDirURL:forRecognizer:
Deprecated Methods
(BOOL) + createDecodingGraphFromSentences:forRecognizer:andSaveWithName:
(BOOL) + createContextualDecodingGraphFromSentences:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:
(BOOL) + createDecodingGraphFromSentences:withTriggerPhrase:forRecognizer:andSaveWithName:
(BOOL) + createDecodingGraphFromSentences:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:

Detailed Description

KIOSDecodingGraph class manages decoding graphs in the filesystem.

You can use various KIOSDecodingGraph class methods to create decoding graphs, which will be saved in the filesystem on the device. Typically, you will provide a list of phrases to createDecodingGraphFromPhrases:forRecognizer:andSaveWithName: method, which will then create a decoding graph in the filesystem. Later on, you can refer to the decoding graph by its name.

Contextual graphs are a composition of multiple decoding graphs in a single graph. If your application needs to create multiple decoding graphs often it may be more efficient to create a single contextual decoding graph instead and then switch the contexts as needed. A good example would be a digital book; each page presented to the user would be a single context and you would switch contexts as the app (or user) changes the pages. The trade-offs with contextual graphs is that creating one with N contexts will be much faster than creation of a single graph N times; the downside is that there will be a small penalty (delay of 100ms or so) when switching between different contexts.

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 langauge algorithmic representation is imperfect, thus you should aim to use KIOSAlternative prounciations to augment the lexicon with 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.
For the large number of phrases (e.g. several thousands), creating of decoding graph can take several seconds on older devices.
Decoding graphs can also be created ahead of time and packaged with the application.

Method Documentation

◆ createContextualDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:

+ (BOOL) createContextualDecodingGraphFromPhrases: (nonnull NSArray< NSArray * > *) contextualPhrases
forRecognizer: (nonnull KIOSRecognizer *) recognizer
usingAlternativePronunciations: (nullable NSArray< KIOSWordPronunciation * > *) alternativePronunciations
andTask: (KIOSSpeakingTask) task
andSaveWithName: (nonnull NSString *) decodingGraphName 

Create custom decoding graph from an array of arrays of phrases and save it in the filesystem for later use. Each top-level array represents a context, which you can then set using prepareForListening before calling startListening.

For example, you could build a decoding graph with the following contextualPhrases parameter: @[ @[ // contextId 0 "This is a first phrase.", @"This first phrase belongs to the first contextual group ], @[ // contextId 1 "This is another phrase.", @"This phrase belongs to the second contextual group ] ];

Custom decoding graphs can be referenced by their name by various methods in the framework.

Decoding graphs created with this method require call to prepareForListeningWithContextId

Parameters
contextualPhrasesan NSArray of NSArrays with NSString objects that specify phrases grouped by specific context. These phrases are used to create a language model, from which decoding graph is created. Text in phrases should be normalized (e.g. numbers and dates should be represented by words, so 'two hundred dollars' not $200)
recognizerKIOSRecognizer 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 KIOSRecognizer object as long as such recognizer uses the same ASR bundle as the KIOSRecognizer object used to create the decoding graph.
alternativePronunciationsan optional NSArray of KIOSWordPronunciation objects specifying alternative pronunciations that should be used when building this decoding graph.
taskKIOSSpeakingTask specyfing the type of task this decoding graph corresponds to. Calling this method with KIOSSpeakingTaskDefault is equivalent to calling createDecodingGraphFromPhrases:forRecognizer:andSaveWithName method.
decodingGraphNamea name of the custom decoding graph. All graph resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in Library/Application Support/KaldiIOS-decoding-graphs/
Returns
TRUE on success, FALSE otherwise

◆ createContextualDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:withSpokenNoiseProbability:andSaveWithName:

+ (BOOL) createContextualDecodingGraphFromPhrases: (nonnull NSArray< NSArray * > *) contextualPhrases
forRecognizer: (nonnull KIOSRecognizer *) recognizer
usingAlternativePronunciations: (nullable NSArray< KIOSWordPronunciation * > *) alternativePronunciations
andTask: (KIOSSpeakingTask) task
withSpokenNoiseProbability: (float) spokenNoiseProbability
andSaveWithName: (nonnull NSString *) decodingGraphName 

Create custom decoding graph from an array of arrays of phrases and save it in the filesystem for later use. Each top-level array represents a context, which you can then set using prepareForListening before calling startListening.

For example, you could build a decoding graph with the following contextualPhrases parameter: @[ @[ // contextId 0 "This is a first phrase.", @"This first phrase belongs to the first contextual group ], @[ // contextId 1 "This is another phrase.", @"This phrase belongs to the second contextual group ] ];

Custom decoding graphs can be referenced by their name by various methods in the framework.

Decoding graphs created with this method require call to prepareForListeningWithContextId

Parameters
contextualPhrasesan NSArray of NSArrays with NSString objects that specify phrases grouped by specific context. These phrases are used to create a language model, from which decoding graph is created. Text in phrases should be normalized (e.g. numbers and dates should be represented by words, so 'two hundred dollars' not $200)
recognizerKIOSRecognizer 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 KIOSRecognizer object as long as such recognizer uses the same ASR bundle as the KIOSRecognizer object used to create the decoding graph.
alternativePronunciationsan optional NSArray of KIOSWordPronunciation objects specifying alternative pronunciations that should be used when building this decoding graph.
taskKIOSSpeakingTask specyfing the type of task this decoding graph corresponds to. Calling this method with KIOSSpeakingTaskDefault is equivalent to calling createDecodingGraphFromPhrases:forRecognizer:andSaveWithName method.
spokenNoiseProbabilitya float value in the range 0.0 - 1.0. Default value is 0.5. Lower values will make <SPOKEN_NOISE> occur less frequently in the result, whereas higher values will make it more likely to occur in the result.
decodingGraphNamea name of the custom decoding graph. All graph resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in Library/Application Support/KaldiIOS-decoding-graphs/
Returns
TRUE on success, FALSE otherwise

◆ createDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:andSaveWithName:

+ (BOOL) createDecodingGraphFromPhrases: (nonnull NSArray *) phrases
forRecognizer: (nonnull KIOSRecognizer *) recognizer
usingAlternativePronunciations: (nullable NSArray< KIOSWordPronunciation * > *) alternativePronunciations
andTask: (KIOSSpeakingTask) task
andSaveWithName: (nonnull NSString *) decodingGraphName 

Create decoding graph from an array of phrases and save it in the filesystem for later use. Decoding graphs can be referenced by their name by various methods in the framework.

Parameters
phrasesan NSArray of NSString objects that specify phrases recognizer should listen for. These phrases are used to create a language model, from which decoding graph is created. Text in phrases should be normalized (e.g. numbers and dates should be represented by words, so 'two hundred dollars' not $200).
recognizerKIOSRecognizer 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 KIOSRecognizer object as long as such recognizer uses the same ASR bundle as the KIOSRecognizer object used to create the decoding graph.
alternativePronunciationsan NSArray of KIOSWordPronunciation objects specifying alternative pronunciations that should be used when building this decoding graph.
taskKIOSSpeakingTask specyfing the type of task this decoding graph corresponds to. Calling this method with KIOSSpeakingTaskDefault is equivalent to calling createDecodingGraphFromSentences:forRecognizer:andSaveWithName method.
decodingGraphNamea name of the custom decoding graph. All graph resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in Library/Application Support/KaldiIOS-decoding-graphs/
Returns
TRUE on success, FALSE otherwise

◆ createDecodingGraphFromPhrases:forRecognizer:usingAlternativePronunciations:andTask:withSpokenNoiseProbability:andSaveWithName:

+ (BOOL) createDecodingGraphFromPhrases: (nonnull NSArray *) phrases
forRecognizer: (nonnull KIOSRecognizer *) recognizer
usingAlternativePronunciations: (nullable NSArray< KIOSWordPronunciation * > *) alternativePronunciations
andTask: (KIOSSpeakingTask) task
withSpokenNoiseProbability: (float) spokenNoiseProbability
andSaveWithName: (nonnull NSString *) decodingGraphName 

Create decoding graph from an array of phrases and save it in the filesystem for later use. Decoding graphs can be referenced by their name by various methods in the framework.

Parameters
phrasesan NSArray of NSString objects that specify phrases recognizer should listen for. These phrases are used to create a language model, from which decoding graph is created. Text in phrases should be normalized (e.g. numbers and dates should be represented by words, so 'two hundred dollars' not $200).
recognizerKIOSRecognizer 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 KIOSRecognizer object as long as such recognizer uses the same ASR bundle as the KIOSRecognizer object used to create the decoding graph.
alternativePronunciationsan NSArray of KIOSWordPronunciation objects specifying alternative pronunciations that should be used when building this decoding graph.
taskKIOSSpeakingTask specyfing the type of task this decoding graph corresponds to. Calling this method with KIOSSpeakingTaskDefault is equivalent to calling createDecodingGraphFromSentences:forRecognizer:andSaveWithName method.
spokenNoiseProbabilitya float value in the range 0.0 - 1.0. Default value is 0.5. Lower values will make <SPOKEN_NOISE> occur less frequently in the result, whereas higher values will make it more likely to occur in the result.
decodingGraphNamea name of the custom decoding graph. All graph resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in Library/Application Support/KaldiIOS-decoding-graphs/
Returns
TRUE on success, FALSE otherwise

◆ createDecodingGraphFromPhrases:withTriggerPhrase:forRecognizer:andSaveWithName:

+ (BOOL) createDecodingGraphFromPhrases: (nonnull NSArray *) phrases
withTriggerPhrase: (nonnull NSString *) triggerPhrase
forRecognizer: (nonnull KIOSRecognizer *) recognizer
andSaveWithName: (nonnull NSString *) decodingGraphName 

Create decoding graph setup for trigger phrase, using an array of phrases and save it in the filesystem for later use. Decoding graphs can be referenced by their name by various methods in the framework.

Parameters
phrasesan NSArray of NSString objects that specify phrases recognizer should listen for. These phrases are used to create a language model, from which decoding graph is created. Text in phrases should be normalized (e.g. numbers and dates should be represented by words, so 'two hundred dollars' not $200).
triggerPhraseNSString object that defines trigger phrase which will be used when building this decoding graphs. When using graphs built with trigger phrase support, recognizer will not report any results until it recognizes the trigger phrase. If you are using trigger phrase graphs, you can also setup a [KIOSRecognizer
recognizerKIOSRecognizer 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 KIOSRecognizer object as long as such recognizer uses the same ASR bundle as the KIOSRecognizer object used to create the decoding graph.
decodingGraphNamea name of the custom decoding graph. All graph resources will be stored in a directy named DECODING_GRAPH_NAME-ASR_BUNDLE_NAME in Library/Application Support/KaldiIOS-decoding-graphs/
Returns
TRUE on success, FALSE otherwise

◆ decodingGraphAtPathExists:

+ (BOOL) decodingGraphAtPathExists: (nonnull NSString *) absolutePathToDecodingGraphDirectory

Returns TRUE if a valid decoding graph exists at the given absolute filepath.

Parameters
absolutePathToDecodingGraphDirectoryabsolute path to the decoding graph directory.
Returns
TRUE if decoding graph with such name exists, FALSE otherwise. This method will also check for existance of all the necessary files in the decoding graph directory.

◆ decodingGraphCreationDate:forRecognizer:

+ (nullable NSDate *) decodingGraphCreationDate: (nonnull NSString *) decodingGraphName
forRecognizer: (nonnull KIOSRecognizer *) recognizer 

Returns date when custom decoding graph was created.

Parameters
decodingGraphNamename of the decoding graph
recognizerKIOSRecognizer object equivalent to the KIOSRecognizer object that was used to create the decoding graph.
Returns
date when decoding graph was created and saved in the filesystem. nil if not available.

◆ decodingGraphExistsAtPath:

+ (BOOL) decodingGraphExistsAtPath: ("Please use decodingGraphAtPathExists method") __deprecated_msg

Returns TRUE if a valid decoding graph exists at the given absolute filepath.

Parameters
absolutePathToDecodingGraphDirectoryabsolute path to the decoding graph directory.
Returns
TRUE if decoding graph with such name exists, FALSE otherwise. This method will also check for existance of all the necessary files in the decoding graph directory.

◆ decodingGraphWithNameExists:forRecognizer:

+ (BOOL) decodingGraphWithNameExists: (nonnull NSString *) decodingGraphName
forRecognizer: (nonnull KIOSRecognizer *) recognizer 

Returns TRUE if valid custom decoding graph with the given name exists in the filesystem.

Parameters
decodingGraphNamename of the custom decoding graph
recognizerKIOSRecognizer object equivalent to the KIOSRecognizer object that was used to create the decoding graph.
Returns
TRUE if decoding graph with such name exists, FALSE otherwise. This method will also check for existance of all the necessary files in the decoding graph directory.

◆ getDecodingGraphDirURL:forRecognizer:

+ (nullable NSURL *) getDecodingGraphDirURL: (nonnull NSString *) decodingGraphName
forRecognizer: (nonnull KIOSRecognizer *) recognizer 

Returns NSURL object that specifies directory where decoding graph is stored.

Parameters
decodingGraphNamename of the decoding graph #param recognizer KIOSRecognizer object equivalent to the KIOSRecognizer object that was used to create the decoding graph.
Returns
NSURL object where the decoding graph was or should have been stored.

The documentation for this class was generated from the following file: