Text To Speech (TTS) With Sonos - Creating Dynamic Messages

Oh I see what youre saying, let me give that a shot. No I was using the one that was originally posted as the one to use.

AHHH, it worked ! thanks you so much for your help

That is fine… Now you have one working start on the next. Compare the changes I pointed out and for most, it will only require the Device id being updated. Good luck

Yes most definitely now I have an idea of how and what needs to change from the code. one more question if I wanted to assign a volume to it, what command and where would i put it? Also is there a pdf file somewhere that addresses all of the different code and syntax for luup?

Look here for volume example
http://forum.micasaverde.com/index.php/topic,12408.msg94695.html#msg94695
:

http://wiki.mios.com/index.php/Luup_Lua_extensions

http://forum.micasaverde.com/index.php?topic=18679.5

@RexBeckett also has created a Lua test tool which will no doubt assist . It is referenced out at the bottom of the last link but for ease of reference
http://forum.micasaverde.com/index.php/topic,24018.0.html

Is anyone having trouble with the Sonos plugin with the latest firmware update to UI7? Mine no longer will connect to the sonos, even though the static IP of the sonos connect is listed in the settings.

edit: a few resets in a row seem to have fixed this, if anyone else has the same issue. All is well ;D

I’ve been playing around with the TTS and wanted some “morning announcements” that let our family know what’s going on for the day before we get out of bed. The latest thing I did was use the GCal3 plugin to pull our events for the day and announce them. It’s been really helpful! For my next trick, I’m hoping to figure out how to alert us to weather alerts when they happen, without it becoming annoying.

I have one hang-up and I know there has to be a simple solution that I’m missing somewhere. I can’t seem to get my times to format properly so that it doesn’t read off as a number (seven zero zero for instance instead of seven o’clock or even just 7.) Can anyone point me in the right direction, please?

