Registering and logging in removes this ad.
Registering and logging in removes this ad.
on-the-fly natlink/vocola macros
I often have to utter something complex like
"set font courier 10 point"
but am too lazy to create a specific vocola macro by hand for this, especially since I will only use it a few times and don't want to keep it around forever.
I hacked the natpython code below to create a hands-free vocola macro. For example,
after I say,
"set font courier 10 point"
I can say
"alias that courier change"
and a new vocola file (_aliasFile.vcl) will be created so the next time I say
"courier change"
the "set font..." command will be executed.
I invite comments. Note that you will have to hand-edit the path to your local vocola directory. I don't know how to do that automatically. You can put this python code in your natlink directory.
===========
# This is the implementation of "alias that". In this implementation, you can
# say "alias that command_name" to create a vocola alias alias the last
# recognition mapped to command_name, which itself can be one or multiple
# words.
#
# This is handy if you enunciate a complex commands that you want to use over
# and over again without having to write a specific vocola macro for it.
#
# Note that the command file is hard-wired below to my d:/documents/.. path.
# You will have to change that for your local installation.
#
# reckoner
# 01/30/2007
import natlink
import string
from natlinkutils import *
lastResult = None
class CatchAllGrammar(GrammarBase):
gramSpec = """
<start> exported = {emptyList};
"""
def initialize(self):
self.load(self.gramSpec,allResults=1)
self.activateAll()
def gotResultsObject(self,recogType,resObj):
global lastResult
if recogType == 'reject':
lastResult = None
elif resObj.getWords(0)[:2] != ['alias','that']:
lastResult = resObj.getWords(0)
class AliasGrammar(GrammarBase):
gramSpec = """
<dgndictation> imported;
<start> exported = alias that <dgndictation>;
"""
def initialize(self):
self.load(self.gramSpec)
self.activateAll()
def gotResults_dgndictation (self,words,fullResults):
global lastResult
file=open('D:/Documents/NatLink/Vocola/_aliasFile.vcl','w')
file.write(string.join(words))
file.write(' = HeardWord(')
for i in lastResult[:-1]:
file.write('"'+i+'",')
file.write('"'+lastResult[-1]+'");')
file.close()
natlink.recognitionMimic( ["Load","All","Voice","Commands"])
def gotResults_start(self,words,fullResults):
global lastResult
catchAllGrammar = CatchAllGrammar()
catchAllGrammar.initialize()
aliasGrammar = AliasGrammar()
aliasGrammar.initialize()
def unload():
global catchAllGrammar
global aliasGrammar
if catchAllGrammar:
catchAllGrammar.unload()
catchAllGrammar = None
if aliasGrammar:
aliasGrammar.unload()
aliasGrammar = None

I invite you to have a look
I invite you to have a look at unimacro and see what you can do there. Hacking into vocola this way is layer upon layer upon layer and not very wise IMHO.
Quintijn
PS Ready to discuss this in private email if you wish.
Yes, but it is pretty cool...
I think this is a great feature ,
but it doesn't appear to work with the latest version of natlink, because my natlink doesn't automatically load changes to scripts anymore with the latest version. Also, when I go into "vocola window" and then I try to reload everything, I get the following error
An exception occurred loading 'natlinkmain' module
No more error information is available"
And then all of my vocola and the natlink macros stop working. I think natlink has crashed...