Author Topic: LUA -random text  (Read 739 times)

Offline paros

  • Full Member
  • ***
  • Posts: 205
  • Karma: +6/-1
LUA -random text
« on: June 10, 2017, 02:49:42 pm »
Does someone have an example of LUA for sending TTS to Sonos or DLNA speaker?
I am using PLEG.
For example: when I open a door (with door sensor), I want the speaker to say "Hi", next time someone enters the door, the speaker should say "something else", etc.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10059
  • Karma: +759/-141
Re: LUA -random text
« Reply #1 on: June 10, 2017, 03:42:25 pm »
Are you sure you need LUA ?
The device probably has a say action you can access from the advanced actions editor.

Sent from my SAMSUNG-SM-G935A using Tapatalk


Offline paros

  • Full Member
  • ***
  • Posts: 205
  • Karma: +6/-1
Re: LUA -random text
« Reply #2 on: June 10, 2017, 04:21:26 pm »
Sorry, I meant: I want to have different/random TTS greating every time :)

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1103
  • Karma: +52/-21
Re: LUA -random text
« Reply #3 on: June 11, 2017, 08:16:36 pm »
That's a fun question actually. How many different greetings are you thinking?
I would use a random number generator and create a "text" variable which would be different for each output of the number generator.
For example if you have 10 of them"

Code: [Select]
local rand = math.random(10)
local text = ""
if rand = 1 then
text = "blah blah 1"
else if rand = 2 then
text = "blah blah 2"
... until 10
end


then run the TTS command to speak out the "text" string
openLuup (93 devices, 122 scenes, 20 apps) controlling HomeAss + VeraPlus (133 zwave nodes, 8 Zigbee nodes, 203 devices, 34 scenes , 3 apps) Bridged to Homekit and Alexa

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2405
  • Karma: +33/-45
  • Life Moves Pretty Fast....
Re: LUA -random text
« Reply #4 on: August 30, 2017, 02:03:27 pm »

Offline akbooer

  • Master Member
  • *******
  • Posts: 5869
  • Karma: +249/-69
  • "Less is more"
Re: LUA -random text
« Reply #5 on: August 30, 2017, 03:12:22 pm »
Check out this post in the "Dynamic TTS" thread

http://forum.micasaverde.com/index.php/topic,12408.msg159478.html#msg159478

Yes indeed.  I have to say that the programming implementation there for selecting different texts is somewhat cleaner than that described here.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.