def load_grammar(): import df_utils from srabuilder import rules names = get_locations() locs = [] for name in names: loc_commands = LOCATION_COMMANDS.get(name) locs.append(Location(name, loc_commands)) grammar = df.Grammar("locations") main_rule = df.MappingRule( name="locations_rule", mapping=mapping, extras=[ rules.num, df_utils.positive_index, df_utils.positive_num, df.Choice("locations", commands(locs)), ], context=is_active, defaults={ "n": 1, "positive_num": 1, "positive_index": 0 }, ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("no_menu") main_rule = df.MappingRule( name="no_menu_rule", mapping=mapping, extras=[ rules.num, df_utils.positive_index, df_utils.positive_num, df.Choice("npcs", characters.npcs), num2, df.Choice("direction_keys", game.direction_keys), df.Choice("direction_nums", game.direction_nums), df.Choice("debris", debris), items.items_choice, df.Choice("points", locations.commands(locations.points)), ], context=is_active, defaults={ "n": 1, "positive_num": 1, "positive_index": 0 }, ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("shipping_bin_menu") main_rule = df.MappingRule(name="shipping_bin_menu_rule", mapping=mapping, extras=[rules.num, df_utils.positive_index], context=is_active) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("items_to_grab_menu") main_rule = df.MappingRule( name="items_to_grab_menu_rule", mapping=mapping, extras=[df_utils.positive_index, df_utils.positive_index2], context=is_active) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("cutscene") main_rule = df.MappingRule( name="cutscene_rule", mapping=mapping, context=df.FuncContext(is_active), ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("crafting_page") extras = [ df_utils.positive_num, df_utils.positive_index, items.craftable_items_choice, df_utils.dictation_rule(), ] grammar = menu_utils.build_menu_grammar(mapping, get_crafting_page, extras=extras) grammar.load()
def load_grammar(): grammar = df.Grammar("any_context") main_rule = df.MappingRule( name="any_context_rule", mapping=non_repeat_mapping, extras=[ df_utils.positive_num, df.Choice("mouse_directions", mouse_directions), ], context=df.FuncContext(is_active), defaults={"positive_num": 1}, ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("game_menu") main_rule = df.MappingRule( name="game_menu_rule", mapping=mapping, extras=[ df.Choice("tabs", tabs), df_utils.positive_num, ], defaults={'positive_num': 1}, context=is_active, ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("dialogue_menu") main_rule = df.MappingRule( name="dialogue_menu_rule", mapping=mapping, extras=[ rules.num, df_utils.positive_index, df_utils.positive_num, df_utils.dictation_rule() ], context=is_active, defaults={'positive_num': 1}, ) grammar.add_rule(main_rule) grammar.load()
def load_grammar(): grammar = df.Grammar("carpenter_menu") main_rule = df.MappingRule( name="carpenter_menu_rule", mapping=mapping, extras=[ df.Choice("direction_keys", game.direction_keys), df.Choice("direction_nums", game.direction_nums), rules.num, df_utils.positive_index, df_utils.positive_num ], context=is_active, defaults={'positive_num': 1}, ) grammar.add_rule(main_rule) grammar.load()
def build_menu_grammar(mapping, menu_validator, extras=(), defaults=None): global MENU_GRAMMAR_COUNT import df_utils, game, server mgb = MenuGrammarBuilder(mapping, menu_validator) defaults = {'positive_num': 1} if defaults is None else defaults n = MENU_GRAMMAR_COUNT + 1 MENU_GRAMMAR_COUNT = n grammar = df.Grammar(f"menu_grammar_{n}") new_mapping = {} for cmd, v in mapping.items(): if isinstance(v, df_utils.AsyncFunction ) and v.format_args: # insert active menu as first arg v.format_args = mgb.format_args_menu_provider(v.format_args) new_mapping[cmd] = v main_rule = df.MappingRule(name=f"menu_grammar_rule_{n}", mapping=new_mapping, extras=extras, defaults=defaults, context=df.FuncContext(mgb.is_active)) grammar.add_rule(main_rule) return grammar
def load(): """Register grammar.""" global GRAMMAR GRAMMAR = dragonfly.Grammar('aenea') GRAMMAR.add_rule(EnableRule()) GRAMMAR.add_rule(DisableRule()) GRAMMAR.add_rule(ChangeServer()) GRAMMAR.load() print 'Aenea client-side modules loaded successfully' print 'Settings:' print '\tHOST:', aenea.config.DEFAULT_SERVER_ADDRESS[0] print '\tPORT:', aenea.config.DEFAULT_SERVER_ADDRESS[1] print '\tPLATFORM:', aenea.config.PLATFORM print '\tUSE_MULTIPLE_ACTIONS:', aenea.config.USE_MULTIPLE_ACTIONS print '\tSCREEN_RESOLUTION:', aenea.config.SCREEN_RESOLUTION try: aenea.proxy_contexts._get_context() print 'Aenea: Successfully connected to server.' except Exception: print 'Aenea: Unable to connect to server.'
class ChangeServer(dragonfly.CompoundRule): spec = command_table['set proxy server to <proxy>'] extras = [dragonfly.DictListRef('proxy', server_list)] def _process_recognition(self, node, extras): aenea.communications.set_server_address((extras['proxy']['host'], extras['proxy']['port'])) def _process_begin(self): if server_list_watcher.refresh(): server_list.clear() for k, v in server_list_watcher.conf.get('servers', {}).iteritems(): server_list[str(k)] = v grammar = dragonfly.Grammar('aenea') grammar.add_rule(EnableRule()) grammar.add_rule(DisableRule()) grammar.add_rule(ReloadGrammarsRule()) grammar.add_rule(ChangeServer()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar if grammar: grammar.unload() grammar = None
def get_grammar(context, config): if "i3-mod-key" not in config: print("Missing required 'i3-mod-key' in config file") return None mod_key = config["i3-mod-key"] mod_char = "a" if mod_key == "ctrl": mod_char = "c" elif mod_key == "alt": mod_char = "a" elif mod_key == "win": mod_char = "w" else: print("Invalid value specified for 'i3-mod-key' in config file") return None # FIXME: This is nested because we need access to the mod_char class Mapping(dragonfly.MappingRule): mapping = aenea.configuration.make_grammar_commands( 'i3wm', { '(works|workspace) <n>': Key(mod_char + "-%(n)d"), 'lock screen': Key(mod_char + "-d") + Text("i3lock") + Key("enter"), '(win|window) left': Key(mod_char + "-j"), '(win|window) right': Key(mod_char + "-semicolon"), '(win|window) up': Key(mod_char + "-l"), '(win|window) down': Key(mod_char + "-k"), 'full-screen': Key(mod_char + "-f"), '(win|window) stacking': Key(mod_char + "-s"), '(win|window) default': Key(mod_char + "-e"), '(win|window) tabbed': Key(mod_char + "-w"), '(win|window) horizontal': Key(mod_char + "-h"), '(win|window) vertical': Key(mod_char + "-v"), '(win|window) terminal': Key(mod_char + "-enter"), '(win|window) vertical (term|terminal)': Key(mod_char + "-v, a-enter"), '(win|window) horizontal (term|terminal)': Key(mod_char + "-h, a-enter"), '(win|window) (kill|close)': Key(mod_char + "s-q"), '(win|window) launch': Key(mod_char + "-d"), }) extras = [ IntegerRef('n', 1, 99), Dictation('text'), dragonfly.IntegerRef('appnum', 1, 99), ] i3wm_grammar = dragonfly.Grammar('i3wm', context=context) i3wm_grammar.add_rule(Mapping(mod_char)) return i3wm_grammar
def get_grammar(context, config): cinnamon_grammar = dragonfly.Grammar('cinnamon', context=context) cinnamon_grammar.add_rule(Mapping()) return cinnamon_grammar
# None of the possible states were accepted, failure. state.decode_failure(self) return def value(self, node): return node.words() class DgnLettersRule(dragonfly.CompoundRule): spec = "letters <dgnletters>" extras = [DgnImported("dgnletters")] def _process_recognition(self, node, extras): aenea.Text(text).execute() grammar = dragonfly.Grammar('global') grammar.add_rule(DgnLettersRule()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar if grammar: grammar.unload() grammar = None
aenea.communications.server.client_finished_macro_reload() print "Reload Natlink..." reload_code() def reload_server_plugins(): print "Telling server to reload plugins" aenea.communications.server.update_server_plugins() class ReloadMacros(dragonfly.MappingRule): mapping = { 'reload macros from server': dragonfly.Function(reload_macros_from_server), 'reload server plugins': dragonfly.Function(reload_server_plugins), } grammar = dragonfly.Grammar('tim reload shared dir macros') grammar.add_rule(ReloadMacros()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
'reply all': Key("a"), 'gmail back': Key("u"), '[go] to inbox': Key("g, i"), '[go] to sent': Key("g, t"), '[go] to archive': Key("g, a"), '[go] to label': Key("g, l"), '[go to] label <text>': Key("g, l") + Text("%(text)s") + Key("enter"), '(delete|trash) message': Key("hash"), 'archive (message|that)': Key("e"), 'preeve [<n>]': Key("p:%(n)d"), } chrome_context = aenea.ProxyCustomAppContext(id="Google Chrome") gmail_context = aenea.ProxyCustomAppContext( titl="Mail") & aenea.ProxyCustomAppContext(id="Google Chrome") chrome_grammar = dragonfly.Grammar('chrome', context=chrome_context) gmail_grammar = dragonfly.Grammar('gmail', context=gmail_context) class MappingChrome(dragonfly.MappingRule): mapping = chrome_mapping extras = [ IntegerRef('n', 1, 25), Dictation('text'), ] defaults = { "n": 1, } class MappingMail(dragonfly.MappingRule):
def get_grammar(context): python_grammar = dragonfly.Grammar('python', context=context) python_grammar.add_rule(Python()) return python_grammar
# Commands for interatcting with Chrome. Requires the Vimium extension. # http://vimium.github.io/ # # Author: Tony Grosinger # # Licensed under LGPL import aenea import aenea.configuration from aenea.lax import Key, Text, Dictation from aenea import (IntegerRef) import dragonfly chrome_context = aenea.ProxyCustomAppContext( executable="/opt/google/chrome/chrome") grammar = dragonfly.Grammar('chrome', context=chrome_context) window_mapping = { # Tab navigation 'page (previous|left)': Key("cs-tab"), 'page (next|right)': Key("c-tab"), 'page <n>': Key("c-%(n)d"), 'page new': Key("c-t"), 'page reopen': Key("cs-t"), 'page close': Key("c-w"), 'page back': Key("s-h"), 'page forward': Key("s-l"), 'refresh': Key("r"), 'link': Key("f"), 'link new': Key("s-f"),
# https://github.com/dictation-toolbox/dragonfly-scripts # # Commands for interacting with Git # # Author: Tony Grosinger # # Licensed under LGPL import aenea import aenea.configuration from aenea.lax import Key from aenea import IntegerRef import dragonfly screen_context = aenea.ProxyPlatformContext('linux') grammar = dragonfly.Grammar('screen', context=screen_context) screen_mapping = aenea.configuration.make_grammar_commands('screen', { 'screen (right|next)': Key("c-a, n"), 'screen (left|previous)': Key("c-a, p"), 'screen create': Key("c-a, c"), 'screen <n>': Key("c-a, %(n)d"), 'screen rename': Key("c-a, s-a"), 'screen exit': Key("c-a, backslash"), 'screen [split] vertical': Key("c-a, bar"), 'screen [split] horizontal': Key("c-a, s-s"), 'screen split next': Key("c-a, tab") })
# Commands for interacting with Vim # # Author: Tony Grosinger # # Licensed under LGPL import aenea import aenea.configuration from aenea.lax import Key, Function from aenea import (Dictation, IntegerRef, Text, Choice) import dragonfly from _generic_edit import pressKeyMap vim_context = aenea.ProxyCustomAppContext(executable="gnome-terminal") grammar = dragonfly.Grammar('vim', context=vim_context) surroundCharsMap = { 'quotes': '"', 'parens': "(", 'brackets': "[", 'braces': "{", } def goto_line(n): for c in str(n): Key(c).execute() Key("G").execute()
extras['static'].execute(extras) class DynamicRule(dragonfly.CompoundRule): spec = command_table['<dynamic>'] extras = [ dragonfly.DictListRef( 'dynamic', aenea.vocabulary.register_global_dynamic_vocabulary()) ] def _process_recognition(self, node, extras): extras['dynamic'].execute(extras) grammar = dragonfly.Grammar('vocabulary') grammar.add_rule(RefreshRule()) grammar.add_rule(EnableRule()) grammar.add_rule(DisableRule()) grammar.add_rule(SwitchRule()) grammar.add_rule(DynamicRule()) grammar.add_rule(StaticRule()) grammar.load() # Unload function which will be called at unload time. def unload(): aenea.vocabulary.unregister_list_of_dynamic_vocabularies() global grammar
mme_mapping = { 'send message': Key("sw-d"), 'edit in (macvim|vim)': Key("cs-o"), 'forward message': Key("sw-f"), 'reply message': Key("w-r"), 'reply all': Key("ws-r"), 'archive message': Key("sw-m"), 'move message': Key("aw-t"), '(send |add) to omnifocus': Key("cs-a"), } mm_context = aenea.ProxyCustomAppContext( id="MailMate") & aenea.ProxyCustomAppContext(match="substring", titl=" message") mme_context = aenea.ProxyCustomAppContext(id="MailMate") mm_grammar = dragonfly.Grammar('mailmate', context=mm_context) mme_grammar = dragonfly.Grammar('mailmate', context=mme_context) ########## class MappingMM(dragonfly.MappingRule): mapping = mm_mapping extras = [ IntegerRef('n', 1, 60), Dictation('text'), ] defaults = { "n": 1, }
_config.conf['enabled'] = True _config.write() def disable_capture(): _config.refresh() _config.conf['enabled'] = False _config.write() class ControlRule(dragonfly.MappingRule): mapping = { 'enable dictation capture': dragonfly.Function(enable_capture), 'disable dictation capture': dragonfly.Function(disable_capture) } grammar = dragonfly.Grammar('capture_client_control') grammar.add_rule(ControlRule()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar if grammar: grammar.unload() grammar = None
spec = command_table["set proxy server to <proxy>"] extras = [dragonfly.DictListRef("proxy", server_list)] def _process_recognition(self, node, extras): aenea.communications.set_server_address( (extras["proxy"]["host"], extras["proxy"]["port"])) def _process_begin(self): if server_list_watcher.refresh(): server_list.clear() for k, v in server_list_watcher.conf.get("servers", {}).iteritems(): server_list[str(k)] = v grammar = dragonfly.Grammar("aenea") grammar.add_rule(EnableRule()) grammar.add_rule(DisableRule()) grammar.add_rule(ReloadGrammarsRule()) grammar.add_rule(ChangeServer()) grammar.load() # Unload function which will be called at unload time. def unload(): global grammar if grammar: grammar.unload() grammar = None
# # Commands for inserting personal details loaded from the config file # # Author: Tony Grosinger # # Licensed under LGPL import aenea import aenea.configuration from aenea.lax import Function, Text from aenea import Choice import dragonfly from config import get_configuration vim_context = aenea.ProxyPlatformContext('linux') generic_grammar = dragonfly.Grammar('generic', context=vim_context) config = get_configuration() commands = {} if "full-name" in config: commands['my full name'] = Text("%s" % config["full-name"]) if "last-name" in config: commands['my last name'] = Text("%s" % config["last-name"]) if "first-name" in config: commands['my first name'] = Text("%s" % config["first-name"]) if "email-address" in config: commands['my email'] = Text("%s" % config["email-address"]) if "company-name" in config: commands['company name'] = Text("%s" % config["company-name"])
dragonfly.Function(lambda text: print("I heard %r!" % str(text))), } extras = [dragonfly.Dictation("text")] # Load engine before instantiating rules/grammars! # Set any configuration options here as keyword arguments. engine = dragonfly.get_engine( "kaldi", model_dir='kaldi_model_zamia', # tmp_dir='kaldi_tmp', # default for temporary directory # vad_aggressiveness=3, # default aggressiveness of VAD # vad_padding_ms=300, # default ms of required silence surrounding VAD # input_device_index=None, # set to an int to choose a non-default microphone # cloud_dictation=None, # set to 'gcloud' to use cloud dictation ) # Call connect() now that the engine configuration is set. engine.connect() grammar = dragonfly.Grammar(name="mygrammar") rule = ExampleCustomRule() grammar.add_rule(rule) grammar.add_rule(ExampleDictationRule()) grammar.load() print( 'Try saying: "I want to eat an apple" or "I want to eat a greasy hamburger" or "dictate this is just a test"' ) print("Listening...") engine.do_recognition()
zotero_mapping = { 'add tag': Key("c-t"), 'add note': Key("c-n"), 'copy bibtex': Key("c-b"), 'copy formatted reference': Key("c-r"), 'copy [zotero] link': Key("c-z"), 'focus info': Key("c-i"), 'edit (info|that)': Key("c-e"), 'delete tags': Key("c-d"), 'delete tags': Key("c-d"), '(get|retrieve) meta-data': Key("c-m"), 'rename attachments': Key("c-a"), } zotero_context = aenea.ProxyCustomAppContext(id="Zotero") zotero_grammar = dragonfly.Grammar('Zotero', context=zotero_context) ########## class MappingZotero(dragonfly.MappingRule): mapping = zotero_mapping extras = [ IntegerRef('n', 1, 60), Dictation('text'), ] defaults = { "n": 1, } zotero_grammar.add_rule(MappingZotero()) zotero_grammar.load()
import aenea import aenea.configuration from aenea.lax import Key from aenea import Text import dragonfly # For now this file will also cover all other iTerm2 commands git_context = aenea.ProxyCustomAppContext(id="iTerm2") grammar = dragonfly.Grammar('git', context=git_context) git_mapping = aenea.configuration.make_grammar_commands( 'git', { 'git': Text("git"), 'git amend': Text("git commit --amend") + Key("enter"), 'git stash': Text("git stash") + Key("enter"), 'git commit': Text("git commit") + Key("enter"), 'git commit all': Text("git commit -av") + Key("enter"), 'git pull': Text("git pull") + Key("enter"), 'git branches': Text("git branch -l") + Key("enter"), 'git status': Text("git status") + Key("enter"), 'git push': Text("git push") + Key("enter"), 'git diff': Text("git diff") + Key("enter"), 'git log': Text("git lg") + Key("enter"), # lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative # Incomplete Commands 'git add': Text("git add "), 'git add force': Text("git add -f "), 'git clone': Text("git clone "),