I recently created a reddit thread about this topic (https://www.reddit.com/r/tasker/comments/2cnfcs/has_anyone_else_ever_created_any_generic/), but it probably makes sense to post this here too.
------------------------------------------------------------------------------
I've been working on creating various hands-free interfaces to things I do on my phone, and like any programmer doing anything like this, I quickly realized that functions would be a much better way to go for some of the more common voice input needs within a task.
For example (and my only "proof of concept" example, at the moment) is a function for a voice assistant to confirm something with the user...typically a simple yes/no response is what I've needed so far (but it could easily become more). If I'm searching through contacts and I want to confirm that the contact found is the correct contact, I might confirm with the user... If I want to send a text message and confirm the message before sending... These things shouldn't be repeated over and over. They should be as simple as a "Perform Task: Confirm" with a paramter of the question to prompt the user with...or as close to that as possible.
So, given that...here's a simple solution that I came up with earlier (but I really feel there's probably a better way). I've already thought of a few possible improvements but I'll just provide what I've tested for now.
First, I created a task called "Confirm". %par1 is the text you'd like the user to be asked. This is the generic function to be called from within a task.
1. Variable Clear: %Confirm
2. Variable Clear: %CurPrompt
3. Variable Clear: %CurQuestionID
4. If %par1 !Set
5. Flash: "When using the 'Confirm' task, you must provide the question for the user as %par1."
6. Stop
7. End If
8. If %par2 !Set
9. Flash: "When using the 'Confirm' task, you must provide the name of the calling task as %par2."
10. Stop
11. End If
12. Variable Set: %WaitingTask to %par2
13. Say: "%par1"
14. AutoVoice Set Cmd Id: Confirm
15. AutoVoice Recognize: Prompt Text: %par1
Next was the response creation. I created 2 profiles (could be more though) for the responses. One called "Confirm: Yes" and one called "Confirm: No". They each have event behavior checked and last command ID set to "Confirm". The command filter for each should be self explanatory (mine happen to be a big regex "or" list for all possible things I might say in each instance). For each of these I also went into the "advanced" AutoVoice configuration to set a variable (called "response") to a value ("Positive Response." for the yes profile and "Negative Response" for the no profile). Finally, they each call the same task called "Confirm Response":
1. Variable Set: %Confirm To %response
2. Variable Clear: %CurPrompt
3. Variable Clear: %CurQuestionID
4. Variable Clear: %WaitingTask
Lastly, I created another task called "Confirm Test" to test the function:
1. Perform Task "Confirm": %par1: "Please provide a positive or negative response.. Like yes or no"
2. Wait Until: %Confirm Is Set
3. Flash: %Confirm
I gave the above a simple voice command profile to get it started, on AutoVoice recognize "confirm". But now, without doing all of this again, I can get a simple yes/no voice prompt in any task. I can only think of a handful of use cases right now, but I feel like most everything complex has a lot of repetition that something like this would mostly eliminate.
At this point, we need some additions to allow for a catch-all (or cancel command) to help compensate for a possible state of "limbo".
For this, we need a new task called "Stop Waiting Tasks":
1. If %WaitingTask Is Set
2. Stop: %WaitingTask
3. End If
4. Variable Clear: %WaitingTask
Once we have that, lets create a new profile triggered by "AutoVoice Recognize" for "Cancel" with no last command ID set. This task should simply call "Stop Waiting Tasks". Now we can stop at any time by saying "cancel" and it won't lock us in limbo if we do.
Though, better still might be to have it repeat the same question again if the match fails so failure in the speech recognition won't necessarily disrupt the task flow (what happens if we don't say "yes", "no", or "cancel"?). For that we'll need two more variables: one for the previous question posed to the user and one for the Command ID used (since Confirm won't be our only function like this). For these, I'll use "%CurPrompt" and "%CurQuestionID".
In the "Confirm" task, we'll need to add these lines somewhere before the last line (I put mine just under the "Array Push" line):
1. Variable Set: %CurPrompt to %par1
2. Variable Set: %CurQuestionID to Confirm
Then we create one more profile, called "Failed Recognition", triggered on "AutoVoice No Match" with a Last Command ID set to "Confirm" so it only triggers during the question we care about. This should trigger a task, also called "Failed Recognition":
1. Say: "Sorry, I didn't catch that."
2. Say: "%CurPrompt"
3. AutoVoice Set Cmd Id: %CurQuestionID
4. AutoVoice Recognize: Prompt Text: %CurPrompt
Now, with all of this in place (and the modifications above in "Confirm Response"), when the "Confirm" voice command is issued, it will ask for the question and it won't stop until it's satisfied with either a response or a "cancel" command.
Given all of that... Has anyone else tackled this concept at all? What have you come up with? What all can we do to improve upon this idea here? I do realize that this became a bit of a How-To even though that wasn't the original intention. Input is still very welcome...if you can improve upon the idea, I'd love to hear about it.
--
You received this message because you are subscribed to the Google Groups "joaomgcd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joaomgcd+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.