Multiple AutoApps Auto Text Voice Task

Discussion in 'Guides / Examples / Ideas Forum' started by Synesthesiac, Mar 6, 2015.

  1. Synesthesiac

    Synesthesiac New Member

    Joined:
    Mar 6, 2015
    Messages:
    2
    Likes Received:
    0
    Below is the Tasker description of an Auto Text task I made using Autovoice and Autocontacts. I created this because I found OK Google to be lacking when it came to hands free voice texting, whether through headphones, or over bluetooth in my car. Specifically, I wanted a system of checks along the way to make sure that I was sending the right message, to the right person, without having to look at the screen. This task uses Autovoice and Autocontacts to do just that. It will walk you through all the steps of sending a voice text message, and make sure at each step that the phone is doing what you want it to. I named this task Auto Text and set up an Autovoice Profile listening for those words. So Ok Google Auto Text launches this for me. You can launch it however you like.


    Honestly, the hardest part of this was the first three, and last line of code. These java functions will check to see if the audio focus is in use (whether music, or in my case, an audiobook is playing). If it finds that music is playing it will pause whatever app is being used to play it, and resume that same app once your message is sent. I got some much needed help from a redditor figuring that one out. Without that little code, the several voice recognize actions throughout the task toggled the play/pause of the app playing music, and brought it back each time, which made it very difficult to listen for instructions and continue through the task. This method seems to pause any app for the duration of the task.


    Hopefully some of you can use this to make driving safer, and texting easier through headphones. The only real limitation that I’m aware of here (please tell me of any you find, if and when you do) is that this task is not designed to handle contacts with multiple phone numbers. I have my contact book set up so that none of my contacts have multiple numbers, so I didn’t go through the trouble. There is some documentation floating around from clever folks who have figured it out, so it’s definitely doable. This task is also easily modified to be triggered by an incoming SMS, with Tasker’s %smsrn and %smsrf variables. I have it set up so that when I’m connected in my car, a very similar task is triggered which pauses my music, tells me who sent me a message, and asks me if I’d like to reply. If I do, this exact task runs without the Autocontact part, because I already know who I’m sending the message to.


    I’m going to post the description here with some comments throughout so you have an idea of what’s doing what. And here are a link to the XML text and .xml file for import.


    XML Text File - https://drive.google.com/open?id=1Q3sbJwJrRNlTRpnN7OBaLHYRp-EN6HZcxMEfai1VJpw&authuser=0


    XML File for Import - https://drive.google.com/file/d/0BxOAJlJxyngfOUpuSkhXT3ZOMWs/view?usp=sharing



    Auto Text (89)

    Abort Existing Task

    A1: Java Function [ Return:manage Class Or Object:CONTEXT Function:getSystemService

    {AudioManager } (String) Param:audio Param: Param: Param: Param: ]

    A2: Java Function [ Return:%musicplaying Class Or Object:manage Function:isMusicActive

    {boolean} () Param: Param: Param: Param: Param: ]

    A3: Java Function [ Return:%val Class Or Object:manage Function:requestAudioFocus

    {int} (OnAudioFocusChangeListener, int, int) Param: Param:3 Param:2 Param: Param: ] If [ %musicplaying ~ true ]


    \\ These are the java functions which will check if music is playing and record that result as a true or false in the %musicplaying variable. A3 pauses the audiostream of the app which currently has the audio focus if %musicplaying is true. The final action in this task is the function which sets that app playing again, if %musicplaying was true when we started. If you run into a problem here with the music not pausing when you launch this task with OK Google, try adding a three second wait before A1. Sometimes Google pauses the music and the task starts before it starts it playing again, which gives %musicplaying a false value of false.


    A4: Say [ Text:Ok, who do you want to text? Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]

    A5: AutoVoice Recognize [ Configuration:Hide Dialog: true

    Voice command without headset

    Timeout: 10

    Command: "all" Package:com.joaomgcd.autovoice Name:AutoVoice Recognize Timeout (Seconds):120 ]


    \\ This is the first of several Say actions followed by AutoVoice Recognize actions which will ask you for input and then turn on the audiovoice listener so you can speak your reply. In this case the name of the contact you are going to text. It’s important to note that with all of these Say actions, the option to “Respect Audio Focus” must be unchecked. This will ensure that the say command is heard, even though the device media stream is currently paused or disabled. Uncheck that box and you’ll hear what’s being said :)


    A6: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]

    A7: Variable Set [ Name:%nickname To:%avcomm Do Maths:Off Append:Off ]

    A8: Goto [ Type:Action Number Number:47 Label: ] If [ %nickname ~R cancel | %nickname ~R stop | %nickname ~R quit ]


    \\ A8 is one of several actions throughout which allow you to cancel out of the task. If you say “cancel”, “stop”, “quit” or any sentence containing those words, the task will exit, resuming your music if it was playing. The only voice input which cannot cancel the task is your actual message, because I wanted to make sure a message containing any of these words didn’t wrongly exit.


    A9: Variable Split [ Name:%avcomm Splitter: Delete Base:Off ]

    A10: If [ %avcomm2 Set ]

    A11: Variable Set [ Name:%firstname To:%avcomm1 Do Maths:Off Append:Off ]

    A12: Variable Convert [ Name:%firstname Function:To Upper Case First Store Result In: ]

    A13: Variable Set [ Name:%lastname To:%avcomm2 Do Maths:Off Append:Off ] If [ %avcomm2 Set ]

    A14: Variable Convert [ Name:%lastname Function:To Upper Case First Store Result In: ]

    A15: Variable Set [ Name:%nickname To:%firstname %lastname Do Maths:Off Append:Off ]

    A16: Variable Convert [ Name:%nickname Function:To Upper Case First Store Result In: ]

    A17: Else

    A18: Variable Convert [ Name:%nickname Function:To Upper Case First Store Result In: ]

    A19: End If

    A20: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]

    A21: AutoContacts [ Configuration:Contact Name or Nickname: %nickname Package:com.joaomgcd.autocontacts Name:AutoContacts Timeout (Seconds):1000 ]

    A22: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]


    \\ Here the name you said you wanted to text (%avcomm) is assigned to the variable %nickname, which we feed to Autocontacts. Autocontacts matches that nickname to the name in your contact list and outputs the phone number into %acnumber. Autovoice is great, and %avcomm works well, so %nickname almost always gets the two word, or one word name of the person you are trying to text. Unfortunately, it reads the two words as all lowercase letters. So in A9 we split %avcomm into two variables if it is found to be two words separated by a space. Actions 10 through 19 check to see if the variable was indeed split into two words, and if it was it capitalizes both of those words and recombines them back into %nickname. If it’s not two words, the task just capitalizes %nickname and sends it to Autocontacts to be searched.


    A23: If [ %acnumber !Set ]

    A24: Say [ Text:Sorry, couldn't resolve that contact. Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]

    A25: Goto [ Type:Action Number Number:1 Label: ]

    A26: End If


    \\ This simply says that if %acnumber is not set, then the contact couldn’t be resolved and you’ll be asked to speak the name again. So if Autocontacts can’t find a match this will give you an opportunity to try again.


    A27: Say [ Text:Ok, what do you want to say to %nickname? Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]

    A28: AutoVoice Recognize [ Configuration:Hide Dialog: true

    Voice command without headset

    Timeout: 20

    Command: "all" Package:com.joaomgcd.autovoice Name:AutoVoice Recognize Timeout (Seconds):120 ]

    A29: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]

    A30: Variable Set [ Name:%textreply To:%avcomm Do Maths:Off Append:Off ]

    A31: Say [ Text:You said, %textreply. Do you want to send it or try again? Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]

    A32: AutoVoice Recognize [ Configuration:Hide Dialog: true

    Voice command without headset

    Timeout: 10

    Command: "all" Package:com.joaomgcd.autovoice Name:AutoVoice Recognize Timeout (Seconds):120 ]

    A33: Goto [ Type:Action Number Number:47 Label: ] If [ %avcomm ~R stop | %avcomm ~R cancel | %avcomm ~R quit ]


    \\ The task now asks you what you want the message of your text to be. The timeout of the recognize command here is 20 seconds, where the others are all 10. Feel free to set it longer if you expect to leave longer messages. The message text will be stored in the %textreply variable. The task will then read your message back to you and ask you if you want to send it or try again. You have another option to cancel out of the task here.


    A34: If [ %avcomm ~R send ]

    A35: Set SMS App [ App:Textra ]

    A36: Send SMS [ Number:%acnumber Message:%textreply Store In Messaging App:Off ]

    A37: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]

    A38: Say [ Text:Message sent to %nickname Engine:Voice:default:default Stream:1 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]


    \\ If you say “send” (or any sentence with send in it) your message will be sent and you’ll be told that it was. I use Textra and so A35 sets my SMS app accordingly. You can set this to whatever app you use to send your SMSs. Or remove it entirely if you use stock, or just find you don’t need it.


    A39: Else If [ %avcomm ~R again ]

    A40: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]

    A41: Goto [ Type:Action Number Number:27 Label: ]

    A42: Else

    A43: Say [ Text:Sorry, I didn't catch that. Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:Off Network:Off Continue Task Immediately:Off ]

    A44: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]

    A45: Goto [ Type:Action Number Number:31 Label: ]

    A46: End If

    A47: Java Function [ Return: Class Or Object:manage Function:abandonAudioFocus

    {int} (OnAudioFocusChangeListener) Param: Param: Param: Param: Param: ]


    \\ If you said “try again” or any sentence with “again” in it, you’ll be brought back up the task and asked again what you’d like the body of your message to be. And if your response isn’t recognized, you’ll be asked the question again. The final line will start your media playing again if it was paused when we started.
     
  2. Stupifier

    Stupifier Member

    Joined:
    Mar 10, 2015
    Messages:
    147
    Likes Received:
    6
    This is a REALLY cool setup you have. Is there a way to get this to work with Group Texts too? f I were to use this to reply to a group text, I believe it would only send a text to the individual who sent the previous message....instead of the whole group.

    I smell a possible new app.....AutoText...lol
     
  3. Synesthesiac

    Synesthesiac New Member

    Joined:
    Mar 6, 2015
    Messages:
    2
    Likes Received:
    0
    You know, I'm not sure how that would work, as I rarely group text. What shows up in the %smsrn variable when your last text is a group? It may populate with all the numbers, since at least for me the text reads as from a group of people. I don't think there would be an easy way to actually send a text to a group, but you may be able to reply. I'd love to know if you play around with it. Glad you're using this!!
     
  4. Stupifier

    Stupifier Member

    Joined:
    Mar 10, 2015
    Messages:
    147
    Likes Received:
    6
    It is a Tasker issue basically. Tasker does not populate %SMSRB upon receiving a group text. Also, Tasker only fills in %SMSRN and %SMSRF fields for JUST the individual who sent you the message....not the whole group. Pity. Tasker basically cannot handle Group Texts at all....kinda strange when you think of it....Since Tasker typically can handle EVERYTHING
     

Share This Page