We have moved at community.getvera.com

Author Topic: Text To Speech (TTS) With Sonos - Creating Dynamic Messages  (Read 90111 times)

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #165 on: February 06, 2015, 07:41:59 pm »
@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

Offline Dnomyar220

  • Sr. Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #166 on: February 12, 2015, 03:51:52 pm »
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
« Last Edit: February 12, 2015, 04:23:04 pm by Dnomyar220 »

Offline becky

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +3/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #167 on: February 14, 2015, 03:35:07 pm »
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)
« Last Edit: February 15, 2015, 06:30:13 pm by becky »

Offline JoeyD

  • Sr. Member
  • ****
  • Posts: 410
  • Karma: +36/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #168 on: February 16, 2015, 01:41:15 pm »
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. :)

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.

Offline becky

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +3/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #169 on: February 17, 2015, 08:41:59 am »
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!

Offline kiethr

  • Full Member
  • ***
  • Posts: 110
  • Karma: +1/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #170 on: February 17, 2015, 10:35:52 am »
Hey Becky,  I'm interested in having my sonos system speak my calendar events. Is there any way you would share your code?

Offline becky

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +3/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #171 on: February 17, 2015, 10:47:24 am »
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.

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


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)
« Last Edit: February 17, 2015, 10:52:18 am by becky »

Offline becky

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +3/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #172 on: February 17, 2015, 11:37:19 am »
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. :)

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.

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!

Offline kiethr

  • Full Member
  • ***
  • Posts: 110
  • Karma: +1/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #173 on: February 17, 2015, 06:09:17 pm »
Thanks becky, I have those apps already installed along with say the weather. There all great and really round off my automation project.

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #174 on: March 14, 2015, 04:02:14 pm »
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?

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #175 on: March 14, 2015, 04:28:28 pm »
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

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #176 on: March 14, 2015, 04:53:55 pm »
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

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)
« Last Edit: March 14, 2015, 05:16:52 pm by tomgru »

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #177 on: March 14, 2015, 05:56:10 pm »
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: [Select]
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)
« Last Edit: March 14, 2015, 07:07:52 pm by Brientim »

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #178 on: March 14, 2015, 09:35:35 pm »
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: [Select]
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)

worked perfectly.  thanks!!!! 

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #179 on: March 14, 2015, 09:40:47 pm »
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