Thursday, February 4, 2016

Using voice to launch all the Tasks (Updated and Improved)

While the debate over more Profiles or more Tasks is better rages on (ok, well, not raging but it's been asked), I prefer to look at it this way.  Profiles I reserve for activities I want to launch a single way, such as Ryoen Deprouw's excellent tutorial on voice searching through your apps. Other profiles are your standard headset inserted and alarm clock ones that many others have documented.

Tasks I like to keep if I want to execute an activity in more than one way, or under different circumstances.  These are usually ad-hoc on demand requests I make, but might also be set as event based.

Sometimes I feel crazy on a Saturday night and want to change my wallpaper on an hourly basis so I set a profile to do that.  But suppose I don't like it, I can create a profile shortcut to change it again or if I'm feeling too lazy to push my screen I use a voice command to launch that task.

The problem is, by default Tasks are First Letter Upper Case, while Google accepts voice inputs as first letter lower case.  And since everything in the world is case sensitive, you need a script to convert the Google input into something Tasker can handle.

BTW I can't take full credit for this, it's from Tristan Pointer's post here: https://groups.google.com/forum/#!topic/tasker/rPO3BExrwcQ.  I changed it slightly to be more general so I could use it to launch a task from my autovoice profile.

As a simple example, here is a flash executed first through a shortcut widget, and then through a voice command.



Tasker Pro over at the G+ Tasker Plugin group made it easier for everyone;

"There's a better way to go about this. I hope you will seriously consider it and add it to your article. It basically works the problem 'backwards' but is indeed a better solution.

So - I've got Tasks with all kinds of upper/lower case mixed names, including Tasks with names like "SEARCH for newest reddit comments".

That wouldn't be able to be launched using the method you outline. What WOULD work however, in a larger variety of situations, is this:

A1. Variable Set: %voice_input To: %avcommnofilter
A2. Test Tasker > Tasks Store Result In: %all_tasks
A3. Variable Set: %index To: %all_tasks(#?%voice_input)
A4. Perform Task: %all_tasks(%index)

And there it is. Four Actions. If you say "launch task play beep sound" it will launch the Task even if it's name in Tasker is "PLay BEEP SoUnD".

It is also easy to add error handling if for example the Task doesn't exist. Right after A3 could just do a "Stop If %index=0" and add a Flash Action as well, or a Say Action to say "The Task you requested does not exist".
Enjoy, here is the download for the long version since I spent like hours figuring it out :)
Voice Search Tasks

Profile: Voice Launch Task (8)
State: AutoVoice Recognized [ Configuration:Event Behaviour: true
Command: "launch task  (regex)"
Last Cmd Id Regex: false
Last Cmd Id Invert: false
Not on Normal: false
Not on Continuous: false
Contains All: false
Use Regex Replacements: false
Do Google Now Search: false ]
Enter: Launch Task (44)
A1: Variable Set [ Name:%convertthis To:%avcommsnofilter() Do Maths:Off Append:Off ]
A2: Variable Split [ Name:%convertthis Splitter: Delete Base:Off ]
A3: For [ Variable:%item Items:%convertthis() ]
A4: Variable Convert [ Name:%item Function:To Upper Case First Store Result In: ]
A5: If [ %converted Set ]
A6: Variable Set [ Name:%converted To:%converted %item Do Maths:Off Append:Off ]
A7: End If
A8: If [ %converted !Set ]
A9: Variable Set [ Name:%converted To:%item Do Maths:Off Append:Off ]
A10: End If
A11: End For
A12: Variable Split [ Name:%converted Splitter: Delete Base:Off ]
A13: Perform Task [ Name:%converted Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ]

No comments:

Post a Comment