Home Tasker AutoVoice - custom voice commands and regex groups

AutoVoice – custom voice commands and regex groups

Making the voice commands easy from 2016!

I have received a few inquiries about the AutoVoice regex groups. I decided to put together a very quick tutorial on how to approach the commands like this. When is it useful? Each time you wish to have a voice command which can perform different tasks based on the words used in your sentence.  For the sake of the example, let’s assume I have super-futuristic light control in my house. I can enable or disable light in each room, or turn them all off etc.  The easy way of doing it is to have your command spoken and to have dozens of variants of your commands listed as profiles in AutoVoice. This would work, but the process is lengthy, tedious and there are better ways of doing it.

I WANT TO TURN ON A BLUE LIGHT!

AutoVoice regex groups allow you to assign part of the voice command to a custom variable. We already have an array for each word, however, this way you will be able to be more precise. The full version of this command, with all available options, would be:

I WANT TO TURN ON A BLUE LIGHT!

The command filter in the AutoVoice allows us to easily type this all in, however, we need to add AutoVoice regex groups to capture the words we need, and assign it to custom variables.

I WANT TO TURN (?<STATE>ON|OFF) (?<COLOUR>BLUE|RED|ALL) LIGHT

How to translate this:

(?<name_your_variable_here>enter|possible|options) or
(?<name_your_variable_here>.+) if you are not sure what your option will be, and you wish to capture one or more character.

In my example, I’m using the preset values, as I know what lights I will be turning on and off. Also, the .+ option should be used only at the end of the command, or put at least one word in between capturing groups. Otherwise, you are risking conflicts.

How about different command structure?

Actually, there isn’t any harm in using the AutoVoice regex groups for this. You will end up with few capturing groups that are not used, but all will work just fine. Single words can be also easily separated by the | symbol.

(?<COMMAND>PLEASE|I WANT TO) TURN (?<STATE>ON|OFF) (?<COLOUR>BLUE|RED|ALL) LIGHT|LIGHTS

How Tasker is set:

Here is the description of the task:

Task: Test 
Abort Existing Task
	A1: Stop [ With Error:Off Task: ] If [ %colour !Set & %state !Set ]
	A2: Variable Set [ Name:%State_led To:'%state' Do Maths:Off Append:Off ]
	A3: Variable Set [ Name:%Colour_led To:'%colour' Do Maths:Off Append:Off ]
	A4: AutoTools SSH [ Configuration:Server: 192.168.0.3
		Port: 32
		Username: pi
		Password: *******
		Command: python /home/pi/Documents/My\ Scripts/led.py %Colour_led %State_led
		Command Variable: atsshresult Timeout (Seconds):60 ]
	A5: Say [ Text:Ok the %colour will get turned %state 
		Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 
		Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]

And the Raspberry?

If you must – the set up is rather simple, as it was just to show the effect of the RegEx visually.

import RPi.GPIO as GPIO
import sys

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#Blue LED
GPIO.setup(26,GPIO.OUT)
#Red LED
GPIO.setup(21,GPIO.OUT)

def lights_on(pin):
	GPIO.output(pin,GPIO.HIGH)
	
def lights_off(pin):
	GPIO.output(pin,GPIO.LOW)

def turn_light(colour, state):
	if state == 'off' and colour == 'all':
		led_all = [21,26]
		
for x in led_all:
	lights_off(x)
	elif state == 'off' and colour == 'blue':
		lights_off(21)
	elif state == 'off' and colour == 'red':
		lights_off(26)
	elif state == 'on' and colour == 'all':
		led_all = [21,26]
for x in led_all:
		lights_on(x)
	elif state == 'on' and colour == 'blue':
		lights_on(21)
	elif state == 'on' and colour == 'red':
		lights_on(26)

I use AutoTools SSH action to run the function and pass to arguments as strings.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

Tasker PC control – #Tutorial 3 (Apps menu)

0
Launch apps and websites from the mobile!

Tasker PC control – #Tutorial 2 (Volume Menu)

0
If you missed the part one, I strongly recommend you to check it out. It tells you all about the framework used, and you...

How to control your PC like a boss – Tasker Project

0
Control PC, and other devices from a custom notification system.

Bluetooth battery monitor – monitor any Bluetooth battery with Tasker

0
Measure the battery use of Bluetooth devices

The Minimal & Elegant giveaway WINNERS

0
Picking the winners live! Livestream and making a Tasker Winners project!

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?