Google voice

From Domoticz
Jump to: navigation, search
Since Nov 2015, Google voice controls the number of call per IP. So if you have a dynamic IP, and are not lucky, you may be banned. 
So this service may not be usable anymore. If so, use VoiceRSS. I have updated the wiki with a VoiceRSS howto, look here : https://www.domoticz.com/wiki/Talking_Domoticz

Purpose

This script will play a string into google translate. It is useful to allow domoticz to give voice notifications.

Dependencies - hardware / software / operating system

  • To trigger this script you can use Trigger a bash script method or any other method.
  • Make sure you have a working sound card on domoticz computer
  • Make sure you have internet access on domoticz computer
  • Make sure mplayer is installed : sudo apt-get install mplayer

Domoticz Setup - switches, variables, version

N/A

Installation instructions

Copy this script in your domoticz\scripts\ folder.

Script with comments Part 1 (lua)

local sensor  = 'Talk - Garbage'
local sensor2 = 'Talk - Recycling'
local sensor3 = 'Talk - Robot'
local sensor4 = 'Talk - Washing'
local sensor5 = 'Talk - Good Morning'
local sensor6 = 'Talk - Humidity'
local sensor7 = 'Security Panel'
local sensor8 = 'Talk - Compost'

commandArray = {} 

if (devicechanged[sensor] == 'On') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Bring the garbage bag out")
commandArray[sensor]='Off'
end

if (devicechanged[sensor2] == 'On') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Bring the recycling bin out")
commandArray[sensor2]='Off'
end 

if (devicechanged[sensor3] == 'On') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Clean Mr. Robot")
commandArray[sensor3]='Off'
end

if (devicechanged[sensor4] == 'On') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Wash the clothes that are dirty")
commandArray[sensor4]='Off'
end

if (devicechanged[sensor5] == 'On') then

os.execute ("/root/domoticz/domoticz/scripts/google_voice_es.sh Buesnas dias Wendy")
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh " .. os.date("today is %A, in %B %d %Y ") )
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh enjoy your day" )
--weather

commandArray[sensor5]='Off'
commandArray['Talk - Weather Now']='On'
end

if (devicechanged[sensor7] == 'Arm Home') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Security panel is set to Arm Home")
end 

if (devicechanged[sensor7] == 'Normal') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Security panel is set to Disarm")
end 

if (devicechanged[sensor7] == 'Arm Away') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Security panel is set to Arm Away")
end

if (devicechanged[sensor8] == 'On') then
os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Bring the composting bin out")
end

return commandArray

Script with comments Part 2 (bash)

For the language type check this : HERE

#!/bin/bash
mplayer -ao alsa -noconsolecontrols "http://translate.google.com/translate_tts?tl=en&q=$*" > /dev/null 2>&1


In some setups the statement above does not work, use the following to download an MP3 with the requested text and play that with mplayer

curl 'http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20world&tl=en&client=t' -H 'Referer: http://translate.google.com/' -H 'User-Agent: stagefright/1.2 (Linux;Android 5.0)' > google_tts.mp3
mplayer -ao alsa google.tts.mp3

Example of use (if relevant) i.e. output files / screen displays

N/A