Elements¶
-
class
SplitDictation
(name, registry=None, forced_dictation=False, **kwargs)[source]¶ A rule element used to split recognized dictation into an initial free dictation part, and a following command part. Either part is optional, unless the element is initialized with the forced_dictation element to True.
The following example shows this element being used and retrieved in the standard expected way.
from dragontide import RegistryRule, SplitDictation class SplitterRule(RegistryRule): spec = "set name <name_split>" extras = (SplitDictation("name_split"), ) def _process_recognition(self, node, extras): name_split = extras["name_split"] name = name_split.dictation
The result is a type of container from which parts of the result may be retrieved. The full list of attributes are individually documented below, but a simple naming scheme is in place. The first part of the attribute name indicates the part desired:
full - The entire utterance
dictation - The utterance only up to the first accepted command, may be the empty string if the utterance began with an accepted command
command - The rest of the utterance starting with the first accepted command, through the end of the utterance
The second part indicates the return type desired:
_words - A string list of the words
_container - The same type of dictation container that a Dictation element would yield, some derived class of BaseDictationContainer as appropriate for the speech recognition system in use.
default - If neither of the above are indicated, the default result type is a string.
The third part indicates whether literal tags should be retained or translated out:
_notrans - Retain the literal tags
_trans - Strip literal tags and return only the intended content
default - If neither of the above are indicated, the result will have the default behavior most common when using the part requested. full and command parts will retain literal tags, while dictation parts will strip them so as to only return the intended free speech. Default translation of the parts applies to all return types.
There is also an issue of formatting. The various dictation containers have a formatting option. For Windows Speech Recognition there is no real formatting provided beyond separating words with spaces. Dragon NaturallySpeaking provides more sophisticated formatting. All return types except for the _container values have formatting applied to the result returned. If you absolutely do not want the formatting applied, you must request the containers directly, from which you can choose to apply formatting or not. If you choose a _trans container, it will have had literal tags stripped, but otherwise be unmodified.
-
__init__
(name, registry=None, forced_dictation=False, **kwargs)[source]¶ - Parameters
name (string) – The name of this element, used as the keyname in the extras dictionary passed back to _process_recognition
registry (Registry) – The
Registry
instance that determines what words form a command and what literal tags are in effect. If None, theActiveGrammarRule
decorator will set the registry of anyRegistryGrammar
derived instance the containing rule is added to.forced_dictation (bool) – When True, refuses to recognize utterance-initial commands, so as to ensure this element returns non-empty free dictation.
kwargs – Passed safely to Dictation.__init__
-
value
(node)[source]¶ Determine the semantic value of this element given the recognition results stored in the node.
- Argument:
node – a
dragonfly.grammar.state.Node
instance representing this element within the recognition parse tree
The default behavior of this method is to return an iterable containing the recognized words matched by this element (i.e. node.words()).
-
property
command_index
¶ Returns the 0-based word index at which the first accepted full command intro occurs, or the index beyond last if no such intro occurs. If forced_dictation was set True during initialization, any utterance-initial command will be skipped to ensure dictation content is non-empty.
-
property
full
¶ Alias for
full_notrans
.
-
property
full_notrans
¶ Returns the full content, as a string, with formatting applied and with literal tags retained.
-
property
full_trans
¶ Returns the full content, as a string, with formatting applied and with literal tags translated to their intended result.
-
property
full_words
¶ Alias for
full_words_notrans
.
-
property
full_words_notrans
¶ Returns the full content, as a word list, with formatting applied and with literal tags retained.
-
property
full_words_trans
¶ Returns the full content, as a word list, with formatting applied and with literal tags translated to their intended result.
-
property
full_container
¶ Alias for
full_container_notrans
.
-
property
full_container_notrans
¶ Returns the full content, as a BaseDictationContainer of the appropriate type given the speech recognition system in use, without any alterations of any sort applied to the container contents.
-
property
full_container_trans
¶ Returns the full content, as a BaseDictationContainer of the appropriate type given the speech recognition system in use, with no formatting applied yet with literal tags translated to their intended result.
-
property
dictation
¶ Alias for
dictation_trans
.
-
property
dictation_trans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a string with formatting and with literal tags translated to their intended result.
-
property
dictation_notrans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a string with formatting and with literal tags retained.
-
property
dictation_words
¶ Alias for
dictation_words_trans
.
-
property
dictation_words_trans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a word list with formatting and with literal tags translated to their intended result.
-
property
dictation_words_notrans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a word list with formatting and with literal tags retained.
-
property
dictation_container
¶ Alias for
dictation_container_trans
.
-
property
dictation_container_notrans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a BaseDictationContainer of the appropriate type given the speech recognition system in use, without any alterations of any sort applied to the container contents.
-
property
dictation_container_trans
¶ Returns any and all content up to the first full command intro, if any. Content is returned as a BaseDictationContainer of the appropriate type given the speech recognition system in use, with no formatting applied yet with literal tags translated to their intended result.
-
property
command
¶ Alias for
command_notrans
-
property
command_notrans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a string with formatting and with literal tags retained.
-
property
command_trans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a string with formatting and with literal tags retained.
-
property
command_words
¶ Alias for
command_words_notrans
-
property
command_words_notrans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a word list with formatting and with literal tags retained.
-
property
command_words_trans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a word list with formatting and with literal tags translated to their intended result.
-
property
command_container
¶ Alias for
command_container_notrans
-
property
command_container_notrans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a BaseDictationContainer of the appropriate type given the speech recognition system in use, without any alterations of any sort applied to the container contents.
-
property
command_container_trans
¶ Returns any and all content starting from first full command intro, if any. Content is returned as a BaseDictationContainer of the appropriate type given the speech recognition system in use, with no formatting applied yet with literal tags translated to their intended result.
-
class
SplitForcedDictation
(name, registry=None, **kwargs)[source]¶ A SplitDictation with forced_dictation set to True, guaranteed to return a value for dictation, even if it must ignore an utterance-initial command from which to provide it.
-
__init__
(name, registry=None, **kwargs)[source]¶ - Parameters
name (string) – The name of this element, used as the keyname in the extras dictionary passed back to _process_recognition
registry (_Registry) – The _Registry instance that determines what words form a command
kwargs – Passed safely to
SplitDictation
-