Elements

class SplitDictation(name, registry=None, forced_dictation=False, **kwargs)

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 dragonfluid 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)
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, the ActiveGrammarRule decorator will set the registry of any RegistryGrammar 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__
command

Alias for command_notrans

command_container

Alias for command_container_notrans

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.

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.

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.

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.

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.

command_words

Alias for command_words_notrans

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.

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.

dictation

Alias for dictation_trans.

dictation_container

Alias for dictation_container_trans.

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.

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.

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.

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.

dictation_words

Alias for dictation_words_trans.

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.

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.

full

Alias for full_notrans.

full_container

Alias for full_container_notrans.

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.

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.

full_notrans

Returns the full content, as a string, with formatting applied and with literal tags retained.

full_trans

Returns the full content, as a string, with formatting applied and with literal tags translated to their intended result.

full_words

Alias for full_words_notrans.

full_words_notrans

Returns the full content, as a word list, with formatting applied and with literal tags retained.

full_words_trans

Returns the full content, as a word list, with formatting applied and with literal tags translated to their intended result.

translate(words_iterable)

Returns a word list, as translated.

class SplitForcedDictation(name, registry=None, **kwargs)

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)
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