Being bilingual can be a curse at times. I have BT headset (LG Tone) which I often use when cycling, to listen to the music. LG companion app allows for the notifications to be spoken through the headset. This is great, however, every time my Polish friend messages me – it feels like cursing in an ancient language. I decided to put an end to this and show you at the same time how to use variables and plug-ins with Tasker to create bilingual headset notifications. This profile can be used with headsets, Bluetooth headsets or just as a car profile.
For the sake of this tutorial, we will be using Autonotification plug-in.
Autonotification is one of the most useful plug-ins available. It allows you to create rich, custom notifications on your screen, and read existing notifications, then store its content inside local variables. This can be used to process the data from notifications in your tasks, or creating elaborate notification trees with buttons, icons, and information.
We are going to use an event condition to intercept notifications from Messenger (Facebook), Whatsapp and Hangouts. If you want to add more, just follow the steps accordingly. In profiles, select plug-in Autonotification – Intercept to respond to each notification from selected apps and gather information from these notifications in local variables. Once notification appears on our screen, Tasker will have a variable available to be used in a task.
Action Say allows the headset notifications profile to select the text to be spoken out loud, and language we want to use. By default, it will be set to your mobile’s language. As our profile is using Autonotification, new variables will be available to us. %antitle will store the name of the person who sent us a message and %antext is responsible for storing the body of the text message. Entering both variables in Say field will read the content of the variable once the message is received.
To select correct language press magnifying glass, then select language of your choice. Copy this entry, as we will use a variable %leng to store information about what language we want to use to play this message.
Create 2 actions (or more for more languages), both Variable Set, one for each language. Set variable %lang to values copied from the TTS setting. One of this tasks will be run, depending on our Replace search result.
Add another action Variable Search Replace. This allows us to pick a variable (%AlterLanguage) and look up its content for a specific information. %AlterLanguage will contain a list of names of our contacts (in my case my Polish friends). We will be checking our %antitle which contains the name of the person who messages us against this list. When a match is found, we will store it in the %foundone array. Select ‘multiline’ and ‘one match only’ and you are ready to go to the last step.
When name from %antitle matches one of the lines in %AlterLanguage -as a result, it populates an array with each match. As we are looking for one match only, the first variable in this array will be filled %foundone1. If this variable is set, we want our TTS setting to speak Polish, otherwise English. Go to the task and Variable Set %lang use IF condition to IS SET/NOT SET to allow selection of the correct language. In my example, TTS in Polish is SET and TTS in English is NOT SET.
Make sure all actions are set in the right order and you are ready to try it. Each name added to %AlterLanguage needs to be the exact spelling of your contact from the phonebook. Each contact must be on the new line of this variable. You can also use Read/Write File action to store the list in a file.
Received Message (9)
A1: Variable Search Replace [ Variable:%AlterLanguage Search:%antitle Ignore Case:Off Multi-Line:On One Match Only:On Store Matches In:%foundone Replace Matches:Off Replace With: ]
A2: Variable Set [ Name:%lang To:com.google.android.tts:pol-pol Do Maths:Off Append:Off ] If [ %foundone1 Set ]
A3: Variable Set [ Name:%lang To:com.google.android.tts:eng-gbr Do Maths:Off Append:Off ] If [ %foundone1 !Set ]
A4: Say [ Text:%antext Engine:Voice:%lang Stream:3 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]
In conclusion I hope this clarifies a bit more how to use variables and plug-ins, and also removes the entertaining mispronunciations of google’s TTS. As always, links to the headset notification profile xml files is here.