Tasker: Get Voice Command
The way I decided to set up Tasker is to use some reusable tasks that can be called from other places. The first one I'll talk about is the Get Voice Command. This task listens for some stock commands like "yes", "no", "cancel", or "repeat". It is a quicker listener than the "Get Voice Input" command which I'll talk about in another post. This is meant some some quick one or two word commands. It uses regular expressions to match commands (meaning, you can say "yep" or "yeah" or "yes sir" and it will return "yes"). Being generic like this means that I don't have to duplicate all these regular expressions everywhere. I can just call this task and if it returns "yes", then I know the user (me) said something like "yes" or "yeah" or whatever.
There's an input parameter to the task of the message to speak before listening for the answer. The task will return "yes" or "no" or "cancel" or "repeat" or "no_input_detected" (with the underscores - so there's no way to "speak" that) if it didn't detect any input for 3 tries (that way, I prevent getting into an infinite loop). If something else was detected (if I said "Bob" for example) then whatever else was detected will be returned. So, technically, this could be used for any kind of input, but it is meant for quick commands. The other task will differentiate between "yes" and "yes sir" and "affirmative", where this task will treat all those the same.
Here's the task in Tasker's nomenclature. Note that this uses Auto Voice. It is assumed that the Continuous Mode for Auto Voice is TURNED OFF - otherwise, the text that is spoken at the start of this task will be interpreted by the Continuous Mode of Auto Voice as input. It gets really confusing. In another task I'll talk about how this Continuous Mode is turned off and on. Remember, this task is not a stand-alone task -- it is meant to be called from elsewhere. So it's not the responsibility of this task to check for Auto Voice Continuous.
Get Voice Command (4)
A1: Variable Set [ Name:%count To:0 Do Maths:Off Append:Off ]
A2: Say [ Text:%par1 Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A3: AutoVoice Recognize [ Configuration:
Prompt Text: %par1
Language Model: Free Form
Voice command without headset
Command: "all" Package:com.joaomgcd.autovoice Name:AutoVoice Recognize Timeout (Seconds):10 Continue Task After Error:On ]
A4: If [ %avcomm !Set ]
A5: Variable Add [ Name:%count Value:1 Wrap Around:0 ]
A6: If [ %count eq 3 ]
A7: Say [ Text:No input detected. Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A8: Return [ Value:no_input_detected Stop:On ]
A9: Stop [ With Error:Off Task: ]
A10: End If
A11: Say [ Text:No input detected. Try again. Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A12: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A13: Goto [ Type:Action Number Number:2 Label: ]
A14: End If
A15: Variable Set [ Name:%yes To:(\W|^)(yes|yes sir|yeah|yup|yes mam|acknowledge|agree|affirmative|good|okay|ok|okie dokie|true|yea|yep|yet|aye|by all means|certainly|of course|very well|absolutely|send)(\W|$) Do Maths:Off Append:Off ]
A16: Return [ Value:yes Stop:On ] If [ %avcomm ~R %yes ]
A17: Variable Set [ Name:%nope To:(\W|^)(no|now|negative|absolutely not|no way|never|not at all|negatory|nullify|nada)(\W|$) Do Maths:Off Append:Off ]
A18: Return [ Value:no Stop:On ] If [ %avcomm ~R %nope ]
A19: Variable Set [ Name:%cancel To:(\W|^)(quit|cancel|eighty six|exit|void|forget it|nix|reject|refuse|skip)(\W|$) Do Maths:Off Append:Off ]
A20: Return [ Value:cancel Stop:On ] If [ %avcomm ~R %cancel ]
A21: Variable Set [ Name:%repeat To:(\W|^)(repeat|say again|huh|what)(\W|$) Do Maths:Off Append:Off ]
A22: Return [ Value:repeat Stop:On ] If [ %avcomm ~R %repeat ]
A23: Return [ Value:%avcomm Stop:On ]
There's an input parameter to the task of the message to speak before listening for the answer. The task will return "yes" or "no" or "cancel" or "repeat" or "no_input_detected" (with the underscores - so there's no way to "speak" that) if it didn't detect any input for 3 tries (that way, I prevent getting into an infinite loop). If something else was detected (if I said "Bob" for example) then whatever else was detected will be returned. So, technically, this could be used for any kind of input, but it is meant for quick commands. The other task will differentiate between "yes" and "yes sir" and "affirmative", where this task will treat all those the same.
Here's the task in Tasker's nomenclature. Note that this uses Auto Voice. It is assumed that the Continuous Mode for Auto Voice is TURNED OFF - otherwise, the text that is spoken at the start of this task will be interpreted by the Continuous Mode of Auto Voice as input. It gets really confusing. In another task I'll talk about how this Continuous Mode is turned off and on. Remember, this task is not a stand-alone task -- it is meant to be called from elsewhere. So it's not the responsibility of this task to check for Auto Voice Continuous.
Get Voice Command (4)
A1: Variable Set [ Name:%count To:0 Do Maths:Off Append:Off ]
A2: Say [ Text:%par1 Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A3: AutoVoice Recognize [ Configuration:
Prompt Text: %par1
Language Model: Free Form
Voice command without headset
Command: "all" Package:com.joaomgcd.autovoice Name:AutoVoice Recognize Timeout (Seconds):10 Continue Task After Error:On ]
A4: If [ %avcomm !Set ]
A5: Variable Add [ Name:%count Value:1 Wrap Around:0 ]
A6: If [ %count eq 3 ]
A7: Say [ Text:No input detected. Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A8: Return [ Value:no_input_detected Stop:On ]
A9: Stop [ With Error:Off Task: ]
A10: End If
A11: Say [ Text:No input detected. Try again. Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]
A12: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A13: Goto [ Type:Action Number Number:2 Label: ]
A14: End If
A15: Variable Set [ Name:%yes To:(\W|^)(yes|yes sir|yeah|yup|yes mam|acknowledge|agree|affirmative|good|okay|ok|okie dokie|true|yea|yep|yet|aye|by all means|certainly|of course|very well|absolutely|send)(\W|$) Do Maths:Off Append:Off ]
A16: Return [ Value:yes Stop:On ] If [ %avcomm ~R %yes ]
A17: Variable Set [ Name:%nope To:(\W|^)(no|now|negative|absolutely not|no way|never|not at all|negatory|nullify|nada)(\W|$) Do Maths:Off Append:Off ]
A18: Return [ Value:no Stop:On ] If [ %avcomm ~R %nope ]
A19: Variable Set [ Name:%cancel To:(\W|^)(quit|cancel|eighty six|exit|void|forget it|nix|reject|refuse|skip)(\W|$) Do Maths:Off Append:Off ]
A20: Return [ Value:cancel Stop:On ] If [ %avcomm ~R %cancel ]
A21: Variable Set [ Name:%repeat To:(\W|^)(repeat|say again|huh|what)(\W|$) Do Maths:Off Append:Off ]
A22: Return [ Value:repeat Stop:On ] If [ %avcomm ~R %repeat ]
A23: Return [ Value:%avcomm Stop:On ]
Comments
Post a Comment