Learn more >
John Walicki | Published April 2, 2019
Artificial intelligenceIoTNatural language processingSpeech and empathy
In this tutorial, you will learn how to create a spoken universal translator by using a Node-RED Starter application to connect with these Watson AI services: Speech to Text, Language Translator, and 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.
After completing this tutorial you will be able to:
Create a Node-RED starter application running in IBM Cloud, create instances of the Watson services, Watson Speech to Text, Watson Text to Speech and Watson Language Translator and connect the 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 tutorial can be completed using an IBM Cloud Lite account.
You can complete this tutorial in approximately 15 minutes.
Follow these steps to create a Node-RED Starter application in IBM Cloud.
Log in to your IBM Cloud account.
Click on the Catalog (1).
Search for node-red (2).
Select the Starter Kits category (3), then select Node-RED Starter (4).
Enter a unique name (5) for your application. This name will be part of the application URL (6).
If the name is not unique, you will receive an error message and will need to enter another name.
The Region (7), Organization (8), and Space (9) fields will be pre-populated with valid options for your IBM Cloud account. If you have a Lite account, then just accept the defaults. If you have a trial or paid account, or if you belong to additional organizations, then you can choose to deploy to any region, organization, and space that is available to you.
In the Selected Plan section, choose Lite (10).
Click the Create button (11).
The Node-RED Starter application will be provisioned in the IBM Cloud region that was specified. This process is called staging an application. It can take a few minutes for this process to complete.
You do not need to wait for the application to provision and start. You can proceed to the next step.
You can add powerful Watson AI microservices to your application as APIs. These services are accessible through instances that you can manage through credentials. Instead of copying and pasting the credential keys into your app, this tutorial demonstrates how to create and bind these microservices to your Cloud Foundry application. The Node-RED nodes for these services will be easy to configure.
Three Watson AI services, all available in the IBM Cloud Lite tier, are needed to build a universal translator:
Watson Language Translator
Return to the IBM Cloud Catalog. Search for speech, navigate to the AI category.
Select Speech to Text, and click the Create button.
Return to the AI category in the IBM Cloud Catalog, and select Text to Speech, and click the Create button.
Return to the IBM Cloud Catalog, search for translator, navigate to the AI category.
Select Language Translator, and click the Create button.
In this step, you connect the newly created Watson AI services to your Node-RED Starter application.
Return to the IBM Cloud Dashboard, and navigate to the Cloud Foundry Apps section.
Select your nodered-universal-translator application. The Applications Details opens.
In the left navigation menu, select Connections.
Click the Create connection button.
Search for the Watson services that you created in the previous step, hover over Speech to Text and press the Connect button.
Click the Connect button to auto generate the binding credentials.
DO NOT RESTAGE the application yet. Click the Cancel button. After you connect all three of the Watson AI service instances, you can restage the application just once.
Click the Create Connection button again.
Search for the speech services, hover over the Text to Speech service, and click the Connect button.
Click the Connect button to auto-generate the binding credentials.
Remember to NOT click the Restage button.
Click the Create connection button again.
Search for the language translator service, hover over the Language Translator service, and click the Connect button.
Click the Connect button to auto-generate the binding credentials. Now, finally, you can click the Restage button.
The Cloud Foundry application will now restage and restart.
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 your Node-RED application, Node-RED helps you set it up and 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.
Use the setup wizard to secure your editor with a user name and password and to browse and add more nodes. If you forget your user name and password, you can reset the credentials in the Cloudant DB or by setting IBM Cloud environment variables. Click the Finish button to proceed
Click the Go to your Node-RED flow editor button to launch the Node-RED flow editor.
Click the Person icon in the upper right corner, and Sign in with your new username and password credentials.
The Node-RED Visual Programming Editor opens with a default flow. On the left side is a palette of nodes that you can drag onto the flow. You can wire nodes together to create a program.
The universal translator that we are building needs both a microphone to record your message and also the ability to play the audio of the translation. Luckily, there are nodes that can be added to the Node-RED palette that add these capabilities.
Click the Node-RED Menu, and select Manage palette
Select the Install tab, and search for browser-utils. Find the node-red-contrib-browser-utils node, and click the Install button.
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.
It is quick and easy to create the flows in Node-RED. However, if you want to just import the flows into your Node-RED application, you can get the code from my GitHub repo.
First, let’s build the 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.
Speech to Text
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. 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.
Text to Speech
Click and drag a Change node to your flow.
The returned audio transcription from the Text to Speech node will be returned as a raw buffer that contains the audio on the msg.speech message. The play-audio node expects the buffer to be passed in on msg.payload so the Change node will reassign the values.
Double-click the Change node and assign the msg.payload to msg.speech.
Click and drag a play-audio node to your flow.
Press the red Deploy button.
Select the tab to the left of the Inject node. The audio of the message will play.
Our universal translator will use the recorded transcript as the input to the language translator node, and then send the foreign language to the Text to Speech node.
Click and drag another Change node to your flow. Double-click it and assign msg.payload to msg.transcription.
Click and drag a language translator node to your flow. Double-click it and select English as the Source and Spanish 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.
Wire the nodes together as shown in the screenshot.
Now that you’ve built a universal translator, try it out!
Record a message.
You can view the translations in the Debug tab of Node-RED.
Experiment with translations between various languages.
Congratulations! You created a Node-RED starter application using Watson services in IBM Cloud.
Get the Code »
Use Node-RED Starter Kit and a Watson Cloud service to send a news article URL to the Watson API and…
Artificial intelligenceKnowledge discovery+
Learn how Node-RED can help your latest IoT application by leveraging flow-based programming and MQTT.
Back to top