Help with speech output saying a random fact

Post your questions and help other users.

Moderator: Martin

Post Reply
dronics
Posts: 7
Joined: 19 Aug 2017 09:57

Help with speech output saying a random fact

Post by dronics » 21 Oct 2017 18:52

I'm not sure what I'm trying to do is possible but thought I'd ask you wonderful guys to see if you've got any ideas.
I've got an hourly talking flow so that every hour I'm told what time it is but I wanted to expand this and get a random fact or joke spoken after the time is spoken. I don't know if it's possible to get a flow to ask "google assistant" to return a random fact or joke or if there is another way to achieve this.
Has anyone got any ideas?
Or am I trying to do something impossible?

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Help with speech output saying a random fact

Post by digitalstone » 21 Oct 2017 20:13

I guess you should trow the "random()" function to it.
Have it coupled to a list with these facts and voila.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

dronics
Posts: 7
Joined: 19 Aug 2017 09:57

Re: Help with speech output saying a random fact

Post by dronics » 22 Oct 2017 15:01

Hi Thanks for you reply, although, I'm not sure what you mean with the random() function?

Could you explain a bit more for me please?
Thanks

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Help with speech output saying a random fact

Post by Desmanto » 22 Oct 2017 16:43

I never use google assistant, not practical for me. But I think it still can be done.

I would go with digitalstone's way. Find some source of jokes and merge them into single text file. Then use Action Init Variable Text File, use script to split them per line (using split()). Then generate random value using random(), which will return value between 0 to 1. Multiply this by number of jokes there and round it up using ceil(). You will get random number of line. Then access the random number line to the splitted list, you get the random joke which can be put at action Speech Output to have it spoken out.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply