Monday, December 30, 2013

Dragon NaturallySpeaking, Vimperator, and Emacs

My wife got me Dragon NaturallySpeaking for Christmas. It's been fun learning how to use it, but it's been frustrating learning how to browse the Internet with it. I ended up saying a lot of hotkeys while working with Firefox, such as "press ctrl+k" and "press ctrl+pgdn".

Then I discovered Vocola, which allows you to define your own custom voice commands. That, together with Vimperator, which I have already been using, it is now a breeze to use Dragon to browse.

I just installed Vocola according to the directions found here.

Here is my .vimperatorrc file:

set hintchars='0123456789'
inoremap <C-a> <Ins><C-a><Ins>
map J gT
map K gt
highlight Hint font-size:200%;color:white;background-color:red;padding:2px;

Simply put this file in your home directory. If you are using a Windows operating system, this is something like c:\Users\djhaskin987.

Then, with Vocola installed, use Dragon NaturallySpeaking to open Firefox, and say "edit voice commands", and paste the following:

 # Voice commands for firefox
visit <_anything> = {Esc}":open $1";
close tab = {Esc}d;
open tab <_anything> = {Esc}":tabopen $1";
follow <_anything> = {Esc} f $1;
follow tab <_anything> = {Esc} F $1;
next doc = {Esc} J;
previous doc = {Esc} K;
back = {Esc} H ;

Viola! Easy browsing by speech. Just say "follow ", or just "follow" and then say the number that pops up next to the link. To open a webpage, just say "visit" followed by the address. Vimperator will give you a menu of options. A couple of "press tab" and "press enter" commands later and you're in business.

I also plan to use Vocola and Dragon NaturallySpeaking to improve my programming by defining some voice commands for Emacs, sort of like Tavis Rudd, only Vocola is way easier to define voice commands with than Python.

Here is my Vocola file so far for Emacs:

# Voice commands for emacs
<number> := 1..99;
open file = {Ctrl+x}{Ctrl+f};
boom = {Enter};
undo = {Ctrl+Shift+_};
die = {Alt+Backspace};
back = {Backspace};
whack = \;
um = {Alt+b};
curly = "{";
close curly = "}";
paren = "(";
all in = ")";
the <_anything> = $1;
start = {Ctrl+a};
end = {Ctrl+e};
camelize <_anything> = {Alt+x} camelize {Enter} $1 {Enter};
left = {Ctrl+b};
<number> up = {Ctrl+u} $1 {Ctrl+p};
<number> down = {Ctrl+u} $1 {Ctrl+n};
<number> left = {Ctrl+u} $1 {Ctrl+b};
right = {Ctrl+f};
up = {Ctrl+p};
down = {Ctrl+n};
go = {Alt+f};
scroll down = {Ctrl+v};
scroll up = {Ctrl+v};
cut = {Ctrl+k};
yank = {Ctrl+y};
nay = {Alt+y};  

The function "camelize" is an emacs lisp interactive function which takes a phrase like "the grand old duke of york" and turns it into "theGrandOldDukeOfYork", kind of like what is found in the emacs wiki, but changing from space separated instead of underscore separated, and making the function interactive as well.

I hope to also use Emacs templating like Tavis Rudd does in his video  to make functions and classes by speech easier in Emacs.

EDIT: I'm putting my vocola files for easy browsing and programming by voice in a git repository. Pull requests wecome!