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

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2474
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #15 on: November 17, 2012, 05:59:22 pm »
Another new one for anyone who is interested..

Sonos Period Of The Day Greetings

This one will check the time of day and then great you with either Good Morning, Good Afternoon or Good Evening

Code: [Select]
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris"

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end
« Last Edit: November 17, 2012, 06:09:51 pm by parkerc »

Offline allmoney.ws

  • Full Member
  • ***
  • Posts: 105
  • Karma: +0/-0
  • Vera 3
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #16 on: December 08, 2012, 07:18:31 pm »
Can it speak in Russian?

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2474
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #17 on: December 09, 2012, 03:03:59 am »
This suggests it does, http://googletranslate.blogspot.co.uk/2010/05/giving-voice-to-more-languages-on.html) - so have a go with the Sonos Plugin and try changing the language values in the 'say' command

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #18 on: December 09, 2012, 11:25:42 am »
If I give it this string:
    Я хотел бы немного водки

It makes the attached TTS version of it.  I have no idea if this is the correct translation, but the original english string, prior to auto-translation, was:
   I would like some vodka

(rename attachment from Say.jpg to Say.mp3 to play it)

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #19 on: December 09, 2012, 01:57:01 pm »
 ;D for the example.

Offline hek

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 714
  • Karma: +60/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #20 on: December 11, 2012, 03:51:32 pm »
My little snippet used when someone calls us... Feel free to modify for your needs...
This code works in Sweden.. but there is probably similar services in other countries that can be used for looking up phonenumbers.


Code: [Select]
--
-- Uses the swedish number-to-name service 188100.se to lookup who is calling (using Fritz!Box integration)
-- and announce it in your sonos speaker system
--
-- You need to install xpath.lua (found here: http://code.mios.com/trac/mios_genericutils/browser)
-- under /usr/lib/lua/ of your vera unit
--
-- Update the following parameters below:
--   apiKey118100 - Your personal api key requested here: http://utveckling.118100.se/node/10
--   AV_DEV - sonos device id
--   FB_DEV - Fritz!Box device id
--   sayText - Text you want the sonos to say (%s = name of caller)
--   sayLang - Laguage (sv = swedish, en=english, ...)
--   sayVolume - Volume of the announcement
--

local url = require("socket.url")
local xp = require ("xpath")
local lom = require ("lxp.lom")
local http = require('socket.http')

local AV_DEV = 115
local FB_DEV = 122
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local FB_SID = "urn:hek:serviceId:FritzBox1"
local apiKey118100 = "XXXXXXXXXXXXXX.XXXXXXXX"
local serviceUrl = "http://developer.118100.se:8080/openapi-1.1/appetizing?query=%s&key=%s"
local sayTextPrivate = "%s %s is calling"
local sayTextCompany = "The company %s is calling"
local sayLang = "sv"
local sayVolume = 30
local number = luup.variable_get( FB_SID, "Number", FB_DEV)

http.TIMEOUT = 5
luup.log("Incoming number: " .. number)
local result = http.request(string.format(serviceUrl, number, apiKey118100))

local lomobj = lom.parse(result)
local firstName = xpath.selectNodes(lomobj,"//individual/name[@type='first']/text()")[1]
local lastName = xpath.selectNodes(lomobj,"//individual/name[@type='last']/text()")[1]
local company = xpath.selectNodes(lomobj,"//company/name[@type='legal']/text()")[1]
local sayText = ""
if company then
    sayText = string.format(sayTextCompany, company)
else
    sayText = string.format(sayTextPrivate, firstName, lastName)
end


luup.log("Saying: " .. sayText)
luup.call_action(LS_SID, "Say", {Text = sayText, Language=sayLang, Volume=sayVolume}, AV_DEV)

Offline turnerg100

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #21 on: January 12, 2013, 11:28:11 pm »
I cannot get the Say function in the device interface to work, though the device works fine with Sonos radio channels and other files. When I enter say "welcome home" and run it, an MP3 is called but no no sound plays, as if the MP3 is a blank recording.

Any ideas? Thank you!

Offline hek

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 714
  • Karma: +60/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #22 on: January 13, 2013, 05:02:28 am »
Does your Vera have internet accces?

Offline turnerg100

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #23 on: January 13, 2013, 09:47:58 am »
It does. I can stream pandora through sonos and write you now... etc. Using vera 3 as my wireless router.

Any ideas? Thank you!

Offline hek

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 714
  • Karma: +60/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #24 on: January 13, 2013, 12:47:10 pm »
Weird.. And your Sonos speakers is also plugged into Vera?

I've got a Vera Light so there is another network topology.. The Say command uses some "magic" to get the Vera ipnumber which is needed to let your sonos speakers find the generated mp3.
I hope this magic works for Vera 3 aswell.... @guessed... you also run Vera3 right?

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #25 on: January 13, 2013, 03:39:20 pm »
See the other thread, since it looks like a similar issue:
    http://forum.micasaverde.com/index.php/topic,13232.0.html

Offline allmoney.ws

  • Full Member
  • ***
  • Posts: 105
  • Karma: +0/-0
  • Vera 3
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #26 on: January 30, 2013, 06:11:38 pm »
Any way to say temperature from weather.com, google search results or other services?

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #27 on: January 31, 2013, 12:37:15 am »
As the work is already done with the Weather plugin you could install that and then use something similar to this *(which has maintained the conventions of the previous Say Temp).

Code: [Select]
url = require("socket.url")

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

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", Weather Underground Temperature DeviceId)

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)



Offline allmoney.ws

  • Full Member
  • ***
  • Posts: 105
  • Karma: +0/-0
  • Vera 3
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #28 on: January 31, 2013, 02:55:17 am »
As the work is already done with the Weather plugin you could install that and then use something similar to this *(which has maintained the conventions of the previous Say Temp).

Code: [Select]
url = require("socket.url")

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

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", Weather Underground Temperature DeviceId)

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)

Thanks a lot!
But why it say only 1st string, if I insert 2 lines, for example:

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)
luup.call_action(LS_SID, "Say", {Text = string.format("Tomorrow will be %s degrees", WUGTemp1 )}, AV_DEV)

?

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #29 on: January 31, 2013, 03:46:34 am »
You can have it get, return and say multiple variable as long as they are available.
You just need to declare where there are coming from... Once again, I will say with the precedence that has been displayed in previous posts.

E.g.
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

So, in the example below
377 is the Sonos and the remaining are other devices that have a Variable called CurrentTemperature



Code: [Select]
url = require("socket.url")

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

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local RoomTemp1 = luup.variable_get(TEMP_SID,"CurrentTemperature", 389)
local RoomTemp2 = luup.variable_get(TEMP_SID,"CurrentTemperature", 36)
local RoomTemp3 = luup.variable_get(TEMP_SID,"CurrentTemperature", 381)
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

luup.call_action(LS_SID, "Say", {Text = string.format("Bedroom1 is currently %s degrees  Room2 is currently at %s degrees, Room3 is currently %s degrees the outside is currently %s degrees" and the maximum excepted today is %s degrees, RoomTemp1,RoomTemp2,RoomTemp3,WUGTempCurrent,WUGTempHigh )}, AV_DEV)