Page 4 of 4
Re: Vocal announcement - Good Morning Script
Posted: Saturday 24 December 2016 13:15
by timbiker
With a little bit of help and a lot of work I have now a working announcement !
It's teaching me LUA !
Thanks !
Re: Vocal announcement - Good Morning Script
Posted: Monday 30 January 2017 13:35
by seblang
Hi
This script is a good idee
I need your help, instead of send the result in a vocal command I want to update a virtual text switch !
Below my script :
Code: Select all
commandArray = {}
local timeNow= os.date("*t")
local curl='C:\\curl\\9\\bin\\curl.exe' --METTRE ICI LE CHEMIN DE VOTRE CURL
local tts_idx =337 -- idx capteur texte pour le tts
-- ############# REMISE A ZERO DE LA VARIABLE "BONJOUR" ENTRE 6H et 7H (la variable doit être de type chaîne) #################
if (timeNow.hour >=5 and timeNow.hour <6) then
commandArray['Variable:bonjour'] = tostring (0)
end
-- ############# CONDITIONS NECESSAIRES A L'EXECUTION DU SCRIPT #################
if (otherdevices['agenda google'] == 'On' and
timeNow.hour >=6 and
uservariables["bonjour"] == '0')
then
local sentence="Bonjour ! Nous sommes le " ..(os.date("%A")).. " " ..(os.date("%d")).. " " .. os.date("%B")
-- ############# PASSAGE DU JOUR ET DU MOIS EN FRANCAIS #################
local d = {
["Monday"] = " Lundi ",
["Tuesday"] = " Mardi ",
["Wednesday"] = " Mercredi ",
["Thursday"] = " Jeudi ",
["Friday"] = " Vendredi ",
["Saturday"] = " Samedi ",
["Sunday"] = " Dimanche ",
["01"] = " premier ",
["02"] = " deux ",
["03"] = " trois ",
["04"] = " quatre ",
["05"] = " cinq ",
["06"] = " six ",
["07"] = " sept ",
["08"] = " huit ",
["09"] = " neuf ",
["January"] = " Janvier ",
["February"] = " Février ",
["March"] = " Mars ",
["April"] = " Avril ",
["May"] = " Mai ",
["June"] = " Juin ",
["July"] = " Juillet ",
["August"] = " Août ",
["September"] = " Septembre ",
["October"] = " Octobre ",
["November"] = " Novembre ",
["December"] = " Décembre " }
for k, v in pairs (d) do
sentence = string.gsub(sentence, k, v)
end
-- ############# PROGRAMME D'ENCODAGE DU TEXTE POUR LE TTS #################
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
-- ############# TEMPERATURE ET METEO #################
if (otherdevices['meteo local']) then --METTRE ICI VOTRE DEVICE DE TEMPERATURE
temperature1, hygro1, etat1= otherdevices_svalues['Température extérieure']:match("([^;]+);([^;]+)")
-- print("TEMP:"..temperature1);
-- print("HUM:"..hygro1);
end
sentence=sentence..". La température extérieure est de "..temperature1.." degré et le taux d'humidité est de "..hygro1.." pourcent. "
json = (loadfile "C:\\cURL\\9\\bin\\JSON.lua")() --METTRE ICI LE CHEMIN DU JSON
local city = "flagey-rigney"
local wuAPIkey = "XXXXXXXX"
local file=assert(io.popen(curl.. 'http://api.wunderground.com/api/'..wuAPIkey..'/forecast/lang:FR/q/France/'..city..'.json'))
local raw = file:read('*all')
file:close()
local jsonForecast = json:decode(raw)
prevision=jsonForecast.forecast.txt_forecast.forecastday[1].fcttext_metric -- Prévision complète
-- prevision=jsonForecast.forecast.simpleforecast.forecastday[1].conditions -- Prévision rapide
local t = {
["ºC"] = "degré",
[" ENE "] = " Est Nord Est ",
[" NNE "] = " Nord Nord Est ",
[" NE "] = " Nord Est ",
[" N "] = " Nord ",
[" NNO "] = " Nord Nord Ouest ",
[" NO "] = " Nord Ouest ",
[" SSE "] = " Sud Sud Est ",
[" SE "] = " Sud Est ",
[" S "] = " Sud ",
[" SSO "] = " Sud Sud Ouest ",
[" SO "] = " Sud Ouest ",
[" O "] = " Ouest ",
[" E "] = " Est ",
["km/h"] = " kilomètre heure" }
for k, v in pairs (t) do
prevision = string.gsub(prevision, k, v)
end
sentence=sentence.."Le temps de la journée sera "..prevision
-- ############# AJOUT RISQUE DE GIVRE #################
if (otherdevices_svalues['alerte givre'])=='Risque de givre' then
sentence=sentence.." Il y a peut etre du givre, soyez prudent."
elseif (otherdevices_svalues['Risque de givre'])=='Présence de givre !' then
sentence=sentence.." Attention il y a du givre, soyez très prudent!"
end
-- ############# AJOUT JOUR DES POUBELLES #################
month=tonumber(os.date("%m"))
day=tonumber(os.date("%d"))
-- TRash day : Mardi poubelle jaune (impair) / mardi poubelle verte (pair)
numOfWeek=tonumber(os.date("%V"))
numOfDay=os.date("%w")
if (numOfDay == '2') then -- mardi
if (numOfWeek % 2 ==0) then
sentence=sentence.."La poubelle verte est rammassé aujourd'hui." --pair
else
sentence=sentence.."La poubelle jaune est rammassé aujourd'hui." --impair
end
-- ############# ENCODAGE DU TTS #################
sentence = url_encode(sentence)
-- ############# SORTIE DU TEXTE #################
--print (sentence)
commandArray['UpdateDevice']= tts_idx ..'|0|'.. tostring(sentence) -- Mise à jour capteur txt
-- ############# PASSAGE DE LA VARIABLE BONJOUR A 1 POUR N'AVOIR LE MESSAGE QU'UNE SEULE FOIS PAR JOUR #################
commandArray['Variable:bonjour'] = tostring (1)
end
return commandArray
I have done this change
Code: Select all
-- ############# SORTIE DU TEXTE #################
--print (sentence)
commandArray['UpdateDevice']= tts_idx ..'|0|'.. tostring(sentence) -- Mise à jour capteur txt
and I have following error :
[string "--[[ ..."]:169: 'end' expected (to close 'if' at line 23) near
tanks in advance
regards
Re: Vocal announcement - Good Morning Script
Posted: Thursday 04 May 2017 17:12
by aleguid
Hello to all,
Great work this script is trying on in my raspberry but even after several attempts of resolution, I can not figure out where I am wrong.
Do you know how to give me a hand?
Code: Select all
Error: EventSystem: in Notification: [string "indexCommand=1 ..."]:6: attempt to index global 'devicechanged' (a nil value)
Code: Select all
indexCommand=1
commandArray = {}
local timeNow= os.date("*t")
if devicechanged['test'] == 'On' and --Motion sensor Living Room ManualLaunchScript
timeNow.hour >=16 and
string.sub(uservariables_lastupdate['goodMorning'], 9, 10) ~= os.date("%d") -- Only one time per day
then
local sentence="Buongiorno, oggi è "..tonumber(os.date("%d")) -- Good morning, today we are the ..
....
Re: Vocal announcement - Good Morning Script
Posted: Friday 05 May 2017 17:17
by aleguid
Everything solved ... at least I hope ... I have to put inside the lua editor of domoticz "UserVariable"
Re: Vocal announcement - Good Morning Script
Posted: Thursday 14 September 2017 17:20
by JuanUil
Hi all,
This is great!! I would like to use this as well but i seem to not succeed in installing izsynth.
I did:
Code: Select all
sudo apt-get update
sudo apt-get install -y sox lame mplayer curl espeak wget bsdmainutils file mawk coreutils
But then when I do the next I get a error
Code: Select all
pi@raspberrypi ~/domoticz/scripts $ izsynth -e naturalreaders -v Peter -t "Welco me home, mr Stark"
-bash: izsynth: no such command
tried this but also no luck
Code: Select all
pi@raspberrypi ~/domoticz/izsynth $ cd /usr/local/bin
pi@raspberrypi /usr/local/bin $ wget https://raw.githubusercontent.com/ugoviti/izsynth/master/izsynth -O izsynth && chmod 755 izsynth
izsynth: Access denied
pi@raspberrypi /usr/local/bin $
Some help would be appriciated.
I am on a rpi2B
greetz
Jan
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 14:23
by JuanUil
Nobody?
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 14:39
by jvdz
According the WiKi you should do:
cd /usr/local/bin
wget
https://raw.githubusercontent.com/ugovi ... er/izsynth -O izsynth && chmod 755 izsynth
As you got access denied I assume you need to run that last command with sudo.
Jos
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 16:01
by JuanUil
Thanks for your reply Jos,
but I still get the same errors
Jan
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 16:14
by jvdz
you mean access denied, even when using sudo?
Jos
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 16:46
by JuanUil
That is right
using sudo and everything installed but when I want to access izsyntz i get access denied.
Jan
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 17:12
by jvdz
Ok so you got one step further and got the command installed.
Sorry for being persistent but that is even when you use sudo on that command?
Jos
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 17:15
by JuanUil
Yes even on that
Code: Select all
pi@raspberrypi ~ $ cd /usr/local/bin
pi@raspberrypi /usr/local/bin $ izsynth
-bash: /usr/local/bin/izsynth: Toegang geweigerd
pi@raspberrypi /usr/local/bin $ sudo izsynth
sudo: izsynth: command not found
pi@raspberrypi /usr/local/bin $
and while installing
Code: Select all
pi@raspberrypi /usr/local/bin $ sudo wget https://raw.githubusercontent.com/ugoviti/izsynth/master/izsynth -O izsynth && chmod 755 izsynth
--2017-09-15 17:16:01-- https://raw.githubusercontent.com/ugoviti/izsynth/master/izsynth
Herleiden van raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.36.133
Verbinding maken met raw.githubusercontent.com (raw.githubusercontent.com)|151.101.36.133|:443... verbonden.
HTTP-verzoek is verzonden; wachten op antwoord... 200 OK
Lengte: 71866 (70K) [text/plain]
Wordt opgeslagen als: ‘izsynth’
100%[======================================>] 71.866 --.-K/s in 0,02s
2017-09-15 17:16:03 (2,88 MB/s) - '‘izsynth’' opgeslagen [71866/71866]
chmod: veranderen van toegangsrechten van ‘izsynth’: Bewerking niet toegestaan
pi@raspberrypi /usr/local/bin $
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 17:21
by jvdz
OK, so that means the chmod didn't work and needs to be done with sudo as well.
sudo chmod 755 izsynth
Jos
Re: Vocal announcement - Good Morning Script
Posted: Friday 15 September 2017 17:27
by JuanUil
Hi Jos,
Thanx, this works!!
Code: Select all
pi@raspberrypi /usr/local/bin $ izsynth
izsynth - TTS/Text To Speech synthesizer, background music overlay assembler and audio file converter for PBX and Home Automation Systems
Written by Ugo Viti <[email protected]>
version: 4.8 released: 20170909
usage: /usr/local/bin/izsynth [options]
Option: Argument: Description:
--------------------------------------------------------------------------------
Input/Output file management:
- Synthesize using standard input
-t <text> Text string to synthesize
-i <file or directory> Input txt/wav/mp3 file or directory to synthesize/c onvert (this disable '-t' option)
-o <directory> Output directory to save synthesized and assembled files (current: /dev/shm)
TextToSpeech management:
-e <engine> TTS voice engine (current: naturalreaders)
-v <voice> TTS voice language (current: Peter)
-T <volume> TTS volume (current: none) (use a number from 0.01 to 1)
-L List usable TTS engines
-l List usable TTS voices
Background music management:
-m <file> Input mp3/wav audio file to use as background music
-S <seconds> Start background music after specified time (curren t: 0 sec)
-p <seconds> Pad the begin of the TTS audio using the specified time (current: 5 sec)
-P <seconds> Pad the end of the TTS audio using the specified ti me (current: 5 sec)
-F <seconds> Fade the begin and the end of the wav music using t he specified time (current: 5 sec)
-M <volume> Background music volume (current: none) (use a numb er from 0.01 to 1)
Soundcard audio playback options:
-b Playback the generated files using the soundcard sp eakers (current: yes)
-B Playback in background detaching the izsynth comman d (current: yes) (only if PLAYBACK=yes)
-k Playback command (current: mplayer)
-K Playback command options (current: none)
-d Playback output device (current: default)
-D List available playback output devices
-W <volume> Change the playback soundcard output volume (curren t: none) (use a number from 0 to 100)
-r Remove synthesized file after playback (current: no ) (no = keep the generated high quality audio file for later usage)
Output file options:
-x Export the generated audio file into PBX formats (c urrent: no) (yes = this will assume PLAYBACK=no and OUTPUT_OVERWRITE=yes)
-X Export using the following audio formats (current: "44khz.wav wav gsm ulaw alaw slin") (valid only if EXPORT_AUDIO=yes))
-w Overwrite the synthesized file (current: no)
-s Split destination audio files into audio formats su b directories (current: yes) (valid only if EXPORT_AUDIO=yes)
Misc options:
-C Write/Overwrite the config file using the command a rguments or the default izsynth variables (file: /home/pi/.config/izsynth/izsynt h.conf)
-h Display this help menu
-H Display the 'naturalreaders' TTS Engine help menu
-E Display izsynth usage examples
-V Display izsynth version
Start working on the implementation now...
Again many thnx for your help
Jan