Domoticz voice feedback (text to speech)

Tutorial Domoticz Speaker

Voice feedback is great when you want to use Domoticz for example as an alarm. In this way, Domoticz can tell you when the alarm is activated. I use IzSynth for this task. izSynth is a bash script running under Linux, written to automate the synthesis of voices used into izPBX System or for realtime TTS (Text To Speech) used into Home Automation solutions. It can use offline synthesis software like eSpeak, Festival, VoiceRSS, NaturalReaders, and other popular online web TTS services to synthesize audio voices from ASCII text files and automatically merging the audio with background music (mp3 and wav format are supported), adding silences and fade in and out.

Speaker

Connect a speaker thought mini-jack to your PI. You can also use Bluetooth speakers, but I will focus here on a simple speaker so the Bluetooth setup is not covered in this article.

Installation of izsynth

1
sudo apt-get install -y sox lame mplayer curl espeak wget bsdmainutils file mawk coreutils<br>

1
cd /
usr
1
2
3
/local/bin<br>
sudo wget https://raw.githubusercontent.com/ugoviti/izsynth/master/izsynth -O izsynth<br>
sudo chmod 755 izsynth<br>

onfiguring text to speech

NB. Some engines, like voicerss, need an APY KEY before you can use it, follow the onscreen guide to get your APY KEY:

1
izsynth -e voicerss -H

izSynth is configurable in 3 ways:

  1. From command line specifying the options (
    1
    izsynth -h
     to list available options or 
    1
    izsynth -E
     for example usage)
  2. Using an external config file for overriding the izsynth variables (suggested method)
  3. Modifying the variables on the izsynth script itself (not suggested)

I suggest creating an external config file to avoid changes to your configurations when you update izSynth script.

Create the following config file: 

1
$HOME/.config/izsynth/izsynth.conf
 using the command:

1
$ izsynth -C

After configuring you can test and use it.

Let Domoticz speak

1
izsynth -e
naturalreaders
1
 -v Peter -t "Hello Gadget freak"

  • Create a virtual switch (or use a real switch or hardware sensor):
    • in the On Action: put a command like this: 
      1
      script://izsynth device activated
    • in the Off Action: put a command like this: 
      1
      script://izsynth device deactivated

This will download the phrases and save them on your Domoticz. But you can always create and save phrases by yourself to play them, so an internet connection is not needed.
create phrases with services like http://soundoftext.com

An example of voice feedback

save a phrase as mp3 in /home/pi/domoticz/phrases
test the command in SSH:

1
/usr/bin/mplayer /home/pi/domoticz/phrases/Alarm_activated.mp3

Modular speak script for Lua events

Create a script, this script is modular and expects a language and a phrase as variable.

Play_sound.sh:

1
2
3
4
#!/bin/sh<br>
killall mplayer<br>
izsynth -e google -v "$1" -t "$2"<br>
#izsynth -e google -v nl'text here'

give it execute rights.

1
chmod +x Play_sound.sh

test the script in Putty before execute it from LUA:

1
sh Play_sound.sh nl "text to test"

It will play the variable text in Dutch language (you can change this by using EN instead of NL)
This way you are able to let speak everything in Lua very simple by using: where language and message must be changed ofcourse.
1
<br>os.execute("sh /home/pi/domoticz/scripts/bash/Play_sound.sh '" .. speakLanguage .. "' '" .. speakMessage .. "' ")

Alternatives and more info

Voice feedback through Amazon Alexa and Google Home and other examples and systems check out:
http://www.domoticz.com/forum/viewforum.php?f=69