Reader small image

You're reading from  Google Cloud AI Services Quick Start Guide

Product typeBook
Published inMay 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788626613
Edition1st Edition
Languages
Right arrow
Author (1)
Arvind Ravulavaru
Arvind Ravulavaru
author image
Arvind Ravulavaru

Arvind Ravulavaru is a platform architect at Ubiconn IoT Solutions, with over 9 years of experience in software development and 2 years in hardware & product development. For the last 5 years, he has been working extensively on JavaScript, both on the server side and the client side. And for the last couple of years in IoT, building a platform for rapidly developing IoT solutions, named The IoT Suitcase. Prior to that, Arvind worked on big data, cloud computing, and orchestration.
Read more about Arvind Ravulavaru

Right arrow

Cloud Translation

In the last chapter, we saw how to work with Cloud Natural Language API and how we can integrate the Cloud Natural Language API with SmartExchange to detect emotion in text. In this chapter, we are going to work with Cloud Translation API. Next to each text reply, we are going to provide a button, using which the message text can be converted to any language the user prefers.

The topics covered in this chapter are:

  • What is Cloud Translation API?
  • Exploring Translation API
  • Integrating Translation API with SmartExchange

Cloud Translation API

Google Cloud Speech API is one of the machine learning services exposed under the Cloud AI vertical. This service is used to translate text from one language to another using state-of-the-art Neural Machine Translation (NMT).

This service offers the following:

  • Provides an on-the-fly translation service, from a sentence to a document
  • Can support up to 104 languages, as of this writing
  • Can detect language in source text automatically
  • Is highly scalable and affordable
  • Continuously updates from various sources and provides us the best translation service

Pricing

The pricing for this service is as follows:

Feature

Pricing

Text translation

$20 for first 1 million characters a month

Language...

Enabling API

Now that we have a project and we have both API and service account keys, we will enable the required API and test our application. Follow these steps to enable the API:

  1. Navigate to the project home page (https://console.cloud.google.com/home/dashboard?project=smart-exchange-b10882). From the menu on the left-hand side, select APIs & Services | Library.
  2. Once we land on this page, search for Google Cloud Translation API and click on that card.
  3. Then, click on the Enable button. This will prompt you to set up billing, if you have not already done so.
  4. Once you have enabled the billing and the API, you should see that the Cloud Natural Language API is enabled on your screen.

In the next section, we are going to explore the API.

Exploring Cloud Translation API

Please refer to the Setting up a Rest Client section from Chapter 3, Cloud Vision API to set up a REST API client, either Postman or cURL before you continue. Now that we have all the required setup done, let's get started with exploring the API.

In this section, we are going to explore two APIs of Cloud Translation:

  • Discovering supporting languages
  • Translating text

Apart from this, there is another API, which helps us discover the language of the text. While integrating with SmartExchange, we are going to make a request to the supporting languages API and then make a request to translate text, to get the translated text. We will start with discovering supporting languages.

Discovering supporting languages

...

Integrating Translate API with SmartExchange

Now that we have seen what can be done using Translate API, let's actually integrate this into SmartExchange. Next to every text message, we are going have a translate button. When the user clicks on the button, we show a popup with the Message text and a dropdown to pick the target language to translate this message to. Once we have successfully translated it, we are going to show the translated text in the same popup. The final output of the text analysis will look as shown here:

So, let's get started with the implementation.

Solution design

To achieve our solution, we are going to do the following:

  1. On the view-thread page, the user is going see a Translate button...

Deploying to Heroku

This step is optional and you can do it if you are interested in deploying this app to Heroku. To continue with this section, you need to have set up a Heroku account and installed the Heroku Toolbelt. Once that is done, open a new Command Prompt or Terminal inside the smart-exchange-base folder, and then run:

$ heroku login

This is a prompt for your Heroku credentials that you have signed up with. Next, let's get our application ready for deployment. Run this:

$ npm run build
or
$ yarn build

This will run the required scripts to build the final dist folder, which will be deployed to Heroku. Once the build is completed, run the following:

$ git add -A
$ git commit -am "Cloud Translate API Integration Commit"

Let's push the code to Heroku. Run this:

$ git push heroku master

If everything goes well, the code will be uploaded to Heroku and you...

Summary

In this chapter, we went through the Google Cloud Translate API and worked with the language and translate API. Then, we set up the required code to integrate this API with SmartExchange app. This concludes our journey into Getting Started with Google AI Services. I hope you have learned the basics of Google Cloud AI and how to integrate it into any application.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Google Cloud AI Services Quick Start Guide
Published in: May 2018Publisher: PacktISBN-13: 9781788626613
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Arvind Ravulavaru

Arvind Ravulavaru is a platform architect at Ubiconn IoT Solutions, with over 9 years of experience in software development and 2 years in hardware & product development. For the last 5 years, he has been working extensively on JavaScript, both on the server side and the client side. And for the last couple of years in IoT, building a platform for rapidly developing IoT solutions, named The IoT Suitcase. Prior to that, Arvind worked on big data, cloud computing, and orchestration.
Read more about Arvind Ravulavaru