HomeTaskerAutoVoice - 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

Charge Test – Tasker charger performance tool

0
Turning Tasker into productive tool for monitoring chargers

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)?