Writing and coding by voice with Talon
Edit 02/2021: this article was written about what is now a legacy version of Talon. The concepts remain the same but the scripts probably won’t work on the latest version of Talon. Visit https://talonvoice.com/ for the most recent documentation.
I previously wrote about writing and coding with the macOS Accessibility Keyboard. It continues to be the most essential piece of assistive technology I use. That said, I recently discovered another amazing tool, Talon.
In recent months, I’ve been spending more time out of my wheelchair in order to get some pressure relief for my legs. As such, I’ve been working a lot on my laptop. I use it in a lying down position, which makes using the mouse somewhat difficult for me. My biggest hindrance is typing on the Accessibility Keyboard.
Enter Talon. Talon is freeware software for macOS that provides “powerful hands-free input” by way of eye-tracking and voice recognition. In particular, its voice recognition system is novel, offering a user experience that’s quite different (and, to me, better) than what you get with Dragon or macOS’ built-in solutions.[1]
The trick is that Talon doesn’t simply type out whatever you dictate. It listens to you then determines what to type based on a set of rules that you can control. For example, if I say:
1title hello world
Talon will output:
1Hello World
This is because I have a script installed that knows if it hears a phrase beginning with the word title
, it should output the rest of that phrase with each word being capitalized. Whereas if I had said:
1hello world
Talon would have output nothing at all. Why is that? Because I don’t have any rules installed that care about the phrase, hello world
. If I did want to literally type hello world
, I would dictate:
1say hello world
By starting the phrase with say
, Talon knows—again, because of a currently installed rule—to output the rest of the phrase normally. Several of these formatters are included in this particular ruleset. Here are just a few of them:
sentence hello world
→Hello world
camel hello world
→helloWorld
snake hello world
→hello_world
spinal hello world
→hello-world
smash hello world
→helloworld
Why Talon? Isn’t Dragon or macOS dictation way better?
Well, that depends. Coders will immediately recognize from my above example what kind of flexibility Talon provides in controlling your output. If you are simply writing natural language, you might not find Talon as useful. But if you need precision—as with programming and editing—Talon really shines. Its number one feature, in my opinion, is its ability to be customized.
Controlling Talon with scripts
For many purposes, the community scripts are enough to provide great functionality. But the real fun is in customizing it to do exactly what you want. Let’s take look at how that works. To do that, we need to use Python. When you install Talon, it creates a user
folder where you can add scripts to control how Talon behaves. You’ll find it at:
1~/.talon/user
This is where you can drop in some Python scripts. Any scripts you put there will be loaded automatically by Talon.
Community scripts
Let’s first take a look at existing scripts you can use to get Talon up and running with some basic functionality. You’ll find some great starting scripts in the talon_community repo. A good start is to include these three files:
utils.py
: used by a bunch of the other filesmisc/basic_keys.py
: what it says on tin, plus a spelling alphabetmisc/std.py
: includes the formatters I described in the intro
Just drop utils.py
into the user
folder. Then create a misc
folder in user
and drop the other two files in. Feel free to edit these files. Personally, I removed a good bit of the coding-related commands from std.py
because they either didn’t support my primary languages or were registering as false positives. Once you launch Talon, it will load those files and you will have access to their functions. For example, basic_keys.py
includes a spelling alphabet for typing single letters—air
becomes a
, bat
becomes b
, and so on. This method gives you greater precision than normal dictation gives you and is especially useful for coding, which contains many terms that can’t be dictated easily.[2]
Writing custom scripts
Of course the real fun is writing your own scripts.[3] Let’s say, like me, you enjoy using the em dash (—
) character. You want to add it your repertoire in Talon. Start by creating a new file, my_scripts.py
. We’re going to be using a module from Talon that is needed to create a keymap—the thing that maps our commands to the output we want.
1from talon.voice import Context
Let’s say we want to type —
by dictating bigger dash
. We would construct our keymap like so:
1ctx = Context('my_scripts')23ctx.keymap({4 'bigger dash': '—'5})
That’s all there is to it. Congratulations, you just wrote your first Talon script!
But let’s keep going. We’ll add a command for activating Spotlight in macOS (command + space). In order to press the modifier key, we need to import something else from Talon. After our addition, the code should look something like this:
1from talon.voice import Context, Key2 3ctx = Context('my_scripts')4 5ctx.keymap({6 'bigger dash': '—',7 'spotlight': Key('cmd-space')8})
Now when we say spotlight
, Talon will virtually type the shortcut for summoning Spotlight search.
Scratching the surface
That’s all we’ve done. Snoop around in the talon_community repo and start to see how powerful Talon really is. If you’re not a coder, don’t worry, there’s a friendly Slack where you can get help from the developer of Talon[4] as well as the community. If you have trouble typing, but haven’t had any luck with dictation in the past, give Talon a try.
Talon actually makes use of Dragon if it’s installed, but also comes with built-in voice recognition, which is what I use. ↩︎
If Talon isn’t picking up certain words or some words are getting false positives, don’t be afraid to experiment with different words. Even if you can’t code, changing the words is as simple as finding the the word list in
basic_keys.py
and editing it. ↩︎Note that, at the time of this writing, there is a new API on the horizon. So keep an eye on the release notes and community repo for changes. ↩︎
The developer has a Patreon so, if you find Talon useful, consider supporting its development. ↩︎