How to Build a Spoken Universal Translator with Node-RED and Watson AI services
Tags: cloud, javascript, node, ibmwatson
Published: 2021-02-22 01:43:26

# What is Node-RED?
[Node-RED](https://nodered.org/) is a low-code programming environment for event-driven applications. It's a programming tool for wiring together hardware devices, APIs, and online services in new and interesting ways.

At the core of Node-RED is Node.js a JavaScript runtime environment built on Chrome's V8 JavaScript engine. Top 5 reasons to use Node-RED can be found [here](https://developer.ibm.com/blogs/top-5-reasons-to-use-node-red-right-now/).

## Let's build a spoken universal translator using Node-RED and Watson AI services 

We will build a universal translator by using a Node-RED Starter application to connect with those Watson AI services: 

- Speech to Text
- Language Translator
- Text to Speech

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpbrpmrd9baso5d2a3bx.png)

The [Node-RED Starter application](https://developer.ibm.com/tutorials/how-to-create-a-node-red-starter-application/) includes a Node-RED Node.js web server and a Cloudant database to store the Node-RED flows.

#### We will learn how to: 

- Create a **Node-RED starter** app running in IBM Cloud. Create instances of the Watson services: Speech to Text, Text to Speech, and Language Translator and how to connect those services to your Node-Red app.

- Launch and configure the Node-RED visual programming editor.

- Install additional Node-RED nodes and create flows that use the Watson services to create the spoken universal translator.


## Prerequisites
This app can be completed using an IBM Cloud Lite account.

Create an [IBM Cloud account](https://cloud.ibm.com/registration?cm_sp=ibmdev-_-developer-tutorials-_-cloudreg)
Log into [IBM Cloud](https://cloud.ibm.com/login?cm_sp=ibmdev-_-developer-tutorials-_-cloudreg)

# Step 1 – Let's create a Node-RED Starter App

Follow these steps to create a Node-RED Starter application in IBM Cloud.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7h9yhwwgc9lv1vuzx7in.png)

1. Log in to your IBM Cloud account.

2. Click on the Catalog 

3. Search for node-red 

4. Select the Starter Kits category, then select Node-RED Starter.


5. Enter a unique name for your application, it will be part of the application URL :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/849vm4y4s1f93oa0mtfs.png)


6. The Region, Organization, and Space fields will be pre-populated with valid options for your IBM Cloud account. I have a Lite account and I just accepted the defaults. 

7. In the Selected Plan section, choose Lite.

8. Click the Create button.


The Node-RED Starter application will be provisioned in the IBM Cloud region that was specified. This process is called staging an application. 

# Step 2 – Let's create the Watson AI service instances

You can add Watson AI microservices to your application as APIs, through instances that you can manage through credentials. We will create and bind these microservices to your Cloud Foundry application. There are three Watson AI services, all available in the *IBM Cloud Lite tier*, needed to build a universal translator:

- Watson Speech to Text
- Watson Text to Speech
- Watson Language Translator

In IBM Cloud Catalog search for speech and navigate to the AI category:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgzhwggn3fl4gyhqbzel.png)

Select **Speech to Text**, and click the Create button.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dpxfbqrgj16b1dgwsf4.png)

Return to the AI category in the IBM Cloud Catalog, and select **Text to Speech**, and click the Create button:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlqj3oadcz3dmcwzw7hw.png)

In IBM Cloud Catalog, search for a translator, navigate to the AI category, select **Language Translator**, and click the Create button, I already had the one: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0kg5c3jcqkm3i0rjt24.png)

# Step 3 – Let's connect the Watson AI Services to the Node-RED Starter Application

1. In [IBM Cloud Dashboard](https://cloud.ibm.com/resources?cm_sp=ibmdev-_-developer-tutorials-_-cloudreg) navigate to the Apps section and select Node-RED universal-translator (your apps unique name):

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/147tyk7n742cf5j1q20f.png)

The Applications Details opens, search for the Watson services that you created in the previous step and press the Connect button. Once it's connected you will have those Services ( Speech to Text, Text to Speech, and Language Translator ) connected like this: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wyohkndk5xgayjwiu11r.png)

# Step 4 – Launch your Node-RED app and open the Node-RED visual programming editor

