1. Home
  2. Training Library
  3. Microsoft Azure
  4. Courses
  5. Translating Language by Using the Azure Speech Service

Translating Text Using Translator Service

Contents

keyboard_tab
Translating Language with Azure Speech Service
1
Introduction
PREVIEW1m 25s
6
Summary
1m 7s
Start course
Overview
Difficulty
Advanced
Duration
48m
Students
30
Ratings
5/5
starstarstarstarstar
Description

In this course, you’ll learn about the Azure Speech and Translator services. You’ll learn about the key features and what’s possible with each of these services. You’ll find out how these services can be used with SDKs, REST APIs, and the command-line interface. You’ll see demos of the Translator, Speech-to-text, and Text-to-speech services in action and understand how to use them.

Learning Objectives

  • Understand the main capabilities of the Azure Speech service
  • Learn available options for using the Azure Speech service
  • Translate text using the Translator service
  • Translate speech to text
  • Translate text to speech

Intended Audience

This course is intended for developers or software architects who want to learn more about the Azure Speech and Translator services.

Prerequisites

Intermediate knowledge of C# and coding techniques is required for this course. You’ll also need to be familiar with Azure concepts such as App Service and resources. An understanding of APIs is also required. We’ll be writing a little code and will be using Visual Studio Community Edition, so you’ll need a copy of that too.

Transcript

Let's look at an overview of the Azure Translator Service. In this lecture, we're going to introduce what the Azure Translator Service is. We'll take a closer look at some of the key features the translator service provides. We'll see some of the things that you can do with the translator service, and finally, we'll see a demo of the translator service in action.

So, what is the Azure Translator Service? The Azure Translator Service contains endpoints that let you perform a variety of translation operations in a single API call. At a high level, these capabilities include text translations, document translations, and customizable translations. To use the translator service, three things are required. You need an existing Azure subscription, an Azure Translator resource, and you also need an API key. With a subscription, translator resource, and accompanying API key, you can start to consume the translator service.

There are a few ways that you can consume the translator service: REST API, Client SDK, or by using the Custom Translator portal. At the time of this course, the REST API is the only way you can perform text translation. The REST API also has support for the processing of large documents. Implementing the REST API calls mean that you're responsible for constructing the HTTP request in any authentication, as well as manually setting any required parameters. The Client SDK lets you consume the translation service using a language such as C# or Python. At present, the Client SDK will only let you perform translation operations on larger documents. This may change in the future, however.

Another option you have is to use the Custom Translator portal. This feature is accessible via the cognitive services language studio portal. The Custom Translator portal is a service that lets you create, test, evaluate, and publish Custom Translation models,  all within a user-friendly web application. Find out more about Azure Cognitive Services language studio in the URL on this slide. To consume the translator service via the REST API, you need to construct a post request. In this example, the detect language endpoint is being called.

A JSON payload contains two strings in Spanish, Hola and Si. Submitting this post request will return the following response. Here we can see the language locale has been identified, along with the probability scoring of one. Two billion properties are included: is translation supported and is transliteration supported. The property is translation supported indicates if the identified language is one of the languages that can be supported for text translation, the property is transliteration supported indicates if the identified language is one of the languages that can be supported for text transliteration, or in other words can the identified strings in the language be converted to the equivalent in a different target language.

To consume the translator service using the Client SDK, one of the first things that you must do is to create an Azure Blob Storage account. The Blob Storage account should contain two containers. One container is used to store the files that you wish to perform translation on. This is often known as the source container. A second container, commonly known as the target container is used to store the translated files. When the storage a current and the company containers have been configured, you can install the Client SDK into your solution. The Client SDK makes it simple for you to programmatically access translation services in either C# or Python.

Let's take a closer look at some additional features the translator service provides. We'll also explore some of the use cases the translator service can be used in. The Azure Translator Service contains features to help you create innovative translation solutions. You may have to perform a translation but are unsure of the incoming language that's being sent to the API. It's important to know this so that you can set the source language for any potential translation operation.

The translator service detect endpoint lets you detect the language of any incoming text. You send a body of text to the detect endpoint and it will automatically identify and return the language being used. The dictionary look up endpoint returns alternative translations for any words or phrases that you supply. Use this feature to help you develop richer translation capabilities or add additional context. You can also instruct the translator service to return the character account for a sentence or series of sentences after the translation operation has been completed.