url = require(“socket.url”)
local AV_DEV = 48
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local time = os.date(‘%I:%M’)
local SONOSZONES=“ALL”
local SameVolume=“true”
local TEMP_SID =“urn:upnp-org:serviceId:TemperatureSensor1”
local WUGTempHigh = luup.variable_get(TEMP_SID, “CurrentTemperature”, 33)
local currentCondition = luup.variable_get(“urn:upnp-micasaverde-com:serviceId:Weather1”, “Forecast.1.Condition”, 30)
local GS_SID = “urn:srs-com:serviceId:GCalIII”
local jsonEvents = luup.variable_get(GS_SID, “gc_jsonEvents”,52)
if ((jsonEvents == “[]”) or (jsonEvents == nil)) then
TodaysEvents=“There are no events for today.”
else
TodaysEvents=“Todays events are "
end
package.loaded.json = nil
local json = require(“json”)
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event
for i = 1,numberEvents do
startevent = eventList[ i ].eventStart
startDate = os.date(”%Y-%m-%d", startevent)
startTime = os.date(“%H:%M:%S”, startevent)
endevent = eventList[ i ].eventEnd
endTime = os.date(“%H:%M:%S”, endevent)
eventname = eventList[ i ].eventName
TodaysEvents = TodaysEvents … eventname … " . "
luup.log(event)
end
package.loaded.json = nil

luup.call_action(LS_SID, “Say”, {Text = string.format(“Good morning, Kirkwoods! It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.”, time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)

Hi Becky,

FYI, there is a specific plug-in called SayTheWeather that works along side Sonos to announce weather forecast and alerts. You might want to check that out. :slight_smile:

But to answer your question, I use a similar format that you have in your code (example, 07:00) and I don’t recall any issues with the time being read as “seven-zero-zero” or “seven hundred.” Are you sure the final statement that is being sent to Sonos TTS includes the colon in the text?

Lastly, I myself use “en” as the Google rendering language. It’s possible if you’re using a different language or dialect that it interprets “7:00” differently.

Thanks JoeyD! I wrote the script before the saytheweather plugin was available, and this is really the only the place I use that function. Eventually I want to write a script that alerts us when there is a severe weather alert, but I’m trying to limit the number of moving parts on the vera as much as I can.

I’m using “en” as the rendering language. And I tweaked the code a tad. This morning it read it as seven hundred. I’ll have to see if the “:” is in the time when it goes off to TTS, thank you for the tip!

Hey Becky, I’m interested in having my sonos system speak my calendar events. Is there any way you would share your code?

I’d be happy to! Below are the lines that are specific to the calendar device. Make sure you have installed the Gcal3 device and the sonos device first. You have to do a little searching on the forum, but are excellent plugins and have really great documentation!! (kudos to the developers) You’ll need to change my device numbers to reflect your own.

My code is a little sloppy, but it seems to work for us.
variable and device mumbo-jumbo:

url = require(“socket.url”)
local AV_DEV = 48
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local time = os.date(‘%I:%M’)
local todaydate = os.date(‘%Y-%m-%d’)
local SONOSZONES=“ALL”
local SameVolume=“true”
local TEMP_SID =“urn:upnp-org:serviceId:TemperatureSensor1”
local WUGTempHigh = luup.variable_get(TEMP_SID, “CurrentTemperature”, 33)
local currentCondition = luup.variable_get(“urn:upnp-micasaverde-com:serviceId:Weather1”, “Forecast.1.Condition”, 30)
local GS_SID = “urn:srs-com:serviceId:GCalIII”
local jsonEvents = luup.variable_get(GS_SID, “gc_jsonEvents”,52)

checking to see if there are any events for the day. if not, tell us that there are no events for today.

if ((jsonEvents == “[]”) or (jsonEvents == nil)) then
TodaysEvents=“There are no events for today.”
else
TodaysEvents="Todays events are "
end

unwrapping all the different variables in the device variable.

[b]package.loaded.json = nil
local json = require(“json”)
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

looping around the dumping the variables into an array

for i = 1,numberEvents do
startevent = eventList[ i ].eventStart
startDate = os.date(“%Y-%m-%d”, startevent)
startTime = os.date(“%H:%M:%S”, startevent)
endevent = eventList[ i ].eventEnd
endTime = os.date(“%H:%M:%S”, endevent)
eventname = eventList[ i ].eventName

if the event happens today, add it to the TodaysEvents variable. if not, don’t add it.

if (startDate == todaydate) then
TodaysEvents = TodaysEvents … eventname … " . "
luup.log(event)
end[/b]

end
package.loaded.json = nil

and then of course sending it all to the sonos device.

luup.call_action(LS_SID, “Say”, {Text = string.format(“Good morning, Kirkwoods! It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.”, time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)

[quote=“JoeyD, post:169, topic:173177”]Hi Becky,

FYI, there is a specific plug-in called SayTheWeather that works along side Sonos to announce weather forecast and alerts. You might want to check that out. :slight_smile:

But to answer your question, I use a similar format that you have in your code (example, 07:00) and I don’t recall any issues with the time being read as “seven-zero-zero” or “seven hundred.” Are you sure the final statement that is being sent to Sonos TTS includes the colon in the text?

Lastly, I myself use “en” as the Google rendering language. It’s possible if you’re using a different language or dialect that it interprets “7:00” differently.[/quote]

I just installed say the weather and I think it’s going to do exactly what I need for the severe weather alert. Thank you!!! That saves a lot of time and headache - perfect!

Thanks becky, I have those apps already installed along with say the weather. There all great and really round off my automation project.

I want to use this to say the inside temperature of my house. My challenges is that i actually don’t have any sensors that read temp, other than my Ecobee thermostat. Since Ecobee hasn’t released the ability to read their remote sensors, i have to rely on the reading from the thermostat itself. I can see this in the U15 dashboard, so i have a temp reading… but i’m not sure how to get it into this LUA.

thoughts?

Follow the example in the first post.
http://forum.micasaverde.com/index.php?topic=12408
You’ll need to Device ID and Service ID you want to read in.

Two way to identify the Service ID as described in this post http://forum.micasaverde.com/index.php/topic,12408.msg218662.html#msg218662

[quote=“Brientim, post:176, topic:173177”]Follow the example in the first post.
http://forum.micasaverde.com/index.php?topic=12408
You’ll need to Device ID and Service ID you want to read in.

Two way to identify the Service ID as described in this post http://forum.micasaverde.com/index.php/topic,12408.msg218662.html#msg218662[/quote]

Oh… that’s handy. thanks. SO, if i did that right, this is the service id:

serviceId=urn:upnp-org:serviceId:TemperatureSensor1&action=GetCurrentTemperature

Modifying the example, i’m not sure what the ‘42’ represents? Would the code look like this?

local AV_DEV = 145 ? My sonos device ID
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”

local TEMP_SID = " urn:upnp-org:serviceId:TemperatureSensor1&action=GetCurrentTemperature "
local houseTemp = luup.variable_get(TEMP_SID,“CurrentTemperature”, 42)
luup.call_action(LS_SID, “Say”, {Text = string.format("The house temperature is currently at %s degrees ", houseTemp)}, AV_DEV)

EDIT. I tried that in the test Lua field, and got “code failed”. trying to think through this, i made these edits. still failed.

local AV_DEV = 45
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local TEMP_SID = " urn:upnp-org:serviceId:TemperatureSensor1 "
local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
luup.call_action(LS_SID, “Say”, {Text = string.format("The house temperature is currently at %s degrees ", houseTemp)}, AV_DEV)

local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
From the above GetCurrentTemperature should have been CurrentTemperature
Watch out for white spaced i.e "GetCurrentTemperature "

42 represented the device ID of the Thermometer that you are reading the temperature from. Remove the two comments once you update – This is the Thermostat Device # – This is the Thermostat Device #

***************Try this with correct devices and remove comments

[code]url = require(“socket.url”)

local AV_DEV = 452 – This is the Sonos Device #
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”

local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1”
local TEMP_DEV = luup.variable_get(TEMP_SID, “CurrentTemperature”, 531) – This is the Thermostat Device #

luup.call_action(LS_SID, “Say”, {Text = string.format(“The current temperature is %s degrees”, TEMP_DEV )}, AV_DEV)[/code]

[quote=“Brientim, post:178, topic:173177”]local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
From the above GetCurrentTemperature should have been CurrentTemperature
Watch out for white spaced i.e "GetCurrentTemperature "

42 represented the device ID of the Thermometer that you are reading the temperature from. Remove the two comments once you update – This is the Thermostat Device # – This is the Thermostat Device #

***************Try this with correct devices and remove comments

[code]url = require(“socket.url”)

local AV_DEV = 452 – This is the Sonos Device #
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”

local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1”
local TEMP_DEV = luup.variable_get(TEMP_SID, “CurrentTemperature”, 531) – This is the Thermostat Device #

luup.call_action(LS_SID, “Say”, {Text = string.format(“The current temperature is %s degrees”, TEMP_DEV )}, AV_DEV)[/code][/quote]

worked perfectly. thanks!!!

So, my next question is how to get the time to sound better. i used the code in this forum, but what it says is … as an example:

“the current time is 38 minutes past oh six”… meaning 6:38pm

can i get it to say “38 minutes past 6 o’clock” ?

this is addicting. :o