Node-RED 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.
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
The Node-RED Starter application includes a Node-RED Node.js web server and a Cloudant database to store the Node-RED flows.
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.
This app can be completed using an IBM Cloud Lite account.
Follow these steps to create a Node-RED Starter application in IBM Cloud.
Log in to your IBM Cloud account.
Click on the Catalog
Search for node-red
Select the Starter Kits category, then select Node-RED Starter.
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.
In the Selected Plan section, choose Lite.
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.
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:
- In IBM Cloud Dashboard navigate to the Apps section and select Node-RED universal-translator (your apps unique name):
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:
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:
A new browser tab opens to the Node-RED start page.
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.
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!
Select the Install tab, and search for browser-utils and Install the node-red-contrib-browser-utils node.
- Search for play-audio, find the node-red-contrib-play-audio node, and click the Install button.
Node-RED allows you to drag and drop Nodes from the left palette onto your flow canvas and wire them together to create programs.
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!”
Now, let’s build the Text-to-Speech flow.
- 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.
- Click and drag a Text to Speech node to your flow, double-click it and select US English.
- Click and drag a Change node to your flow, double-click the Change node and assign the msg.payload to msg.speech.
- Click and drag a play-audio node to your flow.
- Wire the nodes together as shown in the screenshot below:
- Press the Deploy button (the red one).
- Select the tab to the left of the Inject node. The audio of the message will play.
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.
Click and drag a language translator node to your flow. Double-click it and select English as the Source and Croatian
as the Target.
Click and drag a Debug node to your flow.
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)
Finally, click the Deploy button (the red one) on the right top corner!
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:
Full documentation and more details on how to build Node-RED starter application using Watson services in IBM Cloud can be found here
Thank you for reading!