'copy': 'cp ', 'link': 'ln ', 'list': 'ls ', 'make dir': 'mkdir ', 'move': 'mv ', 'p grep': 'pgrep ', 'p kill': 'pkill ', 'remove': 'rm ', 'remove dir': 'rmdir ', 'symbolic link': 'ln -s ', 'all': '-a ', 'force': '-f ', 'interactive': '-i ', 'long': '-l ', 'recursive': '-r ', 'silent': '-s ', 'verbose': '-v ', 'flag': '--', 'help': '--help', 'version': '--version', 'parent': '../', } ctx = Context('cli') ctx.set_commands({ '<cli>': lambda m: insert(cli_map[m['cli']]), }) ctx.set_choices({ 'cli': cli_map, })
from osprey.control import disable, quit_program, reload_scripts from osprey.open import open_config_dir, open_history_file, open_log_file from osprey.voice import Context ctx = Context('osprey_commands') ctx.set_commands({ 'osprey disable': lambda m: disable(), 'osprey quit': lambda m: quit_program(), 'reload scripts': lambda m: reload_scripts(), 'open (config|configuration) (dir|directory)': lambda m: open_config_dir(), 'open history file': lambda m: open_history_file(), 'open log file': lambda m: open_log_file(), })
import subprocess from sys import platform from osprey.voice import Context from ..utils import is_program_running def clear_notifications(m): if platform == 'win32': pass elif platform == 'darwin': pass else: if is_program_running('mako'): subprocess.run('makoctl dismiss -a'.split()) ctx = Context('commands') ctx.set_commands({ 'clear notifications': clear_notifications, })
import subprocess from sys import platform from osprey.voice import Context, press from ..utils import is_program_installed def set_volume(n): if platform == 'win32': pass elif platform == 'darwin': pass else: if is_program_installed('pamixer'): subprocess.run(f'pamixer --set-volume {n}'.split()) ctx = Context('volume') ctx.set_commands({ 'volume up': lambda m: press('VolumeUp'), 'volume down': lambda m: press('VolumeDown'), 'volume mute': lambda m: press('VolumeMute'), 'volume set <n>': lambda m: set_volume(m['n']), })
suffix = 'th' return suffix def format_number(n, separator): n = str(n) if not separator: return n n = list(n) for i in range(3, len(n), 4): n.insert(len(n) - i, separator) return ''.join(n) def number(m): n = m['n'] separator = separators_map[m['separators']] if m['separators'] else None return format_number(n, separator) ctx = Context('numbers') ctx.set_commands({ 'number <n> [with <separators>]': lambda m: insert(number(m)), 'ordinal <n> [with <separators>]': lambda m: insert(number(m) + ordinal_suffix(m['n'])), }) ctx.set_choices({ 'separators': separators_map.keys(), })
'bitwise and': '&', 'bitwise or': '|', 'bitwise x or': '^', 'right shift': '>>', 'left shift': '<<', # boolean expressions 'equivalent': '==', 'not equal': '!=', 'less than': '<', 'greater than': '>', 'less than or equal': '<=', 'greater than or equal': '>=', 'and': '&&', 'or': '||', }) def operators(m): op = operators_map[m['operators']] insert(f' {op} ') ctx = Context('operators') ctx.set_commands({ 'op <operators>': operators, }) ctx.set_choices({ 'operators': operators_map.keys(), })
delimiters_map = normalize_keys({ 'tick': '``', 'quote': '\'\'', 'square|bracket': '[]', 'angle': '<>', 'double quote|double quotes': '""', 'brace|curly': '{}', 'paren': '()', 'double under': '____', 'space': ' ', }) def surround(m): delimiters = delimiters_map[m['delimiters']] insert(delimiters) for _i in range(len(delimiters) // 2): press('Left') ctx = Context('delimiters') ctx.set_commands({ 'surround <delimiters>': surround, 'pair <delimiters>': lambda m: insert(delimiters_map[m['delimiters']]), }) ctx.set_choices({ 'delimiters': delimiters_map.keys(), })
from osprey.voice import Context, repeat ctx = Context('repeater') ctx.set_commands({ 'repeat <n>': lambda m: repeat(m['n'] - 1), 'repeat <n> more': lambda m: repeat(m['n']), 'repeat it': lambda m: repeat(1), })
'snake': lambda s: s.replace(' ', '_'), 'double under': lambda s: '__{}__'.format(s.replace(' ', '_')), } def formatters(m): phrase = m['phrase'] if 'title' in m['formatters']: phrase = formatters_map['title'](phrase) m['formatters'].remove('title') for formatter in m['formatters']: phrase = formatters_map[formatter](phrase) insert(phrase) ctx = Context('formatters') ctx.set_commands({ 'word <word>': lambda m: insert(uppercase_i(m['word'])), 'upper <word>': lambda m: insert(m['word'].capitalize()), 'lower <word>': lambda m: insert(m['word'].lower()), 'phrase <phrase>': lambda m: insert(uppercase_i(m['phrase'])), 'sentence <phrase>': lambda m: insert(uppercase_i(m['phrase'].capitalize())), 'camel <phrase>': camel_case, '<formatters>+ <phrase>': formatters,
""" This module is used for typing out words that are already in the model vocabulary but are difficult for the engine to identify because they get confused with other words. """ from osprey.voice import Context, insert fix_list = [ 'add', 'and', 'bin', 'crate', 'desk', 'git', 'man', ] ctx = Context('fix') ctx.set_commands({ 'fix <fix>': lambda m: insert(m['fix']), 'fix upper <fix>': lambda m: insert(m['fix'].capitalize()), }) ctx.set_choices({ 'fix': fix_list, })
vocab_map.update({word: word for word in vocab_list}) vocab_map.update( {' '.join(word.lower()): word for word in acronyms_spell_out_list}) subcommands = { 'all caps': lambda s: s.upper(), 'lower': lambda s: s.lower(), 'upper': lambda s: s.capitalize(), } def vocab(m): vocab = vocab_map[m['vocab']] if m['subcommands']: subcommand = subcommands[m['subcommands']] vocab = subcommand(vocab) if 'dotted' in m['transcript']: vocab = '.'.join(vocab) + '.' insert(vocab) ctx = Context('vocab') ctx.set_commands({ 'vocab [<subcommands>] [dotted] <vocab>': vocab, }) ctx.set_choices({ 'vocab': vocab_map.keys(), 'subcommands': subcommands.keys(), })
from osprey.voice import Context, insert, press def code_block(m): insert('```') press('Enter') press('Enter') insert('```') press('Up') ctx = Context('markdown') ctx.set_commands({ 'check box': lambda m: insert('- [ ] '), 'code block': code_block, })
'June': 'Jun', 'July': 'Jul', 'August': 'Aug', 'September': 'Sept', 'October': 'Oct', 'November': 'Nov', 'December': 'Dec', # days of the week 'Sunday': 'Sun', 'Monday': 'Mon', 'Tuesday': 'Tue', 'Wednesday': 'Wed', 'Thursday': 'Thu', 'Friday': 'Fri', 'Saturday': 'Sat', } ctx = Context('shrink') ctx.set_commands({ 'shrink <shrink>': lambda m: insert(shrink_map[m['shrink']]), 'shrink upper <shrink>': lambda m: insert(shrink_map[m['shrink']].capitalize()), 'shrink lower <shrink>': lambda m: insert(shrink_map[m['shrink']].lower()), }) ctx.set_choices({ 'shrink': shrink_map.keys(), })
keys.update(misc_keys) keys.update(punctuation) keys.update(alphabet) keys.update(digits) modifiers = normalize_keys({ 'control|troll|command': 'Ctrl', 'shift': 'Shift', 'alt|option': 'Alt', }) def press_key(m): mods = [modifiers[mod] for mod in m['modifiers']] if 'keys' in m: key = keys[m['keys']] press(' '.join(mods + [key])) else: press(' '.join(mods)) ctx = Context('basic_keys') ctx.set_commands({ '<modifiers>* <keys>': press_key, '<modifiers> key': press_key, }) ctx.set_choices({ 'keys': keys.keys(), 'modifiers': modifiers.keys(), })
from osprey.voice import Context, insert symbols_map = { 'arrow': '->', 'wide arrow': '=>', 'ellipsis': '...', 'degree': '°', } ctx = Context('symbols') ctx.set_commands({ 'symbol <symbols>': lambda m: insert(symbols_map[m['symbols']]), }) ctx.set_choices({ 'symbols': symbols_map, })
from osprey.voice import Context, ContextGroup, default_context_group ctx_group = ContextGroup('speech_toggle') ctx = Context('speech_toggle', group=ctx_group) ctx.set_commands({ 'osprey sleep': lambda m: default_context_group.disable(), 'osprey wake': lambda m: default_context_group.enable(), })