Page 1 of 1
Updated Sonos TTS (PHP)
Posted: Tuesday 17 November 2015 0:39
by NoeXie
For everyone interested, i updated the original Sonos class to work with TTS again. Since Google is blocking API Calls we can't use that anymore. I found an alternative service with 350 free requests a day. You need a Account and API key from:
http://www.voicerss.org/
I got the update code posted on GitLab:
https://gitlab.com/J.Tocino/sonos-tts/tree/master
Readme must be helping with the setup:
https://gitlab.com/J.Tocino/sonos-tts/t ... ter#README
Got mine working now! I made a simple script that 'speaks' the weather of that day once i walk into my living room for the first time in the day. It is using Domoticz for the motion sensor. You can also make webcontrols for your Sonos with this script.
Re: Updated Sonos TTS (PHP)
Posted: Tuesday 17 November 2015 8:46
by rtna
Sounds good! I will give it a try later this week and report back in this topic.
Re: Updated Sonos TTS (PHP)
Posted: Tuesday 17 November 2015 21:22
by rtna
I made a simple script that 'speaks' the weather of that day
Can you share this script?
Re: Updated Sonos TTS (PHP)
Posted: Tuesday 17 November 2015 23:06
by G3rard
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
Re: Updated Sonos TTS (PHP)
Posted: Wednesday 18 November 2015 20:55
by NoeXie
rtna wrote:Sounds good! I will give it a try later this week and report back in this topic.
Let me know please!
rtna wrote:Can you share this script?
When i have some time i can make a more usable version. It works with cronjobs and stuff right now, not really noob friendly
G3rard wrote: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?
Thank you, nice PHP script! Mine has some basic functions to play or stop the active queue but nothing special. Great idea to play the queue afterwards. Thanks for sharing the LUA script btw!
Re: Updated Sonos TTS (PHP)
Posted: Wednesday 18 November 2015 23:52
by G3rard
Another script that I am using is a LUA time script which checks if the Sonos is still on/off so the status in Domoticz can be updated. If you switch the Sonos on/off with the button on the Sonos, the status in Domoticz is updated with this script.
You need to use the PHP files from
https://github.com/gerard33/sonos and the following files which still needs to be edited (path, names etc).
script_time_sonos.lua
Code: Select all
function execute(command)
-- returns success, error code, output.
local f = io.popen(command..' 2>&1 && echo " $?"')
local output = f:read"*a"
return output
end
commandArray = {}
str=execute('php /<your path>/sonos/domo_status.php','r')
--print(str)
--aan='<b style="color:green">aan</b>'
--uit='<b style="color:orange">uit</b>'
aan="<font color='forestgreen'>aan</font>"
uit="<font color='sandybrown'>uit</font>"
if string.find(str, "Kantoor: aan") then
print('Sonos kantoor: ' .. aan)
--print(str)
if otherdevices['Sonos kantoor']=='Off' then
commandArray['Sonos kantoor']='On'
end
else
print('Sonos kantoor: ' .. uit)
--print(str)
if otherdevices['Sonos kantoor']=='On' then
commandArray['Sonos kantoor']='Off'
end
end
if string.find(str, "Keuken: aan") then
print('Sonos keuken: ' .. aan)
--print(str2)
if otherdevices['Sonos keuken']=='Off' then
commandArray['Sonos keuken']='On'
end
else
print('Sonos keuken: ' .. uit)
--print(str2)
if otherdevices['Sonos keuken']=='On' then
commandArray['Sonos keuken']='Off'
end
end
return commandArray
domo_status.php
Code: Select all
<?php
$kantoor = file_get_contents("http://<your ip>/sonos/index.php?zone=<your zone>&action=GetTransportInfo", "r");
if ($kantoor == 1) { #1=Playing, 2=Pause, 3=Stopped
echo "Kantoor: aan";
} else {
echo "Kantoor: uit";
}
#echo $kantoor;
echo PHP_EOL;
$keuken = file_get_contents("http://<your ip>/sonos/index.php?zone=<your zone>&action=GetTransportInfo", "r");
if ($keuken == 1) { #1=Playing, 2=Pause, 3=Stopped
echo "Keuken: aan";
} else {
echo "Keuken: uit";
}
#echo $keuken;
?>
Re: Updated Sonos TTS (PHP)
Posted: Thursday 19 November 2015 0:24
by G3rard
NoeXie wrote:For everyone interested, i updated the original Sonos class to work with TTS again. Since Google is blocking API Calls we can't use that anymore. I found an alternative service with 350 free requests a day. You need a Account and API key from:
http://www.voicerss.org/
I got the update code posted on GitLab:
https://gitlab.com/J.Tocino/sonos-tts/tree/master
Readme must be helping with the setup:
https://gitlab.com/J.Tocino/sonos-tts/t ... ter#README
Got mine working now! I made a simple script that 'speaks' the weather of that day once i walk into my living room for the first time in the day. It is using Domoticz for the motion sensor. You can also make webcontrols for your Sonos with this script.
Can you share your dashboard code? I would like to reuse some parts.
Re: Updated Sonos TTS (PHP)
Posted: Tuesday 08 December 2015 10:14
by frizby66
Sorry, am a bit of a novice on PHP.
Have Domoticz running on a Pi2, am also running Homebridge on the PI and using domoticz.js to do voice control of lighting via home kit and it works well.
My key goal is to have the weather forecast for Edinburgh played each morning at a set time in my house (have wunderground virtual weather enabled in Domoticz).
Am 99% sure it is possible by reading various other posts on the site but am struggling to join the dots before making a start (don't want to kill my working system).
Is there a straight forward wiki I can follow?
Questions I have are:-
Should I or can I run PHP on the PI2 along with Domoticz & Homebridge?
How do I get the forecast from wunderground to TTS to Sonos (assuming I get Sonos running)?
Any help would be appreciated
Re: Updated Sonos TTS (PHP)
Posted: Friday 15 January 2016 19:46
by HansLe
Hi, I tried to approach my Sonos system via this option. And to be honest. It works great on a windows system!!!!
I installed XAMPP before so the webserver and PHP were available. The basis functions play and stop are working, TTS to go. I hope you can help me with TTS. I'm struggling with these two lines:
'messagePath' => '//<yourpath>/sonos/spraak/',
'messageStorePath' => '//<yourpath>/sonos/spraak/',
I tried several options but I don't know what to enter?!?!?
I have a localhost with a webdirectory sonos.
I have a directory D:\xampp\htdocs\sonos\spraak with a MP3 file, 1.mp3. I've also defined this directory as a music libary in my sonos system.
==== Edit ====
I discovered wich path to use. Start SONOS on your PC. Via "Selecteer een muziekbron" , select "Muziekbiblioteek", select "mappen" and then you see the names. For exampe "//MYPC/spraak". Use as path "//MYPC/spraak".
Re: Updated Sonos TTS (PHP)
Posted: Sunday 29 January 2017 14:07
by pollefinario
I've now also included the PHP tool to get TTS support. Got it to only after figuring out that "special characters" don't get passed thru the song for sonos. Any tips?