Overview

Skill Level: Beginner

Beginners

Ingredients

  1. IBM Bluemix account
  2. Node-RED Starter Community
  3. Watson Text to Speech service

Step-by-step

  1. Overview

    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.

  2. Prerequisites

    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.

  3. 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

    Function:

    var txt = msg.payload.textalert;
    msg.payload =new Object ();
    msg.payload = txt;
    return msg;

    (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

    Function:

    var speech = msg.speech;
    msg.payload =new Object ();
    msg.payload = speech;
    return msg;

  4. 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.

  5. 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.

  6. Summary

    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.

4 comments on"Cognitive application using Watson Text to Speech that enables voice interaction between device and human"

  1. hkanekal@ameritronik.com April 04, 2016

    Hi,
    Tried to implement your example and failed:
    “502 Bad Gateway: Registered endpoint failed to handle the request.”

    In the node-red watson text to speech , I left the “name” and “password” blank. Should I
    use the credentials of this app ?
    Please help?

    • BalajiKadambi April 20, 2016

      Create an instance of Text to Speech service and bind it to the Node-RED application. That should solve your issue.

  2. (Changed login name.. but same person as above).
    The logs for the app says:
    2016-04-04T12:56:01.767-0700[App/0]OUT4 Apr 19:56:01 – [info] Starting flows
    2016-04-04T12:56:01.841-0700[RTR/0]OUTntts.mybluemix.net – [04/04/2016:19:56:01 +0000] “POST /red/flows HTTP/1.1” 204 1134 0 “http://ntts.mybluemix.net/red/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36″ 169.54.202.25:15245 x_forwarded_for:”104.50.5.217″ x_forwarded_proto:”http” vcap_request_id:da15030f-fdef-4ea8-75a4-a3da9b88cfc2 response_time:0.188124851 app_id:b0d4c040-4a65-4aca-b06a-f47673c8e846 x_global_transaction_id:”1184625405″
    2016-04-04T12:56:01.843-0700[App/0]OUT4 Apr 19:56:01 – [info] Started flows
    2016-04-04T12:57:27.418-0700[App/0]OUT4 Apr 19:57:27 – [error] [watson-text-to-speech:Watson Text to Speech] Missing property: msg.payload
    2016-04-04T12:58:22.909-0700[App/0]OUT4 Apr 19:58:22 – [error] [watson-text-to-speech:Watson Text to Speech] Missing property: msg.payload
    2016-04-04T13:00:22.916-0700[RTR/1]OUTntts.mybluemix.net – [04/04/2016:19:58:22 +0000] “GET /getAudioMessage?textalert=”Alarm%20window%20open” HTTP/1.1″ 502 0 67 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko” 169.54.202.26:31134 x_forwarded_for:”104.50.5.217″ x_forwarded_proto:”http” vcap_request_id:76a3708a-f511-406e-6957-15ce858bfa23 response_time:120.119373151 app_id:b0d4c040-4a65-4aca-b06a-f47673c8e846 x_global_transaction_id:”1184807437″
    2016-04-04T13:00:28.786-0700[RTR/0]OUTntts.mybluemix.net – [04/04/2016:20:00:28 +0000] “GET /red/vendor/ace/worker-javascript.js HTTP/1.1” 304 0 0 “http://ntts.mybluemix.net/red/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36″ 192.155.237.118:56800 x_forwarded_for:”104.50.5.217″ x_forwarded_proto:”http” vcap_request_id:730c9676-5d38-445b-7c29-e79f2b4121e8 response_time:0.006937861 app_id:b0d4c040-4a65-4aca-b06a-f47673c8e846 x_global_transaction_id:”993962127″
    2016-04-04T13:02:19.530-0700[App/0]OUT4 Apr 20:02:19 – [error] [watson-text-to-speech:Watson Text to Speech] Missing property: msg.payload
    2016-04-04T13:05:11.439-0700[App/0]OUT4 Apr 20:05:11 – [info] Stopping flows
    2016-04-04T13:05:11.442-0700[App/0]OUT4 Apr 20:05:11 – [info] Starting flows
    2016-04-04T13:05:11.441-0700[App/0]OUT4 Apr 20:05:11 – [info] Stopped flows
    2016-04-04T13:05:11.548-0700[App/0]OUT4 Apr 20:05:11 – [info] Started flows
    2016-04-04T13:05:47.704-0700[App/0]OUT4 Apr 20:05:47 – [error] [watson-text-to-speech:Watson Text to Speech] Missing property: msg.payload
    2016-04-04T13:05:53.112-0700[App/0]OUT4 Apr 20:05:53 – [error] [watson-text-to-speech:Watson Text to Speech] Missing property: msg.payload
    2016-04-04T13:07:47.703-0700[RTR/1]OUTntts.mybluemix.net – [04/04/2016:20:05:47 +0000] “GET /getAudioMessage?textalert=%3Ctext%3E HTTP/1.1” 502 0 67 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36″ 192.155.237.119:15864 x_forwarded_for:”104.50.5.217″ x_forwarded_proto:”http” vcap_request_id:09b4412e-1920-4195-555e-78bb91586cbe response_time:120.00688138 app_id:b0d4c040-4a65-4aca-b06a-f47673c8e846 x_global_transaction_id:”994912207″
    2016-04-04T13:10:11.817-0700[RTR/1]OUTntts.mybluemix.net – [04/04/2016:20:08:11 +0000] “GET /red/comms HTTP/1.1” 101 0 0 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36″ 108.168.250.156:16201 x_forwarded_for:”104.50.5.217, 108.168.250.156″ x_forwarded_proto:”http” vcap_request_id:cc7c88f1-396f-419a-7888-6f57065b5f42 response_time:120.435442695 app_id:b0d4c040-4a65-4aca-b06a-f47673c8e846 x_global_transaction_id:”2158762519″

    • BalajiKadambi April 20, 2016

      There was an error in the function – Text payload.
      I have corrected it.
      var txt = msg.payload.textalert;
      msg.payload =new Object ();
      msg.payload = txt;
      return msg;
      Please check now.

Join The Discussion