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

Offline paros

  • Full Member
  • ***
  • Posts: 194
  • Karma: +6/-1
    • Husvagnhusbil
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: 9917
  • Karma: +748/-141
    • RTS Services Plugins
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: 194
  • Karma: +6/-1
    • Husvagnhusbil
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: 767
  • Karma: +37/-20
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 (22 devices, 58 scenes, 11 apps) and iobroker controlling VeraPlus with 117 zwave nodes, 8 Zigbee nodes, 7 apps, 246 vera devices, 80 scenes; VeraEdge (0 node, 26 devices, 6 App, 0 scene); Bridged to Homekit and Alexa.

Offline parkerc

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

Offline akbooer

  • Master Member
  • *******
  • Posts: 5343
  • Karma: +231/-68
  • "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.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.