Consider the following scenario. A sensor or device sends events to the Watson IoT platform. The events are fed into the analytics engine to gain insights. There arises a need to communicate an important insight as an alert to the end human user. A text alert is not read unless the human recipient looks at the screen. Many a time, the recipient is not able to look at the screen to read the message as the attention of the recipient is directed at other tasks.
We can use the cognitive capabilities on the Bluemix platform to generate audio alerts. In the case of audio alerts, the text is read out to the recipient as soon as an alert is received. There is no delay in getting the message as the recipient does not need to look at the screen to read the text.
In this recipe, we will show how we can create a ReST endpoint that enables conversion of text to speech using Node-RED and Watson Text to Speech service. This ReST endpoint can be invoked by the Desktop UI or Mobile UI app to read out alerts to the human recipient.
1. Create a Node-RED application
2. Add the Text to Speech service to the Node-RED application
After you have created the Node-RED application and added the Text to Speech service, it should be visible on the Node-RED page as shown below.
Steps to create a REST end point that takes text as an input and returns an audio as output
1. Create a Node-RED flow as shown below
2. Configure the nodes as shown below
(a) Text message
(b) Text payload
var txt = msg.payload.textalert;
msg.payload =new Object ();
msg.payload = txt;
(c) Watson Text to Speech
The supported languages are English, German, French, Spanish and Italian.
The supported voice are Michael(Male), Lisa(Female), Allison(Female) and Kate(Female).
The formats supported are WAV, FLAC and OGG.
(d) Speech payload
var speech = msg.speech;
msg.payload =new Object ();
msg.payload = speech;
Invoke the ReST API to convert text to audio
The ReST API can be invoked as follows:
http://<Node-RED application name>.mybluemix.net/getAudioMessage?textalert=<Text message>
The Node-RED application name and the text message must be replaced in the above URL.
The audio message is returned in the response.
Test the ReST API
The ReST API can be tested by a direct invocation from the browser. The download window that comes up when invoked from Firefox browser is shown below:
The message can be saved and played with a media player. This audio message can be embedded and played on the deskop or mobile UI.
This recipe is a part of the series to demonstrate the cognitive capabilities of Watson services. In this recipe we demonstrated the use of Text-to-Speech capabilities to generate audio alerts. The subsequent recipes will focus on the other Watson services. Keep a watch out for them.