Thanks for sharing. Great to see some more Sonos options for Domoticz.
I have also changed from Google to voicerrs.org in the PHP scripts that I am using. I have posted these on Github
https://github.com/gerard33/sonos.
When playing a TTS, this PHP stops the current playing radio/list, plays the message and then continues the previously played radio/list.
I also tried the PHP source that you have used, but I believe the stopping and continuing is not supported?
I have made a TTS function which can be used in LUA scripts, maybe it is useful for someone. I use the IDX number of the Sonos switch in Domoticz in the config file (config.php), so I can use this on the frontpage which sends commands based on the IDX.
Code: Select all
function PlayTTS(text, zone, volume)
--Sonos setting
sonoskantoor = 115
sonoskeuken = 116
vol_def = 4
zonetext = "onbekend"
--example: PlayTTS('Hier de tekst', 'kantoor', 4)
if (text == nil or text == "") then text = 'geen tekst ingevoerd' end
if (zone == nil or zone == "") then zone = sonoskantoor end --kantoor
if (zone == 'kantoor' or zone == 'Kantoor') then zone = sonoskantoor end --kantoor
if (zone == 'keuken' or zone == 'Keuken') then zone = sonoskeuken end --keuken
if (volume == nil or volume == "") then volume = vol_def end
if zone == sonoskantoor then zonetext = 'Kantoor' end --replace number to text for print
if zone == sonoskeuken then zonetext = 'Keuken' end --replace number to text for print
if zone == 'all' or zone == 'All' then zonetext = 'Kantoor en Keuken' end --play on all known Sonos boxes
print('PlayTTS - Tekst: ' .. text .. ' | Zone: ' .. zonetext .. ' | Volume: ' .. volume)
text = string.lower(text) --lowercase needed for playing TTS
text = string.gsub(text, "%s+", '%%20') --replace spaces with %20 needed for playing TTS with this function
if (zone == 'all') then
local play = 'curl --url "http://<yourip>/sonos/index.php?zone=' .. sonoskantoor .. '&action=sendMessage&message=' .. text .. '&volume=' .. volume .. '" &'
os.execute(play)
local play2 = 'curl --url "http://<yourip>/sonos/index.php?zone=' .. sonoskeuken .. '&action=sendMessage&message=' .. text .. '&volume=' .. volume .. '" &'
os.execute(play2)
else
local play = 'curl --url "http://<yourip>/sonos/index.php?zone=' .. zone .. '&action=sendMessage&message=' .. text .. '&volume=' .. volume .. '" &'
os.execute(play)
end
end