Skip to content

Commit

Permalink
Add optional *spoken_form* param to NatlinkDictationContainer method
Browse files Browse the repository at this point in the history
Re: #387.

This allows formatting Dragon's dictation words using the spoken
form instead.

I've also mentioned this in the documentation of the Dictation
element.
  • Loading branch information
drmfinlay committed Apr 25, 2024
1 parent d279373 commit 33e6227
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dragonfly/engines/backend_natlink/dictation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ def __init__(self, words, methods):
DictationContainerBase.__init__(self, words=unicode_words,
methods=methods)

def format(self):
""" Format and return this dictation. """
def format(self, use_spoken=False):
"""
Format and return this dictation.
Arguments:
- *use_spoken* (*bool*, default: *False*) --
whether to use the spoken form of dictated words in the result
instead of the written form
"""
formatter = WordFormatter()
formatted = formatter.format_dictation(self._words)
formatted = formatter.format_dictation(self._words, use_spoken)
return self.apply_methods(formatted)
6 changes: 6 additions & 0 deletions dragonfly/grammar/elements_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,12 @@ class Dictation(ElementBase):
Dictation("formattedtext").apply(str_func)
Dictation("snake_text").lower().replace(" ", "_")
Dictation("camelText").camel()
If you are using Dragon/Natlink and want the spoken form of the
dictated words instead of the written form, this can be achieved by
passing ``False`` when calling the ``format()`` method of the
``NatlinkDictationContainer`` object given as this element's value.
"""

# pylint: disable=redefined-builtin
Expand Down

0 comments on commit 33e6227

Please sign in to comment.