Node-RED is an open-source Node.js application that provides a visual programming editor that makes it easy to wire together flows.

The first time you start the Node-RED app, it will help you configure the visual programming editor. Once the Green Running icon appears, click the View App URL link, a new browser tab opens to the Node-RED start page: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhmw6h2o1gpltwwkgjz0.png)


A new browser tab opens to the Node-RED start page.

Use the setup wizard to secure your editor with a user name and password and to browse and add more nodes. Click the Finish button to proceed: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zj68d52pwgbxszy5u96.png)

Click the Go to your Node-RED flow editor button to launch the Node-RED flow editor:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlhwuatjglmcjujjmnsx.png)

Click the Person icon in the upper right corner, and Sign in with your new username and password credentials and you will get a screen like this:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qsslxb8ke41azaz8un5.png)

The Node-RED Visual Programming Editor has a left side with a palette of nodes that you can drag onto the flow and wire nodes together to create a program.

# Step 5 – Let's install Additional Node-RED Nodes

The universal translator that we are building needs a **microphone** to record your message and the ability to play the audio of the translation. We can add nodes to the Node-RED palette that add these capabilities, such a great thing! 

1. Click the Node-RED Menu, and select Manage palette
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/refq1uhevlz2r3slvh5k.png)

2. Select the Install tab, and search for *browser-utils* and Install the **node-red-contrib-browser-utils** node. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w8gidpxydu51jz1r33hk.png)

3. Search for *play-audio*, find the **node-red-contrib-play-audio** node, and click the Install button.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yukptsavbb1wkrp0aicd.png)

# Step 6 – Build the flows for the universal translator

Node-RED allows you to drag and drop Nodes from the left palette onto your flow canvas and wire them together to create programs. 

### Speech-to-Text flow
Click and drag a microphone node to your flow.

Click and drag a Speech to Text node to your flow. Double-click it and select US English.

Click and drag a Debug node to your flow. Double-click it and have it output msg.transcription.

Wire the nodes together as shown in the screenshot below.

Click the red Deploy button.

Select the tab to the left of the microphone node and allow your browser access to the microphone on the laptop.

Record a message, like “wow this is so much fun!”

# Text-to-Speech flow
Now, let’s build the Text-to-Speech flow.

1. Click and drag an Inject node to your flow and double-click it and change the payload type to a string and type a message.
2. Click and drag a Text to Speech node to your flow, double-click it and select US English.
3. Click and drag a Change node to your flow, double-click the Change node and assign the msg.payload to msg.speech.
4. Click and drag a play-audio node to your flow.
5. Wire the nodes together as shown in the screenshot below:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28p0496xngl5r804n4ba.png)
6. Press the Deploy button (the red one).
7. Select the tab to the left of the Inject node. The audio of the message will play.

# Language Translator flow

The universal translator will use the recorded transcript as the input to the language translator node, and send the foreign language to the Text to Speech node.

1. Click and drag another Change node to your flow, double-click it and assign msg.payload to msg.transcription like this:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wbanqisq73ayp2dpmjd.png)

2. Click and drag a language translator node to your flow. Double-click it and select English as the Source and Croatian 
as the Target.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqxsc2yr6l306b8ldjxz.png)

3. Click and drag a Debug node to your flow.

4. Double-click the Text to Speech node, and change the language to Spanish and select a voice (here I clicked and tried Croatian language but it was not available, doesn’t show it on the list and I'll stick with Spanish)

This is how your final flow should look like:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxqu1fz166ctfryb2kja.png)

Finally, click the Deploy button (the red one) on the right top corner!

# Final Step – let's test universal translator

Select the tab to the left of the microphone node and allow your browser access to the microphone on the laptop and **record a message**.

You can follow the process and view the translations in the **Debug** tab of Node-RED: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tuu4habq17sa9yh8smt.png)

Full documentation and more details on how to build Node-RED starter application using Watson services in IBM Cloud can be found [here] (https://developer.ibm.com/technologies/iot/tutorials/build-universal-translator-nodered-watson-ai-services/)

To connect please check my [Github](https://github.com/ivanadokic), [LinkedIn](https://www.linkedin.com/in/ivana-dokic/) or [Twitter](https://twitter.com/LloydPile). 

Thank you for reading!