Skip to content

Instantly share code, notes, and snippets.

@alexboche
alexboche / excel.py
Last active December 15, 2019 20:43
"""
Command-module for Microsoft Excel
You also can find some good vocola commands for Excel on Mark Lillibridge's Github:
https://github.com/mdbridge/bit-bucket/tree/master/voice/my_commands/commands
Alex Boche 2019
"""
# import itertools
# this function takes a dictionary and returns a dictionary whose keys are sequences of keys of the original dictionary
import dragonfly
class GreedyishRule(MappingRule):
mapping = {
"say <dictation>": Text("%(<dictation>)s"),
"numb <number_sequence>": Text("%(<number_sequence>)s"),
}
digits = {"one": "1", "two": "2", "three": "3"}
extras = [Dictation("dictation"),

A user mentioned they were experiencing a bug with the text manipulation commands where character names were being interpreted as dictation (e.g. "arch" was being interpreted as the word arch instead of the letter a). Here's some things you could try if you experience a similar bug, based on my incomplete understanding of the problem. Approaches number 3 and 4 will probably not work but they are much less heavy handed than 1 and 2. Approaches 1 and 2 should be done either-or not both. Approaches number 1 and 2 should definitely work, so if they do not there's probably just a typo in my code or something, so let me know.

  1. The purpose of discriminating between dictation and commands here is so you don't end up matching something like "land" when you say "go lease and". This is nice but it's not that important, so you could just handle dictation and commands in the same way. If you replace your text_manipulation_functions.py with this file whic
from dragonfly import *
class CommandRule(MappingRule):
mapping = {
"amp": Key("a"),
"bairch": Key("b"),
"lanty [<n>]": Key("left"),
}
extras = [IntegerRef("n", 1, 10)]
defaults = {"n":1}
from dragonfly import *
import nsformat
dictation_length = [] # for "scratch that" purposes
input_state = None
""" Note: if you pass in the input state into the function using the function action rather than just accessing it
from within the function using the fact that it is in global scope, the input state will not be updated
when you run the dictation command multiple times
To see what I mean note that in contrast to the approach here, the approach taken
at the following link does not update the state after each dictation utterance
def make_averager():
count = 0
total = 0
def averager(new_value):
# nonlocal count, total # doesn't work
# global count, total
count = count + 1
total = total + new_value
print(total/count)
return total/count
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
__version__ = "$Revision: 105 $, $Date: 2008-12-04 12:47:13 +0100 (do, 04 dec 2008) $, $Author: quintijn $"
# Python Macro Language for Dragon NaturallySpeaking
# (c) Copyright 1999 by Joel Gould
# Portions (c) Copyright 1999 by Dragon Systems, Inc.
#
# This code simulates the basic text formatting from NatSpeak.
#
# code written by Joel Gould, posted on the natpython discussion list on Wed, 28 Aug 2002
#
# inserted in the unimacro package june 2006
<?xml version="1.0" encoding="utf-16"?>
<!DOCTYPE WordExport SYSTEM "http://dragoncontent.nuance.com/dtds/Words10.dtd">
<WordExport NatspeakVersion="15.00.000.076" NatspeakEdition="ProfessionalIndividual" User="alex_profile_10-2018 - Copy_july-2019" Topic="math" Language="ENX" MRECVersion="1.35.100.17944">
<Word name="math alpha">
<ITN-RuleInfo rewriteActive="true" paramHandle="-1" paramValue="" userData="">
<RewriteText>
<![CDATA[$\alpha$]]>
------------------
Grammar(chrome): 3 rules (1 exported, 0 imported):
- ChromeRule(chrome) 1571
- Alternative(...) 1570
- Compound('[<click_by_voice_options>] <numbers>') 376
- Sequence(...) 375
- Optional(...) 18
- Choice(..., name='click_by_voice_options') 17
- Compound('click') 2 (+ 1 trivial direct child)
- Compound('copy') 2 (+ 1 trivial direct child)