How to get the variable for words in a dynamic AutoVoice command

autovoice-dynamic-variable

AutoVoice has a few different built in variables, including an array that contains all the individual words in the recognized command, i.e. %avword1, %avword2 etc. That’s great if you know the position of the word you need the variable for, but if that position changes from one command to the next, it’s a bit trickier, but not much.

There are a couple of different situations where you might want to do this. The first is if you want to get the variable that contains a specific word that changes position from command to command. Let’s say you want to know which %avword contains the word “google” in a situation with possible commands along the lines of “ok google, find this” or “I need you to google this for me”. To do this you can use one of the methods for accessing data in an array, documented here. Specifically, you would use the  following action:

Variable Set %temp to %avword(#?google)

After that, you can use the following code to refer to the variable:

%avword(%temp)

Which will then contain “google”. %avword(#?google) essentially tells Tasker to search the array %avword for any variables that match “google”, and return their array number. So if the fifth word is “google”, %avword(#?google) will be 5. Then, by slapping a variable that contains that behind %avword, you’re actually asking for the array variable %avword5.

Note that %avword(%avword(#?google)) doesn’t work, but if anyone knows a way to make Tasker accept variable names that complex, let me know. Also note that the word after #? follows normal matching rules in Tasker, so use * as wildcards to make it match parts of words.

The other way you can use this is to get the variable for a dynamic word that you know the position of relative to another word. This is what I’ve actually used this for myself, as it allows you to get a variable that contains a dynamic word based on its position relative to a static word. For instance, I’ve used this to get the variables of words that immediately precede the words “seconds” and “minutes”. That way, if I use a command that include values in seconds and minutes, I can access the values of those regardless of how the command is phrased, as long as those denominations are used.

The way to do this is very similar to the above, you simply add some math to the whole thing. For instance, if I want to select the word in front of “second” or “seconds” in the command, I would use this action:

Variable Set %temp to %avword(#?second*)-1, Use Maths. 

You can then use %avword(%temp) to refer to the variable right in front of “second” or “seconds”.  Like above we found the array number of a variable containing a certain word, and simply subtracted 1 from it to get the one before it. By subtracting or adding other numbers you can select other words relative to the static one.

By using this method, I was able to get mentions of seconds and minutes as variables that I could then convert and feed into a timer app to start a timer. Another use I’ve seen for this is someone who wanted to get a variable containing the word immediately following “meet” in a command. By doing that, you can tell your voice assistant “hello there, meet John”, and then have a Say response that actually incorporates the name that followed “meet”.   I’ve also used this to integrate my Tasker todo list app with AutoVoice, allowing me to add items using voice. In that case I used this trick to find the word right before “list”, giving me a variable with the name of the list I wanted to add the item to.

tasker banner - for some reason we don't have an alt tag here

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
become a patron button - for some reason we don't have an alt tag here

Andreas Ødegård

Andreas Ødegård is more interested in aftermarket (and user created) software and hardware than chasing the latest gadgets. His day job as a teacher keeps him interested in education tech and takes up most of his time.

Avatar of Andreas Ødegård

5 thoughts on “How to get the variable for words in a dynamic AutoVoice command

  • Avatar of Jackson
    August 1, 2013 at 8:44 am
    Permalink

    Is there a way to convert what is said to its corresponding number, like to set an alarm clock?

    For my sleep mode, it asks me what time I want to set an alarm for. Can I take my response and use it to set an alarm?

    eg: If I say “seven thirty” can I then use
    Set Alarm
    Hours: %avword1
    Minutes: %avword2

    Reply
    • Avatar of Andreas Ødegård
      August 1, 2013 at 8:46 am
      Permalink

      Mine gives me numerical values, so I dont know why yours doesnt

      Reply
  • Avatar of Jackson
    August 1, 2013 at 8:51 am
    Permalink

    Do I need to do a variable split first? Or does Autovoice do this for me?

    Reply
  • Avatar of jocke
    August 14, 2013 at 2:00 pm
    Permalink

    I am trying to use %avcommnofilter to get tasker to respond to names. But it doesn’t work at all.

    First i say: Hi
    Tasker responds with: Hi, who are you?
    I respond: My name is xxx
    Tasker responds with: hi %avcommnofilter i am tasker

    Do i need to set the variable %avcommnofilter to something first or what am i doing wrong??

    Reply
    • Avatar of Pong
      August 18, 2013 at 3:07 am
      Permalink

      Jocke, I think you need to set a new variable to be %avcommnofilter first, then use that new variable instead of %avcommnofilter.

      so, for eg.
      set %name to %avcommnofilter
      say “My name is %name i am tasker”

      Reply

Leave a Reply

Your email address will not be published.