We have moved at community.getvera.com

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

Offline charlesrg

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +1/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #135 on: December 09, 2014, 10:12:57 pm »
Very good Charlesrg...

if I need change the "morning" for "afternoon" when necessary...do you have some code for this ?
thanks !!

Ok, here goes a little improvement. I found that the other code with seconds was not that neat.

Code: [Select]
local SONOS_ID = 127
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Kitchen"
local SONOS_ZONES="ALL"
local WEATHER_ID = 129
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"

local time = os.date('It is %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local weather = "The current weather is " .. weatherCurrCondition .. ". The forecast for today is " ..  weatherForecast .. " with a minimum of " .. weatherLow .. " and a maximum of " .. weatherHigh
local hour=tonumber(os.date('%H'))
local greeting=""

if  hour < 12  then
    greeting = "Good morning"
elseif hour < 17 then
    greeting = "Good afternoon"
elseif hour < 21 then
    greeting = "Good evening"
else
    greeting = "Good night"
end

luup.call_action(SONOS_SID, "Say",
                 {Text= greeting .. " Daisy and Charles. " .. time .. weather .. ". Goodbye.", Language="en", GroupZones=SONOS_ZONES,
                  Volume=15, SameVolumeForAll="true"},
                 SONOS_ID)

function pandoraOn()
    luup.call_action(SONOS_SID, "PlayURI",
                 {URIToPlay="SF:Enya Radio", GroupZones=SONOS_ZONES, SameVolumeForAll="true", Volume=15},
                 SONOS_ID)
end
luup.call_delay("pandoraOn",60)

return true
« Last Edit: December 10, 2014, 11:27:51 pm by charlesrg »

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #136 on: December 14, 2014, 11:50:38 am »
Thanks Charlesrg,

I can not hear any sound from my sonos...

I have this code working fine on my kitchen...

luup.call_action("urn:micasaverde-com:serviceId:Sonos1","Say",{Text="Ola",Language="pt", Volume=50,GroupDevices=""},111)

I put my sonos ID (111) in your code and the ID of my Weather ProviderWUI (Weather Underground) is 25...

I have tapped out the pandora function because I do not have this service...

I can not listen any sound..

what could be wrong ?

thanks for help and clarify...
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline charlesrg

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +1/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #137 on: December 15, 2014, 09:56:47 pm »
If you are on UI7 you can paste the code into the (APPS -> Develop Apps -> Test Luup Code.

Make sure the code works there before you put into your scene.

Perhaps something is wrong with your ID's. I copied and paste from my working setup.

I usually use Notepad++ to do syntax highlighting on the code so I'm sure I didn't miss any quote, try that.

Here is the code again just in case:

Code: [Select]
local SONOS_ID = 127
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Kitchen"
local SONOS_ZONES="ALL"
local WEATHER_ID = 129
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"

local time = os.date('It is %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local weather = "The current weather is " .. weatherCurrCondition .. ". The forecast for today is " ..  weatherForecast .. " with a minimum of " .. weatherLow .. " and a maximum of " .. weatherHigh
local hour=tonumber(os.date('%H'))
local greeting=""

if  hour < 12  then
    greeting = "Good morning"
elseif hour < 17 then
    greeting = "Good afternoon"
elseif hour < 21 then
    greeting = "Good evening"
else
    greeting = "Good night"
end

luup.call_action(SONOS_SID, "Say",
                 {Text= greeting .. " Hello,    excuse me, " .. greeting .. " Daisy and Charles. " .. time .. weather .. ". Goodbye.", Language="en", GroupZones=SONOS_ZONES,
                  Volume=20, SameVolumeForAll="true"},
                 SONOS_ID)

function pandoraOn()
    luup.call_action(SONOS_SID, "PlayURI",
                 {URIToPlay="SF:Enya Radio", GroupZones="ALL", SameVolumeForAll="true", Volume=20},
                 127)
end
luup.call_delay("pandoraOn",60)

return true

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #138 on: December 16, 2014, 08:16:27 am »
Please Look if your plugin (source of information) is the same I have installed...

thanks

Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline charlesrg

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +1/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #139 on: December 20, 2014, 12:31:26 am »
I'm using wundeground weather plugin for weather info and I'm on UI7.

Offline JoeyD

  • Sr. Member
  • ****
  • Posts: 410
  • Karma: +36/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #140 on: December 20, 2014, 04:45:27 pm »
I just released a plug-in for exactly this purpose!   :)  ("Speaking the weather using data from Wunderground weather app....)

 
http://forum.micasaverde.com/index.php/topic,29522.0.html

Offline teonebello

  • Sr. Member
  • ****
  • Posts: 405
  • Karma: +0/-0
  • Macs, Home Automation, Bikers
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #141 on: December 20, 2014, 08:06:21 pm »
Do you think that it could be possible to translate it also in other languages? I saw that some some phrases are editable, but I don't know if all. Thanks

Offline JoeyD

  • Sr. Member
  • ****
  • Posts: 410
  • Karma: +36/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #142 on: December 21, 2014, 11:31:39 am »
Hi teonebello,

Currently you are able to edit the phrases to whatever you'd like, but there are other aspects of the grammatical sentences that are hard coded.

I can attempt to expose these so that they can be edited as well, but the difficulty there will be the underlying difference in language semantics.  In other words, I construct a current forecast like this:

[ For the immediate forecast we are expecting] [wonderfully clear skies] [with] [almost spring like temperatures] [ranging from] [40 to 50] [degrees].

The items in bold are ones that you can currently change to whatever you want since they are based on what the incoming weather values are.  I can expose the other phrases to be user editable, and that may allow you to construct a syntatically usable statement in your language, but it may not.

It's a good suggestion, and I 'll put it on my "to-do" list.  Thanks!

« Last Edit: December 21, 2014, 11:33:10 am by JoeyD »

Offline Hernan

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #143 on: January 01, 2015, 10:55:16 pm »
Hi Guys,

I have a couple of SONOS 1, which have been pair (using SONOS APP) in order to create a stereo experience and say command does not work. SONOS plug in was setup selecting only one of the players and it works fine reproducing music and TTS on both speakers except when calling say lua command...it says nothing. 
Could someone please share some "Say" working code for a couple of SONOS players that are already grouped?

Here is what I have been trying to do:

local AV_DEV =59
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local OutTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 38)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor temperature is currently at %s degrees", OutTemp),Volume=45}, AV_DEV)

I did also try the command GroupZones="Kitchen" (Kitchen is the group name on SONOS APP) after the Volume parameter with no success.  :'(

Thanks,

Hernan

Offline Hernan

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #144 on: January 10, 2015, 12:50:21 pm »
Hi guys,

Solved. I found that paired or synced sonos needs the GroupZones set to "Current" in order to get TTS working. This is all you need GroupZones="Current" in order to make TTS working from luup code within a scene. I did also test it on my paired set of sonos 3, with no issues.

Hopefully this can help to anyone else with same issue and wondering if this tip can be included on the sonos plug-in help page.

Thanks lodomo for this awesome plug-in.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #145 on: January 10, 2015, 01:46:00 pm »
"Current" just bypasses the creation of a new group for TTS and just uses the current group setup.

Offline hkk1644

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #146 on: February 05, 2015, 09:23:39 pm »
I can see all the luup code that needs to be put in but is there anyone that can point out if anything else needs to be done? like what needs to change in the loop code to have it work with peoples veras? changing the name of the sonos maybe? or is there an id that needs to change?  do i need to do anything in the advance tab, like add the sonos and pick a command?

All I see is code for the luup and ive tried pasting that into a scene and running it but nothing will happen.  any help would be appreciated.

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #147 on: February 05, 2015, 11:33:53 pm »
Quote
See below extracts for what you may need to change
Code: [Select]

local LI_DEV1 = 82  *1 In this case the Device_Id for the the light and is reference later
local AV_DEV = 5 *2 This is the Sonos Device_Id and is reference later,
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local livingroomlight = luup.variable_get(SEC_SERV, "Status",LI_DEV2)  *1 LI_DEV2

luup.call_action(LS_SID, "Say", {Text = string.format("All lights are off ")}, AV_DEV) *2 AV_DEV

Otherwise you may see it like this
Code: [Select]


local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local livingroomlight = luup.variable_get(SEC_SERV, "Status",82) Note as it is not declared

luup.call_action(LS_SID, "Say", {Text = string.format("All lights are off ")}, 5) Note as it is not declared


Offline hkk1644

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #148 on: February 06, 2015, 12:11:41 pm »
So all that needs to be done is putting in the luup code?  no devices in the advance tab need to be selected?  also i kind of see where the name of the sonos needs to be changed.  Is there someone who has a video of doing this? maybe just a walk through of putting in the code?

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #149 on: February 06, 2015, 02:10:35 pm »
In the first post is the links to the code for various functional examples.

Really, that is it at the moment. You need to get the device Id that match you Vera and look in the example in the logical places I pointed you too.  Look for numbers.

If it does not work and you need more help, come back here, but ensure you paste the code you are trying to fix. From there someone will assist identify what you need to look at, such as Services and how to  verify other aspects of data required.