You may choose to use this feature to check if the translated text could be shared on social media and falls within the accepted character length constraints. For example, the social media platform Twitter has a character limit of 280 characters a tweet. A document translated feature is also included with the translator API. This API is accessible using the REST endpoint of the dedicated Client SDK. Document translation makes it simple for you to translate large files, and support from multiple documents in multiple languages is also included. You can find out more about document translation capabilities by visiting the URL at the bottom of this slide.

A custom translation feature is available in situations where you are using domain specific terminology. You can use this feature to help you arrive at better translations when sending text to the translator API. You need to implement a series of steps to create a custom translation model. Don't worry too much about this however, as a custom translator portal is available to help you do this. The first step in implementing a custom translation model is to create a project using the portal. You can think of a project as a bucket to store all the assets that will form the model. Parallel sentences are then uploaded when sentence is deemed to be the source language with other being the translated version of the original source sentence.

With the documents uploaded, the model can then be trained. I must point out that to train a model, at least 10,000 parallel sentences must be uploaded. After training your model, you can evaluate the accuracy of any translations that you supply. When you're happy with the accuracy of your model, it can then be published. Your trained and published model can then be consumed by your software application. You can use a translator service to help you create consistent translations when processing documents at scale. For example, this may include but is not limited to, legal documentation, academic or research papers.

You may also choose to implement a translator service when building software that must be implemented in a different geography. For example, it's not uncommon for web applications to contain variants of field descriptions for labels on forms. You might need to implement your web application in a different geography or language. You can use the translator service to automatically create translated versions of the field and label descriptions without the need for human translators.

Deploying the translator service in this use case may reduce the overall cost and delivery time of your software project. Another use case you may choose to deploy the translator service is in conversational AI. People can now interact with Chatbots using text or voice channels. Your Chatbot may only support a single language, however. You can use the translator service to perform a real-time translation of the incoming text, which can then be understood by your conversational AI.

Deploying the translator service in this use case can expose your conversational AI to new markets. The translator service lets you perform text translation, document translation, or if you have more niche requirements, leverage a custom translation model. It's now time for a demo.

In this demo, we'll see how you can perform a text translation operation using the translator service and the REST API. So, we're in Visual Studio here and we're looking at our console application. Here, we can see we have four variables: translatorKey, apiEndpoint, querystring, and location. One thing to note is that the variable querystring contains two values from and to, these are parameters that will be sent over to the translated API.

String interpolation will be used to inject the values for the from and to variables. The from variable will be the language that we want to translate from, and the to variable will be the destination language. We also have at line 17 a translate method. We can expand that and scroll down. So, there are a few things happening here. The first thing that we can see in the translate method is that we have three parameters: source language, destination language, and the text that we want to perform.

The translation on here, we set up an object, passing in the text that we want to translate, we then serialize this data into a variable request body. Here, we set up the HTTP client and the HTTP request message. We define the HTTP method, construct the query string, then passing the apiEndpoint with our query string data. At this point, the query string contains the source language and the destination language. On line 33, we specify the content, which is a request body, along with the encoding type of UTF-8 and set the payload to JSON. We set up the HTTP headers for the request, this contains the translator subscription key and the region that the translator instances hosted in, in Azure. We send the request and then read the response back. The response is then returned.

So, what we can do now is we can call this method, we can specify the source language, followed by the destination language, and finally the text. We'll output this information to the console. And finally, we'll put a breakpoint. We can then run the application. At which point we'll see the English text is translated to Spanish.  So, our math has been hit. We can look at the output, increase the text size, and here we can see that our text has been translated to Spanish. In this demo, we have seen how to create a console application that can use the translated API. We've seen how to use the REST API and set up a response. We've seen how to read the response and output this into the console window.

 

About the Author

Jamie Maguire is a Software Architect, Developer, Microsoft MVP (AI), and lifelong tech enthusiast with over 20 years of professional experience.

Jamie is passionate about using AI technologies to help advance systems in a wide range of organizations. 

He has collaborated on many projects including working with Twitter, National Geographic, and the University of Michigan. Jamie is a keen contributor to the technology community and has gained global recognition for articles he has written and software he has built. 

He is a STEM Ambassador and Code Club volunteer, inspiring interest at grassroots level. Jamie shares his story and expertise at speaking events, on social media, and through podcast interviews. 

He has co-authored a book with 16 fellow MVPs demonstrating how Microsoft AI can be used in the real world and regularly publishes material to encourage and promote the use of AI and .NET technologies.