Build a Live Translated Transcriptions Service in Your Video Call Web App
Tags: agora, webdev, javascript, translation
Published: 2021-10-24 11:48:49

Learn how to make a real-time translation service using the Agora Web SDK and Google Cloud.

## Introduction
Doing business globally is a goal for almost every company. The chance to scale up to an international level can increase profits but may require knowledge of multiple languages to communicate with clients or partners from around the world.

Getting an interpreter to help translate multilingual video conferences is impractical, because it may be annoying and will make the meetings longer than needed. You may also want to keep some information confidential.

In this tutorial, we will develop a web application that supports speech-to-text transcription and translation using JavaScript’s [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API), the [Agora Web SDK](https://docs.agora.io/en/Video/downloads?platform=Web), the [Agora RTM SDK](https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html), and the [Google Cloud Translation API](https://cloud.google.com/translate/docs/basic/quickstart#translate_translate_text-drest) to avoid dependency on translators and remove the language barrier during video calls.

![Screenshot of the project we will be developing in this tutorial](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb7m0kiqq5mi5wqf6i0u.png)

## Prerequisites
- Basic knowledge of how to work with JavaScript, JQuery, Bootstrap, and Font Awesome
- Agora Developer Account - Sign up [here](https://sso.agora.io/en/signup?utm_source=medium&utm_medium=blog&utm_campaign=build-a-live-translated-transcriptions-service-your-video-call-web-app)
- Know how to use the [Agora Web SDK](https://docs.agora.io/en/Video/downloads?platform=Web) and the [Agora RTM SDK](https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html)
- [Google Cloud account](https://console.cloud.google.com/)
- Understand how to make requests and receive responses from REST APIs

## Project Setup
We will build on our [existing project](https://www.agora.io/en/blog/building-your-own-transcription-service-within-a-video-call-web-app/): [Building Your Own Transcription Service Within a Video Call Web App](https://www.agora.io/en/blog/building-your-own-transcription-service-within-a-video-call-web-app/). You can begin by cloning this project’s [GitHub repository](https://github.com/akshatvg/Agora-Transcription). You will now have a project that looks like this:

![Screenshot of the Agora Transcription Service UI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y43man750jyv25eeds09.png)

We will now remove the self-note related HTML and the extra buttons. If you face difficulties understanding what the above code does, see [this tutorial](https://www.agora.io/en/blog/building-your-own-transcription-service-within-a-video-call-web-app/).

I have also added code for muting and unmuting video and audio to the video calling application. You can learn more about muting and unmuting from [the Agora documentation](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/icameravideotrack.html?platform=Web#setenabled). Your code will now look like [this](https://github.com/akshatvg/Agora-Translated-Transcription/tree/starter).

You now have a fully functional transcription service along with muting and unmuting capabilities.

## Adding Real-Time Translation to Our Application
We will now add the following code into our HTML file under the existing input field row and add an option for a user to enter their Google Cloud project's API key.

{% gist https://gist.github.com/akshatvg/e3e21b31a6a9aeb617e8b506913c84b5 %}

![Screenshot of how our application looks after adding the new row](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ght06rmg802fa67sgrl.png)

## Create a Google Cloud Translation API Key
- In the Cloud Console, go to the **[Create service account page](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create?supportedpurview=project)**.
- Select a project.
- In the **Service account name** field, enter a name. The Cloud Console completes the **Service account ID** field based on this name.
- In the **Service account description** field, enter a description. For example, **Agora Live Translated Transcription**. 
- Click **Create and Continue**.

![Screenshot of the page where you can create a service account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/facn6alxdsbmcx8hm3ky.png)

- Click the **Select a role** field and choose the **Cloud Translation API Admin** role.

![Screenshot of the role set screen for service accounts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9of8kneh5he0krxalhx5.png)

- Click **Continue**.
- Click **Done** to finish creating the service account.
- Enable the Cloud Translation API from [here](https://console.cloud.google.com/marketplace/product/google/translate.googleapis.com?q=search&referrer=search&project=agora-328918).

![Enable the Translation API on GCP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwm6cx7sjypu2ihqo26j.png)

- Click the **Credentials** tab in the left sidebar, and then click on **Create Credentials**.
- Create and copy the generated API Key.

![The generated API key has to be copied from this page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bzcpiy6enisfibpsrbb.png)

## Core Functionality (JS)
Now that we have the basic structure laid out as well as the keys generated, we can begin adding functionality to the translation service. It may look intimidating at first, but if you follow GCP’s [official docs](https://cloud.google.com/translate/docs/basic/quickstart#translate_translate_text-drest), it’ll be a piece of cake.

The code below takes in the user’s inputted GCP key and the user’s preferred transcription language. As soon as the user stops speaking, their words are transcribed in the chosen language using JavaScript’s Web Speech API. 
This same message is sent in the speaker’s language to all users through the Agora RTM SDK. When this message is received, we check for the receiver’s preferred language and use the Google Translate API to convert the original sent message to user-understandable text. This way, even if the remote user has a different language from the local user, the logic would still work as expected.

{% gist https://gist.github.com/akshatvg/593816a43bc1f52853bb07eeb1ff7d54 %}

![Screenshot of the demo from the user's perspective.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlop49x3fd53tatloxh9.png)

**Note:** For testing, you can use two or more browser tabs to simulate multiple users on the call.

## Conclusion
### You did it!

You have successfully made a multilingual transcription service inside a web video call application. In case you weren’t coding along or want to see the finished product all together, I have uploaded all the code to GitHub:

[https://github.com/akshatvg/Agora-Translated-Transcription](https://github.com/akshatvg/Agora-Translated-Transcription)

You can check out the demo of the code in action:
[https://translation.akshatvg.com](https://translation.akshatvg.com)

Thanks for taking the time to read my tutorial. If you have questions, please let me know with a comment. If you see room for improvement, feel free to fork the repo and make a pull request!

## Other Resources
To learn more about the Agora Web SDK and other use cases, see the developer guide [here](https://docs.agora.io/en/Video/landing-page?platform=Web).

- https://docs.agora.io/en
- https://agoraio-community.github.io/AgoraWebSDK-NG/api/en/index.html
- https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html
- https://docs.agora.io/en/Real-time-Messaging/messaging_web?platform=Web
- https://www.agora.io/
- https://www.agora.io/en/blog/building-your-own-transcription-service-within-a-video-call-web-app/

You can also join our Slack channel:
[Join Slack](https://www.agora.io/en/join-slack/)