top of page

Text-to-Speech

Updated: May 4, 2020

Time to cook: 30min

Difficulty: +++++



This recipe is about adding the text-to-speech capabilities using the Amazon Alexa platform. This can be very handy if you want to communicate a state change from a device or an event such as a doorbell or notify when it gets dark.


In the previous recipe we covered how to setup Amazon Alexa as a Human Voice assistant to control your devices in OpenHAB. With this recipe, we are going to add Text-to-speech capabilities so we can report on a device state or event using the same human voice assistant.


 

Ingredients


Prerequisites


Tools

 

The Building plan


First we will create an item in openHAB which is linked to the TTS channel of our Amazon Echo device.


When you have added your Alexa Device as a Thing in OpenHAB, it has created a number of channels under your device. One of them is the TTS service called ‘speak’.




To use the Alex TTS capabilities we add an item which is linked to a particular channel of our Amazon Echo device. This item has been setup in the items folder (/etc/openhab2/items) and looks as follows:



amazonechocontrol.items


// Commands String Echo_Living_Room_TTS "Text to Speech" (Alexa_Living_Room) {channel="amazonechocontrol:echo:<echo_id>:textToSpeech"}



Note: replace <echo_id> with the echo ID found in the device channels of your device.



Now for example, Alexa can notify us when the sun is going down and the garden lights are turned on:


To achieve that, we simply create a rule in openHAB. You can create a rule in /etc/openhab2/rules


TTS.rules


rule "Sunset Rule" when Channel 'astro:sun:local:set#event' triggered START then // Do what you want to do at start of sunset for example: Outside_Lights.sendCommand(ON) Echo_Living_Room_TTS.sendCommand('The sun is going under, i've turned on the garden lights') end



In the above example, we used the ASTRO binding in openHAB to trigger on the sun:local:set event. When it is true, we turn on the garden Lights and send a text-to-speech command to the EchoDOT device in the Living Room.


We can make the text to speech even more intuitive by using Amazon Polly services (Amazon Polly is a service that turns text into lifelike speech) to create an even more human-like feeling.


An example is given below how you can use Alexa to whisper something to you:


rule "Say welcome if the door opens" when Item Door_Contact changed to OPEN then Echo_Living_Room_TTS.sendCommand('<speak>welcome home.<amazon:effect name="whispered">everyone is already asleep… be quiet.</amazon:effect></speak>') end



Amazon Polly supports the following Speech Synthesis Markup Language (SSML) tags






9 views0 comments
bottom of page