Skip to content

Instantly share code, notes, and snippets.

@alexboche
Last active July 31, 2019 07:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alexboche/31eecb398f0dbcdc78d5df137cfb6fff to your computer and use it in GitHub Desktop.
from dragonfly import *
import nsformat
formatting_state = None #
def format_dictation(dictation, input_state):
formatted_output, output_state = nsformat.formatWords(str(dictation), state=input_state)
formatted_output = str(formatted_output)
Text(formatted_output).execute()
global formatting_state # I'm not sure if I'm managing the state properly here,I don't know how to properly do that in Python
formatting_state = output_state
class CommandRule(MappingRule):
mapping = {
"splat [<n>]":Key("c-backspace:%(n)s"),
}
extras = [IntegerRef("n", 1, 10)]
defaults = {"n":1}
command_rule = CommandRule()
class DictationRule(MappingRule):
mapping = {
# "<dictation>": Text("%(dictation)s "), # adding a trailing space
"<dictation>": Function(format_dictation, input_state=formatting_state)
}
extras = [ Dictation("dictation") ]
dictation_rule = DictationRule()
dict_cmd_sequence = Repetition(Alternative([RuleRef(dictation_rule), RuleRef(command_rule)]),
min=1, max=10, name="dict_cmd_sequence")
class SequenceRule(CompoundRule):
spec = "<dict_cmd_sequence>"
extras = [dict_cmd_sequence]
def _process_recognition(self, node, extras):
for action in extras["dict_cmd_sequence"]:
action.execute()
grammar = Grammar("zurow")
sequence_rule = SequenceRule()
grammar.add_rule(sequence_rule)
grammar.load()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment