AutoVoice variables

You can use 4 types of variables in the Entry Task of an AutoVoice profile:

– %avcomm
– %avcommnofilter
– %avword1, %avword2, %avword3 etc are all the words in the command you spoke.
– user created variables with regex

%avcomm

Contains the whole command you spoke

 

%avcommnofilter

Contains the whole command minus the the text you put as the command filter in the condition.

Useful when you want the last part of what you spoke readily available.

For example, if you want to google for something on your phone you could have:

  • AutoVoice condition with “google” command filter
  • Task with an action to search google for %avcommnofilter

If, in this example, you said “Google birds”, you would start a google search for “birds”

 

%avword1, %avword2, %avword3 etc

These contain all  the words of the spoken command.

For example, if you say “what time is it”, these variables will be:

  • %avword1: what
  • %avword2: time
  • %avword3: is
  • %avword4: it

 

User created variables with regex:

The above variables are great in some conditions, but there are times that they can also be a bit of a pain.

Gone are the days of fishing around %avwords and %avcommnofilters for words you want to use in your tasks with user created variables!

In the old days, for example, if you wanted a command to turn the lights in a given bedroom to a certain level, you could use something like:
– Command: “Turn lights to 25% in the living room”
– Command filter: “Turn lights to”
– Task:
– Get %avword4 to know the desired percentage, and remove the % at the end (to get the number 25, and not 25%) and put it in the variable %level
– Try and guess what the last words are someway to get the name of the room, so you could support stuff like “living room” (2 words), but also “kitchen” (one word) and put them in the variable %room
– Finally, turn the light level to %level percent, in the room called %room

Long story short, it would be a bit of a headache.

With this new feature you could simply do this:

– Command: “Turn lights to 25% in the living room”
– Command filter: “Turn lights to (?<level>.+) in the (?<room>.+)” with regex
– Task: turn the light level to %level percent, in the room called %room 🙂

No more searching for the right variables, and splitting strings. You can define the variables you want in the command filter itself, and they will be available in the Task!

Use the (?<variableName>) notation around the stuff you want to be a variable. In regex, “.+” means “1 or more characters”, so in this example this simple expression is used twice in  (?<level>.+) and ?<room>.+)  to get what you want.

To use these named groups you have to remember something very important: you need to name EVERY group you make or else the named variables will not be correctly populated. So, for instance, instead of using a command filter like:

“(play|put on) a movie by (?<actor>.+)”

use something like

“(?<play>play|put on) a movie by (?<actor>.+)”
You’ll have the correctly populated %actor variable as well as a (rather useless perhaps) %play variable.