Voice pattern
Moderator: Martin
Voice pattern
Hi
I'm trying to do something like voice assistant. For now it work for me, but i did it in this way :
1. Input speach -> I'm saying "search for images" -> input speach -> i'm saying what i want to find, so for now i need to use INPUT SPEACH two times. Is there a way to make this my "search for images" as a voice pattern ?
I want to say for example "search for images banksy" or "search for data automagic", where "search for images" and "search for data" would be a patterns. It's becouse in next step i need to use different url's for search specyfic things in google (using Open URL In Browser)
2. Second my question is if it is possible to send Input Speach value to any application ? For example to my music player or google map ? I mean to start after my voice command google map with "parameter" (where i want to go) ?
Thanks
I'm trying to do something like voice assistant. For now it work for me, but i did it in this way :
1. Input speach -> I'm saying "search for images" -> input speach -> i'm saying what i want to find, so for now i need to use INPUT SPEACH two times. Is there a way to make this my "search for images" as a voice pattern ?
I want to say for example "search for images banksy" or "search for data automagic", where "search for images" and "search for data" would be a patterns. It's becouse in next step i need to use different url's for search specyfic things in google (using Open URL In Browser)
2. Second my question is if it is possible to send Input Speach value to any application ? For example to my music player or google map ? I mean to start after my voice command google map with "parameter" (where i want to go) ?
Thanks
Re: Voice pattern
Hi,
1. You could use regular expressions with capturing groups to analyse the text. Something like this should work:
-action Input Speech
-action Script
-condition Debug Dialog (to show the variables and the contents)
The first line of the script just creates an empty list that will hold the extracted capturing groups of the function call matches. The first element in the list contains the complete text, the second element (index=1) contains the element of the first capturing group.
Depending on patterns you could also simplify the script:
2. Action Start Activity with action set to android.intent.action.SEARCH and Extras set to putString("query", value_to_search); could work when the target app supports the search function. You could also use Explicit Component to send the search query to a particular app only. Action Start Activity contains some more examples to trigger different kind of searches in other apps.
Regards,
Martin
1. You could use regular expressions with capturing groups to analyse the text. Something like this should work:
-action Input Speech
-action Script
Code: Select all
groups = newList();
if(matches(value, "search for images (.*)", groups))
{
images_to_search = getElement(groups, 1);
}
else if(matches(value, "search for data (.*)", groups))
{
data_to_search = getElement(groups, 1);
}
The first line of the script just creates an empty list that will hold the extracted capturing groups of the function call matches. The first element in the list contains the complete text, the second element (index=1) contains the element of the first capturing group.
Depending on patterns you could also simplify the script:
Code: Select all
groups = newList();
if(matches(value, "search for (image|data) (.*)", groups))
{
type_of_search = getElement(groups, 1);
value_to_search = getElement(groups, 2);
}
2. Action Start Activity with action set to android.intent.action.SEARCH and Extras set to putString("query", value_to_search); could work when the target app supports the search function. You could also use Explicit Component to send the search query to a particular app only. Action Start Activity contains some more examples to trigger different kind of searches in other apps.
Regards,
Martin
Re: Voice pattern
Thank you very much. I will try this way 
Thanks

Thanks
Re: Voice pattern
Hi
I did it as in your example. For now in debug window i have everything ok, so images_to_search it is "banksy" (without quotes), but when i'm using Start Activity (i use Dolphin browser), in my browser i have "Null", not my "banksy".
Anyway google want to know that i want to search for images something like this :
"https://www.google.pl/search?hl=pl&site ... 5&q=banksy", so i tried to "convert" images_to_search to value fo to get something like this :
"https://www.google.pl/search?hl=pl&site ... bih=955&q={value}", but for now this what i get, is whole "search for images banksy" (in browser).
I did it as in your example. For now in debug window i have everything ok, so images_to_search it is "banksy" (without quotes), but when i'm using Start Activity (i use Dolphin browser), in my browser i have "Null", not my "banksy".
Anyway google want to know that i want to search for images something like this :
"https://www.google.pl/search?hl=pl&site ... 5&q=banksy", so i tried to "convert" images_to_search to value fo to get something like this :
"https://www.google.pl/search?hl=pl&site ... bih=955&q={value}", but for now this what i get, is whole "search for images banksy" (in browser).
Re: Voice pattern
Hi,
Did you add the correct variable into the intent extra? It seems like you used the variable images_to_search so the extras in action Start Activity should be set to:
putString("query", images_to_search);
Also watch out for typos. Scripts are case sensitive so the variable should be written all lower case.
Please share the flow if it still fails. To do this, open the forum in Automagic and use the dark green button Publish Flows/Widgets. You can paste the generated link in a reply. Please ensure that the flow does not contain personal information.
Regards,
Martin
Did you add the correct variable into the intent extra? It seems like you used the variable images_to_search so the extras in action Start Activity should be set to:
putString("query", images_to_search);
Also watch out for typos. Scripts are case sensitive so the variable should be written all lower case.
Please share the flow if it still fails. To do this, open the forum in Automagic and use the dark green button Publish Flows/Widgets. You can paste the generated link in a reply. Please ensure that the flow does not contain personal information.
Regards,
Martin
Re: Voice pattern
I see that you use an upper case I in the script action: Images_to_search = ... but use a lowercase i in the action Start Activity. Variables are case sensitive so it does matter if you use I or i.
Re: Voice pattern
Hi
Thank you very much.
I will try when i'll have my phone
Thanks
Thank you very much.
I will try when i'll have my phone

Thanks
Re: Voice pattern
HiMartin wrote:I see that you use an upper case I in the script action: Images_to_search = ... but use a lowercase i in the action Start Activity. Variables are case sensitive so it does matter if you use I or i.
I have already my phone back so i can to try. I changed this "i" letter and now my contetnt is properly sent to browser, but even when i'm searching for images it not open in google graphic tab. I'm still in normal search window. It look like google don't know i'm searching exactly for images.
Re: Voice pattern
Hi,
How are you launching the search in your flow, using the Start Activity: ...WEB_SEARCH? In this case you could also switch to an action Open URL in Browser with a URL like https://www.google.ch/search?q={images_ ... }&tbm=isch. Note that the value needs to be properly encoded when it contains spaces etc. so the URL should look like this:
https://www.google.ch/search?q={encodeU ... }&tbm=isch
Regards,
Martin
How are you launching the search in your flow, using the Start Activity: ...WEB_SEARCH? In this case you could also switch to an action Open URL in Browser with a URL like https://www.google.ch/search?q={images_ ... }&tbm=isch. Note that the value needs to be properly encoded when it contains spaces etc. so the URL should look like this:
https://www.google.ch/search?q={encodeU ... }&tbm=isch
Regards,
Martin